]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Allow Diagram API to work for Document instances. 17/3717/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 17 Dec 2019 15:50:49 +0000 (17:50 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Tue, 17 Dec 2019 15:50:49 +0000 (17:50 +0200)
gitlab #7

Change-Id: I1947db44ea134743abdcf50cbee7eaeac54e2a8c

org.simantics.interop.diagram/src/org/simantics/interop/diagram/Diagram.java
org.simantics.interop.diagram/src/org/simantics/interop/diagram/DiagramUtils.java

index 5695798e65946d0ffaa59918053f81dbfa933eb7..15174e65378d43565cd7692dda0a58adba966486 100644 (file)
@@ -123,6 +123,8 @@ public abstract class Diagram<T extends Symbol> {
                Resource model = DiagramUtils.getModel(graph, res);
                Resource configuration = DiagramUtils.getConfiguration(graph, model);
                Set<String> names = new HashSet<String>();
+               if (configuration == null)
+                       return names;
                Collection<Resource> composites = getAllComposites(graph, configuration);
                for (Resource composite : composites) {
                        names.addAll(getAllModuleNamesForComposite(graph, composite));
@@ -282,7 +284,7 @@ public abstract class Diagram<T extends Symbol> {
         * @throws ManyObjectsForFunctionalRelationException
         * @throws ServiceException
         */
-       private static Resource getDiagramFromComposite(ReadGraph g, Resource compositeType) throws DatabaseException {
+       public Resource getDiagramFromComposite(ReadGraph g, Resource compositeType) throws DatabaseException {
                ModelingResources m  = ModelingResources.getInstance(g);
                Collection<Resource> diagramTemplates = g.getAssertedObjects(compositeType, m.HasModelingTemplate);
                for (Resource diagramTemplate : diagramTemplates) {
index 29f3e21186761cc846daecffa2b22e1f2a0beed0..6a1aa1010cd496eb4ed11d78d46dd6e987122fae 100644 (file)
@@ -78,6 +78,8 @@ public class DiagramUtils {
                while (r != null) {
                        if (graph.isInstanceOf(r, sim.Model))
                                return r;
+                       if (graph.isInstanceOf(r, l0.SharedOntology))
+                               return r;
                        r = graph.getPossibleObject(r, l0.PartOf);
                }
                return r;
@@ -85,6 +87,6 @@ public class DiagramUtils {
        
        public static Resource getConfiguration(ReadGraph graph, Resource model) throws DatabaseException {
                SimulationResource sim = SimulationResource.getInstance(graph);
-               return graph.getSingleObject(model, sim.HasConfiguration);
+               return graph.getPossibleObject(model, sim.HasConfiguration);
        }
 }