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.synchronization.graph;
14 import java.awt.geom.AffineTransform;
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.diagram.content.ConnectionUtil;
20 import org.simantics.diagram.synchronization.ModificationAdapter;
21 import org.simantics.g2d.diagram.DiagramHints;
22 import org.simantics.g2d.diagram.DiagramMutator;
23 import org.simantics.g2d.diagram.IDiagram;
24 import org.simantics.g2d.element.ElementHints;
25 import org.simantics.g2d.element.ElementUtils;
26 import org.simantics.g2d.element.IElement;
27 import org.simantics.g2d.elementclass.BranchPoint;
28 import org.simantics.g2d.elementclass.BranchPoint.Direction;
31 * @author Tuukka Lehtonen
33 public class AddBranchpoint extends ModificationAdapter {
39 public AddBranchpoint(IDiagram diagram, IElement connection, IElement element) {
40 super(ADD_BRANCH_PRIORITY);
41 this.diagram = diagram;
42 this.connection = connection;
43 this.element = element;
47 public void perform(WriteGraph g) throws DatabaseException {
48 ConnectionUtil cu = new ConnectionUtil(g);
50 DiagramMutator mutator = diagram.getHint(DiagramHints.KEY_MUTATOR);
52 Resource connectionResource = mutator.backendObject(connection);
54 AffineTransform tr = ElementUtils.getTransform(element);
55 Direction dir = element.getElementClass().getSingleItem(BranchPoint.class).getDirectionPreference(element, null);
56 Resource bp = cu.newBranchPoint(connectionResource, tr, dir);
58 element.setHint(ElementHints.KEY_OBJECT, bp);
59 mutator.register(element, bp);