]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java
Improved shared library structure dump to take more types into account
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / ModelingUtils.java
index 4a4d97a18a2b254f0be58c2a928483dcecd234c6..1edf3cd3121a4e4682e5de0012916fcfd0b74ee5 100644 (file)
@@ -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<SimanticsClipboard>() {
-            @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<String,Variant> 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<Representation> 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<String, Variant> getExportMetadata() {