package org.simantics.district.network.ui.templates; import java.util.Map; import java.util.UUID; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Template; import org.simantics.diagram.stubs.DiagramResource; import org.simantics.diagram.synchronization.graph.layer.GraphLayer; import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil; import org.simantics.district.network.ontology.DistrictNetworkResource; public class AddLayerToDNDiagramTemplate implements Template { Resource template; public AddLayerToDNDiagramTemplate(Resource template) { this.template = template; } @Override public void apply(WriteGraph graph, Map parameters) throws DatabaseException { Resource diagram = (Resource)parameters.get("diagram"); if (diagram == null) { diagram = graph.newResource(); parameters.put("diagram", diagram); } DiagramResource DIA = DiagramResource.getInstance(graph); IGraphLayerUtil layerUtil = graph.adapt(DistrictNetworkResource.getInstance(graph).Layer, IGraphLayerUtil.class); GraphLayer layer = layerUtil.createLayer(graph, UUID.randomUUID().toString(), true); // Create layer graph.claim(diagram, DIA.HasLayer, layer.getLayer()); } }