]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java
Add progress monitoring for copying resources on desktop
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / StandardCutHandler.java
index 350366e6cc621c6fa3fee4c8728224d1d2421777..0c6d8ba3dcb27c736fc4fb1a5b83ffbcb2df7683 100644 (file)
@@ -17,6 +17,11 @@ import java.util.Set;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.PlatformUI;
@@ -45,29 +50,38 @@ public class StandardCutHandler extends AbstractHandler {
             setStatus("Nothing to cut.");
            return null;
         }
-
-        try {
-            final SimanticsClipboardImpl builder = new SimanticsClipboardImpl();
-
-            Simantics.getSession().syncRequest(new ReadRequest() {
-                @Override
-                public void run(ReadGraph graph) throws DatabaseException {
-                    Set<Resource> unique = new HashSet<Resource>();
-                    for (Resource r : rs) {
-                        if (!unique.add(r))
-                            continue;
-                        CopyHandler handler = graph.adapt(r, CopyHandler.class);
-                        handler.cutToClipboard(graph, builder);
-                    }
+        Job job = new Job("Cut resources") {
+
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                monitor.beginTask("Cut resources", rs.length);
+                try {
+                    final SimanticsClipboardImpl builder = new SimanticsClipboardImpl();
+
+                    Simantics.getSession().syncRequest(new ReadRequest() {
+                        @Override
+                        public void run(ReadGraph graph) throws DatabaseException {
+                            Set<Resource> unique = new HashSet<Resource>();
+                            for (Resource r : rs) {
+                                if (!unique.add(r))
+                                    continue;
+                                CopyHandler handler = graph.adapt(r, CopyHandler.class);
+                                handler.cutToClipboard(graph, builder, SubMonitor.convert(monitor, 1));
+                            }
+                        }
+                    });
+
+                    Simantics.setClipboard(builder);
+                    setCutMessage(builder.getContents().size(), "resource");
+
+                } catch (DatabaseException e) {
+                    Logger.defaultLogError(e);
                 }
-            });
-
-            Simantics.setClipboard(builder);
-            setCutMessage(builder.getContents().size(), "resource");
-
-        } catch (DatabaseException e) {
-            Logger.defaultLogError(e);
-        }
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
 
         return null;
     }
@@ -95,7 +109,7 @@ public class StandardCutHandler extends AbstractHandler {
                 public void run(ReadGraph graph) throws DatabaseException {
                     for (Resource r : rs) {
                         CopyHandler handler = graph.adapt(r, CopyHandler.class);
-                        handler.cutToClipboard(graph, builder);
+                        handler.cutToClipboard(graph, builder, null);
                     }
                 }
             });