class="org.simantics.db.layer0.adapter.impl.SharedOntologyCopyHandler">
<this />
</type>
+ <type
+ uri="http://www.simantics.org/Layer0-0.0/Ontology"
+ class="org.simantics.db.layer0.adapter.impl.SharedOntologyCopyHandler">
+ <this />
+ </type>
</target>
<target
id="org.simantics.debug.adapter2"
priority="-1">
</adapterClass>
+ <adapterClass
+ class="org.simantics.debug.ui.internal.TGEditorAdapter"
+ id="org.simantics.debug.adapter3"
+ priority="-1">
+ </adapterClass>
</extension>
<extension
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.debug.ui.internal;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.PossibleIndexRoot;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.layer0.Layer0;
+import org.simantics.ui.SimanticsUI;
+import org.simantics.ui.workbench.ResourceEditorInput;
+import org.simantics.ui.workbench.editor.AbstractResourceEditorAdapter;
+
+/**
+ * @author Antti Villberg
+ */
+public class TGEditorAdapter extends AbstractResourceEditorAdapter {
+
+ public static final String EDITOR_ID = "org.simantics.modeling.ui.pgraphEditor";
+
+ public TGEditorAdapter() {
+ super("Ontology Viewer", SimanticsUI.getImageDescriptor("icons/etool16/bug.png"));
+ }
+
+ @Override
+ public boolean canHandle(ReadGraph g, Resource r) throws DatabaseException {
+ Resource indexRoot = g.syncRequest(new PossibleIndexRoot(r));
+ if(indexRoot == null) return false;
+ Layer0 L0 = Layer0.getInstance(g);
+ return g.isInstanceOf(indexRoot, L0.Ontology);
+ }
+
+ @Override
+ public void openEditor(Resource r) throws Exception {
+ openEditorWithId(EDITOR_ID, new ResourceEditorInput(EDITOR_ID,r));
+ }
+
+}
import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.PossibleIndexRoot;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.common.request.UniqueRead;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.util.Layer0Utils;
+import org.simantics.graph.refactoring.GraphRefactoringUtils;
+import org.simantics.graph.representation.PrettyPrintTG;
+import org.simantics.graph.representation.TransferableGraph1;
import org.simantics.layer0.Layer0;
+import org.simantics.modeling.ModelingUtils;
+import org.simantics.modeling.ui.sharedontology.wizard.Constants;
import org.simantics.scl.compiler.errors.CompilationError;
import org.simantics.scl.compiler.errors.Locations;
import org.simantics.ui.workbench.ResourceEditorInput;
@Override
public Document perform(ReadGraph graph) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
- currentText = graph.getRelatedValue(resource, L0.PGraph_definition, Bindings.STRING);
- errorHappened = false;
- return new Document(currentText != null ? currentText : "");
+ if(graph.isInstanceOf(resource, L0.PGraph)) {
+ currentText = graph.getRelatedValue(resource, L0.PGraph_definition, Bindings.STRING);
+ errorHappened = false;
+ return new Document(currentText != null ? currentText : "");
+ } else {
+ Resource indexRoot = graph.syncRequest(new PossibleIndexRoot(resource));
+ if(indexRoot != null && graph.isInstanceOf(indexRoot, L0.Ontology)) {
+ TransferableGraph1 tg = ModelingUtils.exportSharedOntology(graph, indexRoot, null, Constants.SHARED_LIBRARY_FORMAT, Constants.SHARED_LIBRARY_CURRENT_VERSION);
+ GraphRefactoringUtils.fixOntologyExport(tg);
+ currentText = PrettyPrintTG.print(tg);
+ errorHappened = false;
+ return new Document(currentText != null ? currentText : "");
+ }
+ throw new DatabaseException("Could not get PGraph from " + resource);
+ }
}
});
} catch (DatabaseException e) {
}
- public static void exportSharedOntology(IProgressMonitor monitor, RequestProcessor processor, File location, String format, int version, final LibraryInfo info) throws DatabaseException, IOException {
+ 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();
metadata.put(ExternalDownloadBean.EXTENSION_KEY, edb);
}
- monitor.setTaskName("Writing transferable graph...");
- DataContainers.writeFile(location, new DataContainer(
- format, version,
- metadata, new Variant(TransferableGraph1.BINDING, tg)));
-
- monitor.worked(5);
+ if(location != null) {
+ monitor.setTaskName("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");
+
}
public static TreeMap<String, Variant> getExportMetadata() {
}
- public static void exportSharedOntology(ReadGraph graph, Resource library, String fileName, String format, int version) throws DatabaseException {
+ public static TransferableGraph1 exportSharedOntology(ReadGraph graph, Resource library, String fileName, String format, int version) throws DatabaseException {
Layer0 L0 = Layer0.getInstance(graph);
String name = graph.getRelatedValue(library, L0.HasName, Bindings.STRING);
LibraryInfo info = new LibraryInfo(name, library, draft);
try {
- exportSharedOntology(new NullProgressMonitor(), graph, new File(fileName), format, version, info);
+ return exportSharedOntology(new NullProgressMonitor(), graph, fileName != null ? new File(fileName) : null, format, version, info);
} catch (IOException e) {
throw new DatabaseException(e);
}