Add progress monitoring for copying resources on desktop 83/1983/6
authorjsimomaa <jani.simomaa@gmail.com>
Fri, 3 Aug 2018 10:22:24 +0000 (13:22 +0300)
committerJani Simomaa <jani.simomaa@semantum.fi>
Sat, 1 Sep 2018 07:26:58 +0000 (07:26 +0000)
gitlab #74

Change-Id: Ia061109ef6553c1d148fcadd30b6622ea2b85bda

20 files changed:
bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/AnnotationTypeExporter.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/CopyHandler.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultCopyHandler.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelDependenciesBean.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardBuilder.java
bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardImpl.java
bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Profiles.java
bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java
bundles/org.simantics.modeling.template2d.ui/META-INF/MANIFEST.MF
bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/export/DrawingTemplateExporter.java
bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/DrawingTemplateExporter.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Copy.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java
bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java
bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java
bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/TGElementCopyAdvisor.java
bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java

index 70470fc6a503309c04ce5073879db4b44cd8d749..417f2c515a8b7a2c14529ffc58d457e457309716 100644 (file)
@@ -43,7 +43,7 @@ import org.simantics.utils.ui.dialogs.ShowMessage;
 
 /**
  * @author Tuukka Lehtonen
- * @author Teemu Mätäsniemi
+ * @author Teemu M�t�sniemi
  */
 public class AnnotationTypeExporter implements IRunnableWithProgress {
 
@@ -99,13 +99,13 @@ public class AnnotationTypeExporter implements IRunnableWithProgress {
             public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException {
                 CopyHandler ch = graph.adapt(annotation, CopyHandler.class);
                 SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                ch.copyToClipboard(graph, clipboard);
+                ch.copyToClipboard(graph, clipboard, SubMonitor.convert(monitor, 85));
                 return clipboard;
             }
         });
         for (Set<Representation> object : clipboard.getContents()) {
             TransferableGraph1 tg = ClipboardUtils.accept(object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
-            monitor.worked(95);
+            monitor.worked(10);
 
             monitor.setTaskName("Writing transferable graph...");
             DataContainers.writeFile(location, new DataContainer(
index 7830513c5aa8e2c846e7a76f43fb42400c75153b..a2e9ebd817e3388ec6b280699c4f2e57faa11747 100644 (file)
  *******************************************************************************/
 package org.simantics.db.layer0.adapter;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.util.SimanticsClipboardBuilder;
 
 public interface CopyHandler {
 
-       void copyToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard) throws DatabaseException;
-       void cutToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard) throws DatabaseException;
+       void copyToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard, IProgressMonitor monitor) throws DatabaseException;
+       void cutToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard, IProgressMonitor monitor) throws DatabaseException;
        
 }
index 312d4a10c2890cd14f2425a9a4a7657beacd3f98..dfbaf2678e438f671b0508f37886d103195ce8e2 100644 (file)
@@ -17,6 +17,8 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.common.request.ResourceRead;
@@ -36,9 +38,12 @@ import org.simantics.graph.db.TransferableGraphSource;
 import org.simantics.graph.db.TransferableGraphs;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.operation.Layer0X;
+import org.slf4j.LoggerFactory;
 
 public class DefaultCopyHandler implements CopyHandler, CopyHandler2 {
 
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DefaultCopyHandler.class);
+    
     protected Collection<Resource> resources;
 
     public DefaultCopyHandler(Resource resource) {
@@ -111,29 +116,39 @@ public class DefaultCopyHandler implements CopyHandler, CopyHandler2 {
         };
     }
 
