From: Marko Luukkainen Date: Tue, 17 Dec 2019 15:50:49 +0000 (+0200) Subject: Allow Diagram API to work for Document instances. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4113c2d809d7e412c6a297eaf694958db6ef512b;p=simantics%2Finterop.git Allow Diagram API to work for Document instances. gitlab #7 Change-Id: I1947db44ea134743abdcf50cbee7eaeac54e2a8c --- diff --git a/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Diagram.java b/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Diagram.java index 5695798..15174e6 100644 --- a/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Diagram.java +++ b/org.simantics.interop.diagram/src/org/simantics/interop/diagram/Diagram.java @@ -123,6 +123,8 @@ public abstract class Diagram { Resource model = DiagramUtils.getModel(graph, res); Resource configuration = DiagramUtils.getConfiguration(graph, model); Set names = new HashSet(); + if (configuration == null) + return names; Collection composites = getAllComposites(graph, configuration); for (Resource composite : composites) { names.addAll(getAllModuleNamesForComposite(graph, composite)); @@ -282,7 +284,7 @@ public abstract class Diagram { * @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 diagramTemplates = g.getAssertedObjects(compositeType, m.HasModelingTemplate); for (Resource diagramTemplate : diagramTemplates) { diff --git a/org.simantics.interop.diagram/src/org/simantics/interop/diagram/DiagramUtils.java b/org.simantics.interop.diagram/src/org/simantics/interop/diagram/DiagramUtils.java index 29f3e21..6a1aa10 100644 --- a/org.simantics.interop.diagram/src/org/simantics/interop/diagram/DiagramUtils.java +++ b/org.simantics.interop.diagram/src/org/simantics/interop/diagram/DiagramUtils.java @@ -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); } }