package org.simantics.district.network.ui; import java.util.Collections; 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; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.graph.layer.GraphLayer; import org.simantics.diagram.synchronization.graph.layer.GraphLayerUtil; import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; import org.simantics.layer0.Layer0; public class DNGraphLayerUtil implements IGraphLayerUtil { public DNGraphLayerUtil(Resource layer) { } @Override public GraphLayer loadLayer(ReadGraph graph, Resource layer) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); String name = graph.getRelatedValue(layer, L0.HasName); Resource inLayer = graph.getSingleObject(layer, DN.HasInLayerTag); Map properties = new HashMap<>(); properties.put("IN_LAYER", inLayer); return new GraphLayer(name, layer, properties); } @Override public GraphLayer createLayer(WriteGraph graph, String layerName, boolean active) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); DiagramResource DIA = DiagramResource.getInstance(graph); DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph); Resource layer = graph.newResource(); graph.claim(layer, L0.InstanceOf, null, DN.Layer); // Assign tagging relations Resource inLayerTag = GraphLayerUtil.newTag(graph, L0, DN.InLayer); graph.claim(layer, DN.HasInLayerTag, inLayerTag); // Assign shared name property for all, the layer and the tags Resource name = graph.newResource(); graph.claim(name, L0.InstanceOf, null, L0.String); graph.claimValue(name, layerName); graph.claim(layer, L0.HasName, name); graph.claim(inLayerTag, L0.HasName, name); graph.claim(layer, DN.HasSpatialRefSystem, DN.EPSG_4326); GraphLayerUtil.setLayerActive(graph, DIA, layer, active); return new GraphLayer(layerName, layer, Collections.emptyMap()); } }