]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java
Fixed Job to return Status.OK_STATUS instead of null
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / StandardCopyHandler.java
index 9730334ccc3dcaabf67ca3ec98c33c82eb729309..1ce5b2d3698ddee5ce7989059dc58de5d6a9fe04 100644 (file)
@@ -19,6 +19,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.jface.viewers.StructuredSelection;
@@ -91,13 +96,22 @@ public class StandardCopyHandler extends AbstractHandler {
         if(copyText(selection)) return null;
 
         formatSelectionToClipboardText(event);
-
         final Resource[] rs = ResourceAdaptionUtils.toResources(selection);
-        copyResourcesToClipboard(rs, selection);
+        Job job = new Job("Copy resources") {
+            @Override
+            protected IStatus run(IProgressMonitor monitor) {
+                monitor.beginTask("Copy resources to clipboard", 1);
+                copyResourcesToClipboard(rs, selection, SubMonitor.convert(monitor, 1));
+                return Status.OK_STATUS;
+            }
+        };
+        job.setUser(true);
+        job.schedule();
+        
         return null;
     }
     
-    public static String copyResourcesToClipboard(final Resource[] rs, ISelection selection) {
+    public static String copyResourcesToClipboard(final Resource[] rs, ISelection selection, IProgressMonitor monitor) {
        
         if(rs == null || rs.length == 0) {
             // This support was added for copying of properties (variables)
@@ -105,7 +119,7 @@ public class StandardCopyHandler extends AbstractHandler {
             if(!variables.isEmpty()) {
                 final SimanticsClipboardImpl builder = new SimanticsClipboardImpl();
                 for(Variable var : variables) {
-                    builder.addContent(Collections.singleton(ClipboardUtils.createVariable(Simantics.getSession(), var)));
+                    builder.addContent(Collections.singleton(ClipboardUtils.createVariable(Simantics.getSession(), var)), monitor);
                 }
                 Simantics.setClipboard(builder);
                 setCopyMessage(builder.getContents().size(), "variable");
@@ -122,7 +136,7 @@ public class StandardCopyHandler extends AbstractHandler {
                 public void run(ReadGraph graph) throws DatabaseException {
                     for (Resource r : rs) {
                         CopyHandler handler = graph.adapt(r, CopyHandler.class);
-                        handler.copyToClipboard(graph, builder);
+                        handler.copyToClipboard(graph, builder, monitor);
                     }
                 }
             });
@@ -145,8 +159,11 @@ public class StandardCopyHandler extends AbstractHandler {
     }
 
     private static void setStatus(String message) {
-        if (status != null)
-            status.setMessage(message);
+        if (status != null) {
+            SWTUtils.asyncExec(
+                    PlatformUI.getWorkbench().getDisplay(),
+                    () -> status.setMessage(message));
+        }
     }
 
     private boolean formatSelectionToClipboardText(ExecutionEvent event) {