X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fsynchronization%2Fgraph%2Flayer%2FGraphLayerUtil.java;h=6a4ecd667bc1190f7576d64b3c340da3fe86f18b;hp=198452ed1a2fe7886e480f6facbaa584092bcbcd;hb=d11fef0101853949671492de5b49ea94892ced78;hpb=efec7759cf9f153cf368f2ece6fed67f0d1632b1 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java index 198452ed1..6a4ecd667 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/layer/GraphLayerUtil.java @@ -11,6 +11,10 @@ *******************************************************************************/ package org.simantics.diagram.synchronization.graph.layer; +import java.util.HashMap; +import java.util.Map; + +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; @@ -24,51 +28,67 @@ import org.simantics.layer0.Layer0; * * @author Tuukka Lehtonen */ -public final class GraphLayerUtil { - - WriteGraph graph; - Layer0 l0; - DiagramResource dia; +public final class GraphLayerUtil implements IGraphLayerUtil { - public GraphLayerUtil(WriteGraph graph) { - this.graph = graph; - this.l0 = Layer0.getInstance(graph); - this.dia = DiagramResource.getInstance(graph); + public GraphLayerUtil(Resource layer) { } - public GraphLayer createLayer(String layerName, boolean active) throws DatabaseException { + @Override + public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + Resource layer = graph.newResource(); - graph.claim(layer, l0.InstanceOf, null, dia.Layer); + graph.claim(layer, L0.InstanceOf, null, DIA.Layer); // Assign tagging relations - Resource visibleTag = newTag(dia.IsVisible); - Resource focusableTag = newTag(dia.IsFocusable); - graph.claim(layer, dia.HasVisibleTag, visibleTag); - graph.claim(layer, dia.HasFocusableTag, focusableTag); + Resource visibleTag = newTag(graph, L0, DIA.IsVisible); + Resource focusableTag = newTag(graph, L0, DIA.IsFocusable); + graph.claim(layer, DIA.HasVisibleTag, visibleTag); + graph.claim(layer, DIA.HasFocusableTag, focusableTag); // Assign shared name property for all, the layer and the tags Resource name = graph.newResource(); - graph.claim(name, l0.InstanceOf, null, l0.String); + graph.claim(name, L0.InstanceOf, null, L0.String); graph.claimValue(name, layerName); - graph.claim(layer, l0.HasName, name); - graph.claim(visibleTag, l0.HasName, name); - graph.claim(focusableTag, l0.HasName, name); + graph.claim(layer, L0.HasName, name); + graph.claim(visibleTag, L0.HasName, name); + graph.claim(focusableTag, L0.HasName, name); - setLayerActive(layer, active); + setLayerActive(graph, DIA, layer, active); - return new GraphLayer(layerName, layer, visibleTag, focusableTag); + Map properties = new HashMap<>(); + properties.put(GraphLayer.PROP_FOCUSABLE, focusableTag); + properties.put(GraphLayer.PROP_VISIBLE, visibleTag); + + return new GraphLayer(layerName, layer, properties); } - public Resource newTag(Resource baseTag) throws DatabaseException { + public static Resource newTag(WriteGraph graph, Layer0 L0, Resource baseTag) throws DatabaseException { Resource tag = graph.newResource(); - graph.claim(tag, l0.SubrelationOf, baseTag); - graph.claim(tag, l0.InverseOf, tag); + graph.claim(tag, L0.SubrelationOf, baseTag); + graph.claim(tag, L0.InverseOf, tag); return tag; } - public void setLayerActive(Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException { - graph.claimLiteral(layer, dia.IsActive, Boolean.valueOf(active)); + public static void setLayerActive(WriteGraph graph, DiagramResource DIA, Resource layer, boolean active) throws ManyObjectsForFunctionalRelationException, ServiceException { + graph.claimLiteral(layer, DIA.IsActive, Boolean.valueOf(active)); + } + + @Override + public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + DiagramResource DIA = DiagramResource.getInstance(graph); + String name = graph.getRelatedValue(layer, L0.HasName); + Resource visible = graph.getSingleObject(layer, DIA.HasVisibleTag); + Resource focusable = graph.getSingleObject(layer, DIA.HasFocusableTag); + + Map properties = new HashMap<>(); + properties.put(GraphLayer.PROP_FOCUSABLE, focusable); + properties.put(GraphLayer.PROP_VISIBLE, visible); + + return new GraphLayer(name, layer, properties); } }