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;
import org.simantics.db.Resource;
import org.simantics.db.Session;
import org.simantics.db.Statement;
+import org.simantics.db.VirtualGraph;
import org.simantics.db.WriteGraph;
import org.simantics.db.common.Indexing;
import org.simantics.db.common.NamedResource;
import org.simantics.diagram.stubs.DiagramResource;
import org.simantics.diagram.stubs.G2DResource;
import org.simantics.diagram.synchronization.graph.AddElement;
+import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
import org.simantics.graph.db.IImportAdvisor2;
import org.simantics.graph.db.ImportAdvisors;
import org.simantics.graph.db.MissingDependencyException;
import org.simantics.scl.runtime.tuple.Tuple;
import org.simantics.simulation.ontology.SimulationResource;
import org.simantics.structural.stubs.StructuralResource2;
+import org.simantics.structural2.modelingRules.IModelingRules;
import org.simantics.structural2.scl.StructuralComponent;
import org.simantics.structural2.utils.StructuralUtils;
import org.simantics.utils.ObjectUtils;
}
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();
-
+ 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);
- 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() {
}
public static File fileDialog(String title, List<Tuple> namesAndExtensions) {
-
- Display display = Display.getCurrent();
- Shell shell = display.getActiveShell();
-
- FileDialog dialog = new FileDialog(shell, SWT.OPEN);
- dialog.setText(title);
-
- String[] extensions = new String[namesAndExtensions.size()];
- String[] filterNames = new String[namesAndExtensions.size()];
- int index = 0;
- for(Tuple t : namesAndExtensions) {
- String filterName = (String)t.get(0);
- String extension = (String)t.get(1);
- filterNames[index] = filterName;
- extensions[index] = extension;
- index++;
- }
-
- dialog.setFilterExtensions(extensions);
- dialog.setFilterNames(filterNames);
- final String fileName = dialog.open();
- if (fileName == null) return null;
-
- return new File(fileName);
+ return new Runnable() {
+ private File result;
+
+ File getFile() {
+ Display.getDefault().syncExec(this);
+ return result;
+ }
+
+ @Override
+ public void run() {
+ result = showDialog();
+ }
+ private File showDialog() {
+ Display display = Display.getCurrent();
+ Shell shell = display.getActiveShell();
+
+ FileDialog dialog = new FileDialog(shell, SWT.OPEN);
+ dialog.setText(title);
+
+ String[] extensions = new String[namesAndExtensions.size()];
+ String[] filterNames = new String[namesAndExtensions.size()];
+ int index = 0;
+ for(Tuple t : namesAndExtensions) {
+ String filterName = (String)t.get(0);
+ String extension = (String)t.get(1);
+ filterNames[index] = filterName;
+ extensions[index] = extension;
+ index++;
+ }
+
+ dialog.setFilterExtensions(extensions);
+ dialog.setFilterNames(filterNames);
+ final String fileName = dialog.open();
+ if (fileName == null) return null;
+
+ return new File(fileName);
+ }
+ }.getFile();
}
public static Resource createLibrary(WriteGraph graph, Resource parent) throws DatabaseException {
return library;
}
+ public static IModelingRules getModelingRules(ReadGraph graph, Resource diagramResource) throws DatabaseException {
+ return DiagramGraphUtil.getModelingRules(graph, diagramResource, null);
+ }
+ public static void markChanged(WriteGraph graph, Resource r) throws DatabaseException {
+ VirtualGraphSupport support = Simantics.getSession().getService(VirtualGraphSupport.class);
+ VirtualGraph vg = support.getWorkspacePersistent("changeInformation");
+ graph.syncRequest(new WriteRequest(vg) {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ graph.claim(r, MOD.changed, MOD.changed, r);
+ }
+ });
+ }
+
}