X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fscenegraph%2Fbase%2FParentNode.java;h=5c834fba1dd8b89233f1dbc4e33c5f9a30fb42a4;hb=refs%2Fchanges%2F95%2F3395%2F1;hp=14618318abbaba810f6bc4013043d05dc05ce4a4;hpb=011a16274c3209e40ec885b82c3f295020729a3a;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java index 14618318..5c834fba 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java +++ b/org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java @@ -12,7 +12,6 @@ package org.simantics.g3d.scenegraph.base; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import org.simantics.utils.datastructures.MapList; @@ -22,8 +21,13 @@ public abstract class ParentNode extends Node { private MapList children = new MapList(); public synchronized void addNode(String relName, T child) { - if (child.getParent() != null) + if (child == null) + throw new NullPointerException("Cannot add null child"); + if (child.getParent() != null) { + if (child.getParent() == this) + throw new IllegalArgumentException("Given node is already a child"); child.getParent().deattachNode(child.getParentRel(), child); + } child.setParent(this, relName); children.add(relName, (T) child); @@ -42,7 +46,7 @@ public abstract class ParentNode extends Node { public synchronized final boolean removeNode(String relName, INode child) { if (children.remove(relName, (T) child)) { fireNodeRemoved(child, relName); - child.remove(); + child.remove(); child.setParent(null, null); return true; } @@ -70,7 +74,7 @@ public abstract class ParentNode extends Node { for (T child : nodes) { if (children.remove(relName, (T) child)) { fireNodeRemoved(child, relName); - child.remove(); + child.remove(); child.setParent(null, null); }