-    protected void fillTG(ReadGraph graph, HashSet<Representation> items, boolean cut) {
-
+    protected void fillTG(ReadGraph graph, HashSet<Representation> items, boolean cut, IProgressMonitor monitor) {
+        SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
+        subMonitor.subTask("Fill tg");
         try {
 
             Representation tgRepresentation = createTransferableGraph(graph, resources, cut);
-            if(tgRepresentation != null) items.add(tgRepresentation);
+            if (tgRepresentation != null)
+                items.add(tgRepresentation);
+            subMonitor.worked(2);
             Representation tgSourceRepresentation = createTransferableGraphSource(graph, resources, cut);
-            if(tgSourceRepresentation != null) items.add(tgSourceRepresentation);
-
-            if(resources.size() == 1) {
-                Collection<Representation> representations = graph.syncRequest(new ResourceRead<Collection<Representation>>(resources.iterator().next()) {
-                    @Override
-                    public Collection<Representation> perform(ReadGraph graph) throws DatabaseException {
-                        ArrayList<Representation> result = new ArrayList<Representation>();
-                        Layer0X L0X = Layer0X.getInstance(graph);
-                        for(Resource adapter : graph.getObjects(resource, L0X.HasRepresentation)) {
-                            result.add(graph.adapt(adapter, Representation.class));
-                        }
-                        return result;
-                    }
-                });
+            if (tgSourceRepresentation != null)
+                items.add(tgSourceRepresentation);
+            subMonitor.worked(2);
+
+            if (resources.size() == 1) {
+                SubMonitor splittedChild = subMonitor.split(6);
+                Collection<Representation> representations = graph
+                        .syncRequest(new ResourceRead<Collection<Representation>>(resources.iterator().next()) {
+                            @Override
+                            public Collection<Representation> perform(ReadGraph graph) throws DatabaseException {
+                                ArrayList<Representation> result = new ArrayList<Representation>();
+                                Layer0X L0X = Layer0X.getInstance(graph);
+                                for (Resource adapter : graph.getObjects(resource, L0X.HasRepresentation)) {
+                                    result.add(graph.adapt(adapter, Representation.class));
+                                    splittedChild.worked(1);
+                                }
+                                return result;
+                            }
+                        });
                 for (Representation r : representations)
                     items.add(r);
+            } else {
+                LOGGER.warn("Invalid amount of resources {} for filling tg", resources);
             }
 
         } catch (DatabaseException e) {
@@ -142,28 +157,36 @@ public class DefaultCopyHandler implements CopyHandler, CopyHandler2 {
 
     }
 
-    protected void fillCopyResource(ReadGraph graph, HashSet<Representation> items) {
+    protected void fillCopyResource(ReadGraph graph, HashSet<Representation> items, IProgressMonitor monitor) {
+        SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
+        subMonitor.subTask("Fill copy resources");
         items.add(ClipboardUtils.createCopyResources(resources));
+        subMonitor.worked(1);
     }
 
-    protected void fillCutResource(ReadGraph graph, HashSet<Representation> items) {
+    protected void fillCutResource(ReadGraph graph, HashSet<Representation> items, IProgressMonitor monitor) {
+        SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
+        subMonitor.subTask("Fill cut resources");
         items.add(ClipboardUtils.createCutResources(resources));
+        subMonitor.worked(1);
     }
 
     @Override
-    public void copyToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard) throws DatabaseException {
+    public void copyToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard, IProgressMonitor monitor) throws DatabaseException {
+        SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
         HashSet<Representation> items = new HashSet<Representation>();
-        fillTG(graph, items, false);
-        fillCopyResource(graph, items);
-        clipboard.addContent(items);
+        fillTG(graph, items, false, subMonitor.split(80));
+        fillCopyResource(graph, items, subMonitor.split(10));
+        clipboard.addContent(items, subMonitor.split(10));
     }
 
     @Override
-    public void cutToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard) throws DatabaseException {
+    public void cutToClipboard(ReadGraph graph, SimanticsClipboardBuilder clipboard, IProgressMonitor monitor) throws DatabaseException {
+        SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
         HashSet<Representation> items = new HashSet<Representation>();
-        fillTG(graph, items, true);
-        fillCutResource(graph, items);
-        clipboard.addContent(items);
+        fillTG(graph, items, true, subMonitor.split(80));
+        fillCutResource(graph, items, subMonitor.split(10));
+        clipboard.addContent(items, subMonitor.split(10));
     }
 
 }
index 56e1e11f23a10893b0b2818c31845e5bbe7d1c48..438c629b67432b6b6b4ac1cc90b8db75c5a15630 100644 (file)
@@ -882,7 +882,7 @@ public class Layer0Utils {
 
        public static Collection<Resource> copyTo(WriteGraph graph, Resource targetContainer, PasteEventHandler handler, CopyHandler copyHandler, PasteHandler pasteHandler) throws DatabaseException {
                SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-               copyHandler.copyToClipboard(graph, clipboard);
+               copyHandler.copyToClipboard(graph, clipboard, new NullProgressMonitor());
                if(targetContainer != null) {
                        if(pasteHandler == null) pasteHandler = graph.adapt(targetContainer, PasteHandler.class);
                        return pasteHandler.pasteFromClipboard(graph, clipboard, handler);
@@ -1192,7 +1192,7 @@ public class Layer0Utils {
 
        SimanticsClipboardImpl cp = new SimanticsClipboardImpl();
        CopyHandler c1 = graph.adapt(r, CopyHandler.class);
-       c1.copyToClipboard(graph, cp);
+       c1.copyToClipboard(graph, cp, null);
        Collection<Set<Representation>> reps = cp.getContents();
        if(reps.size() != 1) return null;
        return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
@@ -1203,7 +1203,7 @@ public class Layer0Utils {
 
        SimanticsClipboardImpl cp = new SimanticsClipboardImpl();
        CopyHandler c1 = graph.adapt(r, CopyHandler.class);
-       c1.copyToClipboard(graph, cp);
+       c1.copyToClipboard(graph, cp, null);
        Collection<Set<Representation>> reps = cp.getContents();
        if(reps.size() != 1) return null;
        return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH_SOURCE);
index afeba2fb9d298b7c42183dd41cdcae7ed9ee40bd..f941b8bf326afca87ac16e0e56d5f163c91f4a3d 100644 (file)
@@ -8,6 +8,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.adapter.AdaptException;
 import org.simantics.databoard.binding.Binding;
@@ -70,7 +71,7 @@ public class ModelDependenciesBean {
                        if(uri == null) continue;
                        CopyHandler ch = graph.adapt(library, CopyHandler.class);
                        SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                       ch.copyToClipboard(graph, clipboard);
+                       ch.copyToClipboard(graph, clipboard, new NullProgressMonitor());
                        for (Set<Representation> object : clipboard.getContents()) {
                                TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
                                if(tg != null) {
index 454227f1aa71dc3789caec25443d2b3b76265f9b..4d993275f1e294ecbabdfec0980c30572b82915c 100644 (file)
@@ -13,10 +13,11 @@ package org.simantics.db.layer0.util;
 
 import java.util.Set;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.simantics.db.layer0.util.SimanticsClipboard.Representation;
 
 public interface SimanticsClipboardBuilder {
        
-       void addContent(Set<Representation> content);
+       void addContent(Set<Representation> content, IProgressMonitor monitor);
 
 }
index b760d578b62e8990d81c7b605a2f8332cc133638..2d0227571845eee6fc7d02f0f546289c0bd1a0ee 100644 (file)
@@ -16,6 +16,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Set;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.utils.datastructures.collections.CollectionUtils;
 
 final public class SimanticsClipboardImpl implements SimanticsClipboard, SimanticsClipboardBuilder {
@@ -26,11 +28,11 @@ final public class SimanticsClipboardImpl implements SimanticsClipboard, Simanti
        }
        
        public SimanticsClipboardImpl(Representation representation) {
-               addContent(Collections.singleton(representation));
+               addContent(Collections.singleton(representation), new NullProgressMonitor());
        }
 
        public SimanticsClipboardImpl(Representation ... representation) {
-               addContent(CollectionUtils.toSet(representation));
+               addContent(CollectionUtils.toSet(representation), new NullProgressMonitor());
        }
 
        @Override
@@ -39,7 +41,7 @@ final public class SimanticsClipboardImpl implements SimanticsClipboard, Simanti
        }
 
        @Override
-       public void addContent(Set<Representation> content) {
+       public void addContent(Set<Representation> content, IProgressMonitor monitor) {
                objects.add(content);
        }
        
index 03da3b78ca287da81bd56d2bb9fe2e6bc5a2f454..cca82ff9aa3edc292f11a7d0219beee6f3b048dc 100644 (file)
@@ -17,6 +17,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.db.ReadGraph;
@@ -292,7 +293,7 @@ public class Profiles {
                                        return resource;
                                }
                        };
-                       handler.copyToClipboard(graph, builder);
+                       handler.copyToClipboard(graph, builder, new NullProgressMonitor());
                        for(Set<SimanticsClipboard.Representation> object : builder.getContents()) {
                    TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
                    TransferableGraphs.importGraph1(graph, tg, advisor);
index 61d09acdd3cb18981d53c67e9300d255a3fc23d6..ab28463e84d5a8e3d3ae81af98b52f990393f167 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.function.BiFunction;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.databoard.Bindings;
 import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.type.Datatype;
@@ -736,7 +737,7 @@ public class CopyAdvisorUtil {
      */
     public static Resource copy4(WriteGraph graph, Resource source, CopyHandler copyHandler) throws DatabaseException {
         SimanticsClipboardImpl builder = new SimanticsClipboardImpl();
-        copyHandler.copyToClipboard(graph, builder);
+        copyHandler.copyToClipboard(graph, builder, new NullProgressMonitor());
 
         for(Set<Representation> object : builder.getContents()) {
             TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
index 93a01f258f61a64337ab84ed84c0733df7bd6b6a..38d430200d69c9053324ccf0a7723928859d88e2 100644 (file)
@@ -19,7 +19,8 @@ Require-Bundle: org.simantics.layer0.utils;bundle-version="0.8.0",
  org.simantics.modeling.template2d.ontology;bundle-version="1.0.0",
  org.simantics.annotation.ontology;bundle-version="1.0.0",
  org.simantics.graph.db;bundle-version="[1.1.9,2.0.0)",
- org.simantics.export.core;bundle-version="1.0.0"
+ org.simantics.export.core;bundle-version="1.0.0",
+ org.slf4j.api
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.simantics.modeling.template2d.ui.function
index 2a60f8095b812820e3b59d9f58c793db6c75a50a..e3ae930349052d7c66d52df821857c4761486050 100644 (file)
@@ -6,6 +6,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
 import org.osgi.service.prefs.Preferences;
 import org.simantics.databoard.binding.mutable.Variant;
 import org.simantics.databoard.type.RecordType;
@@ -61,9 +62,10 @@ public class DrawingTemplateExporter implements ExportClass {
                        ) throws ExportException {
                                
                final TransferableGraphWriter writer = (TransferableGraphWriter) writer_;
-               
+               SubMonitor ss = SubMonitor.convert(monitor, 2);
         try {
                List<Resource> resources = context.session.syncRequest( ExportQueries.toResources2(contents) );
+               SubMonitor subMonitor = ss.split(resources.size());
                for ( final Resource model : resources ) {
                    // TODO: figure out a way to make the TG go directly into a file
                    // instead of having it all in memory at once.
@@ -72,13 +74,15 @@ public class DrawingTemplateExporter implements ExportClass {
                        public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException {
                            CopyHandler ch = graph.adapt( model, CopyHandler.class );
                            SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                           ch.copyToClipboard(graph, clipboard);
+                           ch.copyToClipboard(graph, clipboard, subMonitor.split(1));
                            return clipboard;
                        }
                    });
+                   SubMonitor subMonitor2 = ss.split(resources.size());
                    for (Set<Representation> object : clipboard.getContents()) {
                        TransferableGraph1 tg = ClipboardUtils.accept(object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);                    
                        writer.writeFile(TransferableGraph1.BINDING, tg);
+                       subMonitor2.worked(1);
                    }
                }
 
index bee851607a3a748848fd1f171c96ef14a2877fa1..ead7e836d2d18d2d8f61907245422aadb6f79ff1 100644 (file)
@@ -29,7 +29,6 @@ import org.simantics.databoard.serialization.SerializationException;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.CopyHandler;
 import org.simantics.db.layer0.util.ClipboardUtils;
@@ -41,13 +40,17 @@ import org.simantics.db.request.Read;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.modeling.template2d.DiagramTemplateConstants;
 import org.simantics.utils.ui.dialogs.ShowMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Tuukka Lehtonen
- * @author Teemu Mätäsniemi
+ * @author Teemu M�t�sniemi
  */
 public class DrawingTemplateExporter implements IRunnableWithProgress {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DrawingTemplateExporter.class);
+    
     ExportPlan exportModel;
 
     public DrawingTemplateExporter(ExportPlan exportModel) {
@@ -92,25 +95,22 @@ public class DrawingTemplateExporter implements IRunnableWithProgress {
                 public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException {
                     CopyHandler ch = graph.adapt(template, CopyHandler.class);
                     SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                    ch.copyToClipboard(graph, clipboard);
+                    ch.copyToClipboard(graph, clipboard, SubMonitor.convert(mon, 50));
                     return clipboard;
                 }
             });
             for (Set<Representation> object : clipboard.getContents()) {
                 TransferableGraph1 tg = ClipboardUtils.accept(object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
-                mon.worked(95);
+                mon.worked(50);
 
                 mon.setTaskName("Writing transferable graph...");
                 DataContainers.writeFile(location, new DataContainer(
                         DiagramTemplateConstants.DRAWING_TEMPLATE_FORMAT, DiagramTemplateConstants.DRAWING_TEMPLATE_CURRENT_VERSION,
                         new Variant(TransferableGraph1.BINDING, tg)));
-
                 mon.worked(5);
             }
-
         } catch (DatabaseException e) {
-            e.printStackTrace();
-            Logger.defaultLogError(e);
+            LOGGER.error("Drawing template export failed", e);
             mon.setCanceled(true);
             ShowMessage.showError("Export failed.", "Internal application error in export. See log for details.");
         }
index 3d2b46288f60edd25999f8701757928b1cba92cb..94db9c596e301975d7e34e28442d0f158d99307b 100644 (file)
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.viewers.ISelection;
 import org.simantics.db.Resource;
 import org.simantics.modeling.ui.modelBrowser.handlers.StandardCopyHandler;
@@ -27,7 +28,7 @@ public class SCLClipboard {
                
                ISelection selection = ISelectionUtils.createSelection(node);
                Resource[] rs = new Resource[] {node};
-               StandardCopyHandler.copyResourcesToClipboard(rs, selection);
+               StandardCopyHandler.copyResourcesToClipboard(rs, selection, new NullProgressMonitor());
        }
        
        public static void pasteNode (Resource target) {
index 27d6d6bd6c0f8e472031af392bf36ffb1428360c..407e1ec694345e0b135a6192f5f60585a59e96fa 100644 (file)
@@ -4,6 +4,10 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
 import org.simantics.db.Resource;
 import org.simantics.db.layer0.adapter.ActionFactory;
 import org.simantics.db.layer0.adapter.ActionFactory2;
@@ -26,14 +30,17 @@ public class Copy implements ActionFactory, ActionFactory2 {
                                return null;
                        resources.add((Resource)o);
                }
-        
-        return new Runnable() {
-            @Override
-            public void run() {
-               
-               StandardCopyHandler.copyResourcesToClipboard(resources.toArray(new Resource[resources.size()]), null);
-               
-            }
+        return () -> {
+            Job job = new Job("Copy") {
+
+                @Override
+                protected IStatus run(IProgressMonitor monitor) {
+                    StandardCopyHandler.copyResourcesToClipboard(resources.toArray(new Resource[resources.size()]), null, monitor);
+                    return Status.OK_STATUS;
+                }
+            };
+            job.setUser(true);
+            job.schedule();
         };
     }
 
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);
                     }
                 }
             });
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);
                     }
                 }
             });
index 879a57d19a637935bd7164fb03c32af6fe738088..be5f9abaee7c87b6f0b6ac5ee0cf401128f37a79 100644 (file)
@@ -130,7 +130,7 @@ public class CompilePGraphs {
 
                 String uri = graph.getURI(r);
                 SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                ch.copyToClipboard(graph, clipboard);
+                ch.copyToClipboard(graph, clipboard, monitor);
                 for (Set<Representation> object : clipboard.getContents()) {
                     TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
                     if (tg != null)
index 017d1cf4bc6ab01c5593025a022435746dc37c36..f7ab55fdd3715e742f4a4450c3dba9c0cd274afa 100644 (file)
@@ -1516,7 +1516,7 @@ public class ModelingUtils {
     public static TransferableGraph1 exportSharedOntology(IProgressMonitor monitor, RequestProcessor processor, File location, String format, int version, final LibraryInfo info) throws DatabaseException, IOException {
        
        if(monitor == null) monitor = new NullProgressMonitor();
-       
+       final IProgressMonitor finalMonitor = monitor;
         // TODO: figure out a way to make the TG go directly into a file
         // instead of having it all in memory at once.
 
@@ -1526,7 +1526,7 @@ public class ModelingUtils {
             public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException {
                 CopyHandler ch = graph.adapt(info.library.getResource(), CopyHandler.class);
                 SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                ch.copyToClipboard(graph, clipboard);
+                ch.copyToClipboard(graph, clipboard, finalMonitor);
                 return clipboard;
             }
         });
index 4c7c3d77988f94299cfd18ef8667d046bbd64a40..8b486943746def717dcc7641decb8679422902bf 100644 (file)
@@ -4,6 +4,7 @@ import java.util.ArrayList;
 import java.util.Map;
 import java.util.Set;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.WriteGraph;
@@ -50,7 +51,7 @@ public class TGElementCopyAdvisor extends ElementCopyAdvisor {
                        
                        ComponentAndElementPasteImportAdvisor advisor = new ComponentAndElementPasteImportAdvisor(graph, targetContainer, false,true);
                        
-                       handler.copyToClipboard(graph, builder);
+                       handler.copyToClipboard(graph, builder, new NullProgressMonitor());
                        for(Set<Representation> object : builder.getContents()) {
                    TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
                    if(tg != null) {
index a92d7b62643d713ac3095f1d7df58966e8cb80f2..8aef62c7b2dfe3e6e34d9a8629400fbf245ebedf 100644 (file)
@@ -21,6 +21,7 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Consumer;
 
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.simantics.NameLabelMode;
 import org.simantics.NameLabelUtil;
 import org.simantics.Simantics;
@@ -169,7 +170,7 @@ public class TypicalUtil {
                CommonDBUtils.selectClusterSet(graph, target);
                 SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
                 CopyHandler ch = new TypicalCompositeCopyHandler(template.getResource());
-                ch.copyToClipboard(graph, clipboard);
+                ch.copyToClipboard(graph, clipboard, new NullProgressMonitor());
 
                 Map<String,Object> hints = Collections.singletonMap(ClipboardUtils.HINT_TARGET_RESOURCE, target);