]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
An action to show a pgraph for resources in ontologies 22/522/2
authorAntti Villberg <antti.villberg@semantum.fi>
Sat, 13 May 2017 18:33:37 +0000 (21:33 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 15 May 2017 11:57:04 +0000 (14:57 +0300)
#7225

Change-Id: I358fc705d5a7afcb20edb6520019a3689a978cd7

bundles/org.simantics.db.layer0/adapters.xml
bundles/org.simantics.debug.ui/plugin.xml
bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/TGEditorAdapter.java [new file with mode: 0644]
bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/componentTypeEditor/PGraphEditorDocumentProvider.java
bundles/org.simantics.modeling/src/org/simantics/modeling/ModelingUtils.java

index 13fbd87b2b7c5d03ca082e011d17e968bd470721..5586b5fd1c8598e459b411d81310596ee54b1386 100644 (file)
                        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
index 6ed0b55c213ffad78bb011b8a12e5e5b175470e1..abceb0952ea63ebaf17abad361e0ca8fa2c97c24 100644 (file)
             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
diff --git a/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/TGEditorAdapter.java b/bundles/org.simantics.debug.ui/src/org/simantics/debug/ui/internal/TGEditorAdapter.java
new file mode 100644 (file)
index 0000000..a941ecb
--- /dev/null
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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));
+    }
+    
+}
index 69449fd8f0f7c2bdf86acee536af1f86d630240d..ad247b6bd8cf70e0bf8dd993ed2b96ff9ea0ae4a 100644 (file)
@@ -20,12 +20,18 @@ import org.simantics.databoard.Bindings;
 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;
@@ -48,9 +54,21 @@ public class PGraphEditorDocumentProvider extends AbstractDocumentProvider {
                 @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) {
index 3b4806c7ce927a78b46bdc60f8931b3bb6db535d..8a5b92228a74f52dd5e4bf41665bf09a0567c88b 100644 (file)
@@ -1470,7 +1470,7 @@ public class ModelingUtils {
        
     }
        
-    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();
        
@@ -1504,13 +1504,20 @@ public class ModelingUtils {
                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() {
@@ -2205,7 +2212,7 @@ public class ModelingUtils {
 
        }
 
-       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);
@@ -2217,7 +2224,7 @@ public class ModelingUtils {
         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);
                }