]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/graph/RemoveBranchpoint.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / graph / RemoveBranchpoint.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.util.Collection;
15 import java.util.Iterator;
16
17 import org.simantics.db.Resource;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.diagram.content.ConnectionUtil;
21 import org.simantics.diagram.stubs.DiagramResource;
22 import org.simantics.diagram.synchronization.ModificationAdapter;
23 import org.simantics.g2d.element.ElementHints;
24 import org.simantics.g2d.element.IElement;
25
26 /**
27  * @author Tuukka Lehtonen
28  */
29 public class RemoveBranchpoint extends ModificationAdapter {
30
31     Resource element;
32
33     public RemoveBranchpoint(IElement element) {
34         super(REMOVE_BRANCH_PRIORITY);
35         this.element = element.getHint(ElementHints.KEY_OBJECT);
36         assert element != null;
37     }
38
39     @Override
40     public void perform(WriteGraph g) throws DatabaseException {
41         DiagramResource dr = DiagramResource.getInstance(g);
42         Collection<Resource> connectors = g.getObjects(element, dr.AreConnected);
43
44         ConnectionUtil cu = new ConnectionUtil(g);
45         cu.removeConnectionPart(element);
46
47         // If this *was* a route point, reconnect the connectors previously
48         // connected to the route point. Otherwise just leave it.
49         if (connectors.size() == 2) {
50             Iterator<Resource> it = connectors.iterator();
51             Resource c1 = it.next();
52             Resource c2 = it.next();
53             cu.connect(c1, c2);
54         }
55     }
56
57 }