1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.diagram.adapter;
15 import org.simantics.db.AsyncReadGraph;
16 import org.simantics.db.Resource;
17 import org.simantics.db.common.procedure.adapter.AsyncProcedureAdapter;
18 import org.simantics.db.common.procedure.guarded.GuardedAsyncProcedureWrapper;
19 import org.simantics.db.procedure.AsyncProcedure;
20 import org.simantics.diagram.stubs.DiagramResource;
21 import org.simantics.diagram.synchronization.SynchronizationHints;
22 import org.simantics.diagram.synchronization.graph.TransformSynchronizer;
23 import org.simantics.g2d.canvas.ICanvasContext;
24 import org.simantics.g2d.diagram.IDiagram;
25 import org.simantics.g2d.element.ElementClass;
26 import org.simantics.g2d.element.IElement;
27 import org.simantics.g2d.element.handler.impl.StaticObjectAdapter;
28 import org.simantics.g2d.elementclass.BranchPoint;
29 import org.simantics.g2d.elementclass.BranchPoint.Direction;
30 import org.simantics.g2d.elementclass.BranchPointClass;
33 * @author Tuukka Lehtonen
35 public class BranchPointClassFactory extends ElementFactoryAdapter {
37 public static ElementClass create(Resource elementClass) {
38 return BranchPointClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementClass));
42 public void create(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, Resource elementType, AsyncProcedure<ElementClass> procedure) {
43 procedure.execute(graph, BranchPointClass.CLASS.newClassWith(false, new StaticObjectAdapter(elementType)));
47 public void load(AsyncReadGraph graph, ICanvasContext canvas, IDiagram diagram, final Resource element, final IElement e, final AsyncProcedure<IElement> procedure) {
48 e.setHint(SynchronizationHints.HINT_SYNCHRONIZER, TransformSynchronizer.INSTANCE);
50 final AsyncProcedure<IElement> guard = new GuardedAsyncProcedureWrapper<IElement>(procedure, 2);
52 final BranchPoint bp = e.getElementClass().getAtMostOneItemOfClass(BranchPoint.class);
54 final DiagramResource dr = graph.getService(DiagramResource.class);
55 graph.forHasStatement(element, dr.Horizontal, element, new AsyncProcedureAdapter<Boolean>() {
57 public void exception(AsyncReadGraph graph, Throwable throwable) {
58 guard.exception(graph, throwable);
61 public void execute(AsyncReadGraph graph, final Boolean horizontal) {
62 graph.forHasStatement(element, dr.Vertical, element, new AsyncProcedure<Boolean>() {
64 public void exception(AsyncReadGraph graph, Throwable throwable) {
65 guard.exception(graph, throwable);
68 public void execute(AsyncReadGraph graph, Boolean vertical) {
69 Direction direction = Direction.Any;
70 if (horizontal ^ vertical)
71 direction = horizontal ? Direction.Horizontal : Direction.Vertical;
72 bp.setDirectionPreference(e, direction);
74 guard.execute(graph, e);
81 ElementFactoryUtil.readTransform(graph, element, e, guard);