]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/AddBranchpoint.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / AddBranchpoint.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.diagram.synchronization.graph;
13
14 import java.awt.geom.AffineTransform;
15
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;
29
30 /**
31  * @author Tuukka Lehtonen
32  */
33 public class AddBranchpoint extends ModificationAdapter {
34
35     IDiagram diagram;
36     IElement connection;
37     IElement element;
38
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;
44     }
45
46     @Override
47     public void perform(WriteGraph g) throws DatabaseException {
48         ConnectionUtil cu = new ConnectionUtil(g);
49
50         DiagramMutator mutator = diagram.getHint(DiagramHints.KEY_MUTATOR);
51
52         Resource connectionResource = mutator.backendObject(connection);
53
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);
57
58         element.setHint(ElementHints.KEY_OBJECT, bp);
59         mutator.register(element, bp);
60     }
61
62 }