]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java
Add progress monitoring for copying resources on desktop
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / modelBrowser / handlers / StandardCopyHandler.java
index 9730334ccc3dcaabf67ca3ec98c33c82eb729309..c8946df682bd9f7a7459f3954abbef3bfaee4bb4 100644 (file)
@@ -19,6 +19,10 @@ 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.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 +95,23 @@ 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 null;
+            }
+        };
+        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);
                     }
                 }
             });