/******************************************************************************* * Copyright (c) 2012, 2013 Association for Decentralized Information Management in * Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.g3d.scenegraph.structural; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.simantics.db.Resource; import org.simantics.objmap.structural.IStructuralObject; @SuppressWarnings("rawtypes") public abstract class Connection, T2 extends IComponentNode> implements IStructuralObject{ private List connects = new ArrayList(); public void addConnect(T2 node) { if (!connects.contains(node)) connects.add(node); fireChanged(node,true); } @SuppressWarnings("unchecked") protected void fireChanged(T2 node, boolean add){ for (T2 n : connects) { n.connectionChanged((T) this,node,add); } } public Collection getConnected() { return connects; } public void removeConnect(T2 node) { connects.remove(node); fireChanged(node,false); } @SuppressWarnings("unchecked") public void remove() { List toRemove = new ArrayList(connects.size()); toRemove.addAll(connects); for (IComponentNode node : toRemove) { node.removeConnection((T) this); } } public T2 getOther(IComponentNode node) { if (connects.size() != 2) return null; if (connects.get(0).equals(node)) return connects.get(1); else if (connects.get(1).equals(node)) return connects.get(0); return null; } @Override public void setType(Resource type) { } @Override public Resource getType() { return null; } private List ctx = new ArrayList(1); @Override public List getContext() { return ctx; } @Override public void setContext(List object) { ctx = object; } }