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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.sysdyn.ui.elements2.connections;
\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
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
32 * @author Tuukka Lehtonen
\r
34 public class FlowConnectionFactory extends ElementFactoryAdapter {
\r
36 public static final ElementClass CLASS = SysdynConnectionClass.CLASS;
\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
43 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
44 procedure.exception(graph, throwable);
\r
47 public void execute(AsyncReadGraph graph, Resource connectionType) {
\r
48 procedure.execute(graph, ConnectionClass.CLASS.newClassWith(false, new StaticObjectAdapter(connectionType)));
\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