From: jsimomaa Date: Fri, 3 Aug 2018 10:22:24 +0000 (+0300) Subject: Add progress monitoring for copying resources on desktop X-Git-Tag: v1.43.0~136^2~390 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=60509f4629d5ca644dd9533dd2abc64349aad328;p=simantics%2Fplatform.git Add progress monitoring for copying resources on desktop gitlab #74 Change-Id: Ia061109ef6553c1d148fcadd30b6622ea2b85bda --- diff --git a/bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/AnnotationTypeExporter.java b/bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/AnnotationTypeExporter.java index 70470fc6a..417f2c515 100644 --- a/bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/AnnotationTypeExporter.java +++ b/bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/AnnotationTypeExporter.java @@ -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 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( diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/CopyHandler.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/CopyHandler.java index 7830513c5..a2e9ebd81 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/CopyHandler.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/CopyHandler.java @@ -11,13 +11,14 @@ *******************************************************************************/ 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; } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultCopyHandler.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultCopyHandler.java index 312d4a10c..dfbaf2678 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultCopyHandler.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/adapter/impl/DefaultCopyHandler.java @@ -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 resources; public DefaultCopyHandler(Resource resource) { @@ -111,29 +116,39 @@ public class DefaultCopyHandler implements CopyHandler, CopyHandler2 { }; } - protected void fillTG(ReadGraph graph, HashSet items, boolean cut) { - + protected void fillTG(ReadGraph graph, HashSet 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 representations = graph.syncRequest(new ResourceRead>(resources.iterator().next()) { - @Override - public Collection perform(ReadGraph graph) throws DatabaseException { - ArrayList result = new ArrayList(); - 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 representations = graph + .syncRequest(new ResourceRead>(resources.iterator().next()) { + @Override + public Collection perform(ReadGraph graph) throws DatabaseException { + ArrayList result = new ArrayList(); + 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 items) { + protected void fillCopyResource(ReadGraph graph, HashSet 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 items) { + protected void fillCutResource(ReadGraph graph, HashSet 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 items = new HashSet(); - 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 items = new HashSet(); - 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)); } } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java index 56e1e11f2..438c629b6 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Layer0Utils.java @@ -882,7 +882,7 @@ public class Layer0Utils { public static Collection 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> 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> reps = cp.getContents(); if(reps.size() != 1) return null; return ClipboardUtils.accept(graph, reps.iterator().next(), SimanticsKeys.KEY_TRANSFERABLE_GRAPH_SOURCE); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelDependenciesBean.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelDependenciesBean.java index afeba2fb9..f941b8bf3 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelDependenciesBean.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelDependenciesBean.java @@ -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 object : clipboard.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); if(tg != null) { diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardBuilder.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardBuilder.java index 454227f1a..4d993275f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardBuilder.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardBuilder.java @@ -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 content); + void addContent(Set content, IProgressMonitor monitor); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardImpl.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardImpl.java index b760d578b..2d0227571 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardImpl.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/SimanticsClipboardImpl.java @@ -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 content) { + public void addContent(Set content, IProgressMonitor monitor) { objects.add(content); } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Profiles.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Profiles.java index 03da3b78c..cca82ff9a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Profiles.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/profile/Profiles.java @@ -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 object : builder.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); TransferableGraphs.importGraph1(graph, tg, advisor); diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java index 61d09acdd..ab28463e8 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/CopyAdvisorUtil.java @@ -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 object : builder.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); diff --git a/bundles/org.simantics.modeling.template2d.ui/META-INF/MANIFEST.MF b/bundles/org.simantics.modeling.template2d.ui/META-INF/MANIFEST.MF index 93a01f258..38d430200 100644 --- a/bundles/org.simantics.modeling.template2d.ui/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.modeling.template2d.ui/META-INF/MANIFEST.MF @@ -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 diff --git a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/export/DrawingTemplateExporter.java b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/export/DrawingTemplateExporter.java index 2a60f8095..e3ae93034 100644 --- a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/export/DrawingTemplateExporter.java +++ b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/export/DrawingTemplateExporter.java @@ -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 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 object : clipboard.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); writer.writeFile(TransferableGraph1.BINDING, tg); + subMonitor2.worked(1); } } diff --git a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/DrawingTemplateExporter.java b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/DrawingTemplateExporter.java index bee851607..ead7e836d 100644 --- a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/DrawingTemplateExporter.java +++ b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/DrawingTemplateExporter.java @@ -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 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."); } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java index 3d2b46288..94db9c596 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/SCLClipboard.java @@ -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) { diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Copy.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Copy.java index 27d6d6bd6..407e1ec69 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Copy.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/Copy.java @@ -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(); }; } diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java index 9730334cc..c8946df68 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCopyHandler.java @@ -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); } } }); diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java index 350366e6c..0c6d8ba3d 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/modelBrowser/handlers/StandardCutHandler.java @@ -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 unique = new HashSet(); - 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 unique = new HashSet(); + 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); } } }); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java index 879a57d19..be5f9abae 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/CompilePGraphs.java @@ -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 object : clipboard.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); if (tg != null) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java index 017d1cf4b..f7ab55fdd 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -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; } }); diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/TGElementCopyAdvisor.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/TGElementCopyAdvisor.java index 4c7c3d779..8b4869437 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/TGElementCopyAdvisor.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/mapping/TGElementCopyAdvisor.java @@ -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 object : builder.getContents()) { TransferableGraph1 tg = ClipboardUtils.accept(graph, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); if(tg != null) { diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java index a92d7b626..8aef62c7b 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/TypicalUtil.java @@ -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 hints = Collections.singletonMap(ClipboardUtils.HINT_TARGET_RESOURCE, target);