]> gerrit.simantics Code Review - simantics/district.git/blob
909f7fb1d2deb02cec0fa8ebb38e47f8c350d150
[simantics/district.git] /
1 package org.simantics.district.network.ui.adapters;\r
2 \r
3 import org.simantics.db.AsyncReadGraph;\r
4 import org.simantics.db.ReadGraph;\r
5 import org.simantics.db.Resource;\r
6 import org.simantics.db.exception.DatabaseException;\r
7 import org.simantics.db.procedure.AsyncProcedure;\r
8 import org.simantics.diagram.adapter.SyncElementFactory;\r
9 import org.simantics.diagram.stubs.DiagramResource;\r
10 import org.simantics.district.network.ontology.DistrictNetworkResource;\r
11 import org.simantics.g2d.canvas.ICanvasContext;\r
12 import org.simantics.g2d.diagram.IDiagram;\r
13 import org.simantics.g2d.element.ElementClass;\r
14 import org.simantics.g2d.element.IElement;\r
15 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
16 \r
17 public class DistrictNetworkVertexElementFactory extends SyncElementFactory {\r
18 \r
19     public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;\r
20     private DistrictNetworkResource DN;\r
21     private DiagramResource DIA;\r
22 \r
23     public DistrictNetworkVertexElementFactory(ReadGraph graph) {\r
24         this.DN = DistrictNetworkResource.getInstance(graph);\r
25         this.DIA = DiagramResource.getInstance(graph);\r
26     }\r
27 \r
28     @Override\r
29     public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType,\r
30             AsyncProcedure<ElementClass> procedure) {\r
31         procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));\r
32     }\r
33 \r
34     @Override\r
35     protected Resource getElementClassBaseType(AsyncReadGraph graph) {\r
36         return DN.Vertex;\r
37     }\r
38 \r
39     @Override\r
40     public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {\r
41         \r
42         double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);\r
43         \r
44         DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);\r
45         \r
46         element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);\r
47     }\r
48 }\r