1 package org.simantics.district.network.ui.templates;
\r
3 import java.util.Map;
\r
4 import java.util.UUID;
\r
6 import org.simantics.db.Resource;
\r
7 import org.simantics.db.WriteGraph;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.db.layer0.adapter.Template;
\r
10 import org.simantics.diagram.stubs.DiagramResource;
\r
11 import org.simantics.diagram.synchronization.graph.layer.GraphLayer;
\r
12 import org.simantics.diagram.synchronization.graph.layer.IGraphLayerUtil;
\r
13 import org.simantics.district.network.ontology.DistrictNetworkResource;
\r
15 public class AddLayerToDNDiagramTemplate implements Template {
\r
19 public AddLayerToDNDiagramTemplate(Resource template) {
\r
20 this.template = template;
\r
24 public void apply(WriteGraph graph, Map<String, Object> parameters) throws DatabaseException {
\r
25 Resource diagram = (Resource)parameters.get("diagram");
\r
26 if (diagram == null) {
\r
27 diagram = graph.newResource();
\r
28 parameters.put("diagram", diagram);
\r
31 DiagramResource DIA = DiagramResource.getInstance(graph);
\r
32 IGraphLayerUtil layerUtil = graph.adapt(DistrictNetworkResource.getInstance(graph).Layer, IGraphLayerUtil.class);
\r
33 GraphLayer layer = layerUtil.createLayer(graph, UUID.randomUUID().toString(), true);
\r
36 graph.claim(diagram, DIA.HasLayer, layer.getLayer());
\r