]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/AddBranchpoint.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / AddBranchpoint.java
diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/AddBranchpoint.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/AddBranchpoint.java
new file mode 100644 (file)
index 0000000..8bb96d9
--- /dev/null
@@ -0,0 +1,62 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.diagram.synchronization.graph;\r
+\r
+import java.awt.geom.AffineTransform;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.diagram.content.ConnectionUtil;\r
+import org.simantics.diagram.synchronization.ModificationAdapter;\r
+import org.simantics.g2d.diagram.DiagramHints;\r
+import org.simantics.g2d.diagram.DiagramMutator;\r
+import org.simantics.g2d.diagram.IDiagram;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.elementclass.BranchPoint;\r
+import org.simantics.g2d.elementclass.BranchPoint.Direction;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class AddBranchpoint extends ModificationAdapter {\r
+\r
+    IDiagram diagram;\r
+    IElement connection;\r
+    IElement element;\r
+\r
+    public AddBranchpoint(IDiagram diagram, IElement connection, IElement element) {\r
+        super(ADD_BRANCH_PRIORITY);\r
+        this.diagram = diagram;\r
+        this.connection = connection;\r
+        this.element = element;\r
+    }\r
+\r
+    @Override\r
+    public void perform(WriteGraph g) throws DatabaseException {\r
+        ConnectionUtil cu = new ConnectionUtil(g);\r
+\r
+        DiagramMutator mutator = diagram.getHint(DiagramHints.KEY_MUTATOR);\r
+\r
+        Resource connectionResource = mutator.backendObject(connection);\r
+\r
+        AffineTransform tr = ElementUtils.getTransform(element);\r
+        Direction dir = element.getElementClass().getSingleItem(BranchPoint.class).getDirectionPreference(element, null);\r
+        Resource bp = cu.newBranchPoint(connectionResource, tr, dir);\r
+\r
+        element.setHint(ElementHints.KEY_OBJECT, bp);\r
+        mutator.register(element, bp);\r
+    }\r
+\r
+}\r