X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FModelingUtils.java;fp=bundles%2Forg.simantics.modeling%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2FModelingUtils.java;h=1edf3cd3121a4e4682e5de0012916fcfd0b74ee5;hp=4a4d97a18a2b254f0be58c2a928483dcecd234c6;hb=9214a600c9401b06057fc2c10ea86a0ce0218d87;hpb=7bc4de702166fe57dd45b7f161847e6d21d83bb4 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 4a4d97a18..1edf3cd31 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java @@ -29,6 +29,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -1515,53 +1516,46 @@ 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; + SubMonitor mon = SubMonitor.convert(monitor, "Exporting shared library", 100); + // TODO: figure out a way to make the TG go directly into a file // instead of having it all in memory at once. - monitor.beginTask("Exporting shared library...", 100); - SimanticsClipboard clipboard = processor.syncRequest(new Read() { - @Override - public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException { - CopyHandler ch = graph.adapt(info.library.getResource(), CopyHandler.class); - SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl(); - ch.copyToClipboard(graph, clipboard, finalMonitor); - return clipboard; - } + SimanticsClipboard clipboard = processor.syncRequest((ReadGraph graph) -> { + CopyHandler ch = graph.adapt(info.library.getResource(), CopyHandler.class); + SimanticsClipboardImpl result = new SimanticsClipboardImpl(); + ch.copyToClipboard(graph, result, mon.split(5)); + return result; }); - + TreeMap metadata = getExportMetadata(); DraftStatusBean draft = info.draft; if(draft != null) { - metadata.put(DraftStatusBean.EXTENSION_KEY, new Variant(DraftStatusBean.BINDING ,draft)); + metadata.put(DraftStatusBean.EXTENSION_KEY, new Variant(DraftStatusBean.BINDING ,draft)); } - + for (Set object : clipboard.getContents()) { - + mon.subTask("Constructing exported material"); TransferableGraph1 tg = ClipboardUtils.accept(processor, object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH); - monitor.worked(95); - + mon.worked(90); + Variant edb = tg.extensions.get(ExternalDownloadBean.EXTENSION_KEY); if(edb != null) { - metadata.put(ExternalDownloadBean.EXTENSION_KEY, edb); + metadata.put(ExternalDownloadBean.EXTENSION_KEY, edb); } if(location != null) { - monitor.setTaskName("Writing transferable graph..."); + monitor.subTask("Writing transferable graph"); DataContainers.writeFile(location, new DataContainer( format, version, metadata, new Variant(TransferableGraph1.BINDING, tg))); monitor.worked(5); } - + return tg; - } - - throw new DatabaseException("Failed to export"); - + + throw new DatabaseException("Export failed, no contents to export"); } public static TreeMap getExportMetadata() {