]> gerrit.simantics Code Review - simantics/sysdyn.git/blob
57cc1fca1049f4923205236693e8f0cf72d47371
[simantics/sysdyn.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.sysdyn.ui.elements2.connections;\r
13 \r
14 import org.simantics.db.AsyncReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.procedure.AsyncProcedure;\r
17 import org.simantics.diagram.adapter.ElementFactoryAdapter;\r
18 import org.simantics.diagram.stubs.DiagramResource;\r
19 import org.simantics.g2d.canvas.ICanvasContext;\r
20 import org.simantics.g2d.diagram.DiagramHints;\r
21 import org.simantics.g2d.diagram.IDiagram;\r
22 import org.simantics.g2d.element.ElementClass;\r
23 import org.simantics.g2d.element.IElement;\r
24 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;\r
25 import org.simantics.g2d.elementclass.connection.ConnectionClass;\r
26 import org.simantics.g2d.routing.RouterFactory;\r
27 \r
28 /**\r
29  * An element class for single connection entity elements. A connection entity\r
30  * consists of connection edge segments and branch points as its children.\r
31  * \r
32  * @author Tuukka Lehtonen\r
33  */\r
34 public class FlowConnectionFactory extends ElementFactoryAdapter {\r
35 \r
36     public static final ElementClass CLASS = SysdynConnectionClass.CLASS;\r
37 \r
38     @Override\r
39     public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, final AsyncProcedure<ElementClass> procedure) {\r
40         DiagramResource dr = graph.getService(DiagramResource.class);\r
41         graph.forSingleType(elementType, dr.Connection, new AsyncProcedure<Resource>() {\r
42             @Override\r
43             public void exception(AsyncReadGraph graph, Throwable throwable) {\r
44                 procedure.exception(graph, throwable);\r
45             }\r
46             @Override\r
47             public void execute(AsyncReadGraph graph, Resource connectionType) {\r
48                 procedure.execute(graph, ConnectionClass.CLASS.newClassWith(false, new StaticObjectAdapter(connectionType)));\r
49             }\r
50         });\r
51     }\r
52 \r
53     @Override\r
54     public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementResource,\r
55             final IElement element, final AsyncProcedure<IElement> procedure) {\r
56         element.setHint(DiagramHints.ROUTE_ALGORITHM, RouterFactory.create(true, true));\r
57         procedure.execute(graph, element);\r
58     }\r
59 \r
60 }\r