1 package org.simantics.district.network.ui.adapters;
\r
3 import java.awt.geom.AffineTransform;
\r
5 import org.simantics.db.AsyncReadGraph;
\r
6 import org.simantics.db.ReadGraph;
\r
7 import org.simantics.db.Resource;
\r
8 import org.simantics.db.exception.DatabaseException;
\r
9 import org.simantics.db.procedure.AsyncProcedure;
\r
10 import org.simantics.diagram.adapter.SyncElementFactory;
\r
11 import org.simantics.diagram.stubs.DiagramResource;
\r
12 import org.simantics.district.network.ontology.DistrictNetworkResource;
\r
13 import org.simantics.g2d.canvas.ICanvasContext;
\r
14 import org.simantics.g2d.diagram.IDiagram;
\r
15 import org.simantics.g2d.element.ElementClass;
\r
16 import org.simantics.g2d.element.ElementUtils;
\r
17 import org.simantics.g2d.element.IElement;
\r
18 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
\r
20 public class DistrictNetworkVertexElementFactory extends SyncElementFactory {
\r
22 public static final ElementClass CLASS = DistrictNetworkVertexElement.CLASS;
\r
23 private DistrictNetworkResource DN;
\r
24 private DiagramResource DIA;
\r
26 public DistrictNetworkVertexElementFactory(ReadGraph graph) {
\r
27 this.DN = DistrictNetworkResource.getInstance(graph);
\r
28 this.DIA = DiagramResource.getInstance(graph);
\r
32 public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {
\r
33 procedure.execute(graph, CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));
\r
37 protected Resource getElementClassBaseType(AsyncReadGraph graph) {
\r
42 public void load(ReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource vertexResource, IElement element) throws DatabaseException {
\r
44 double[] coords = graph.getRelatedValue(vertexResource, DIA.HasLocation);
\r
45 DistrictNetworkVertex vertex = new DistrictNetworkVertex(coords);
\r
46 element.setHint(DistrictNetworkVertexElement.KEY_DN_VERTEX, vertex);
\r
48 // set element transform based on layer SRS and coords
\r
49 AffineTransform at = new AffineTransform(1, 0, 0, 1, coords[0], coords[1]);
\r
50 ElementUtils.setTransform(element, at);
\r