1 package org.simantics.district.network.ui.adapters;
\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
17 public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
\r
19 public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;
\r
20 private DistrictNetworkResource DN;
\r
21 private DiagramResource DIA;
\r
23 public DistrictNetworkVertexElementFactory(ReadGraph graph) {
\r
24 this.DN = DistrictNetworkResource.getInstance(graph);
\r
25 this.DIA = DiagramResource.getInstance(graph);
\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
35 protected Resource getElementClassBaseType(AsyncReadGraph graph) {
\r
40 public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {
\r
42 double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);
\r
44 DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);
\r
46 element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);
\r