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.util.Collection;
15 import java.util.Iterator;
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;
27 * @author Tuukka Lehtonen
29 public class RemoveBranchpoint extends ModificationAdapter {
33 public RemoveBranchpoint(IElement element) {
34 super(REMOVE_BRANCH_PRIORITY);
35 this.element = element.getHint(ElementHints.KEY_OBJECT);
36 assert element != null;
40 public void perform(WriteGraph g) throws DatabaseException {
41 DiagramResource dr = DiagramResource.getInstance(g);
42 Collection<Resource> connectors = g.getObjects(element, dr.AreConnected);
44 ConnectionUtil cu = new ConnectionUtil(g);
45 cu.removeConnectionPart(element);
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();