]> gerrit.simantics Code Review - simantics/3d.git/blobdiff - org.simantics.g3d/src/org/simantics/g3d/scenegraph/base/ParentNode.java
Filter conflicting changes (deleted + added at the same time)
[simantics/3d.git] / org.simantics.g3d / src / org / simantics / g3d / scenegraph / base / ParentNode.java
index 14618318abbaba810f6bc4013043d05dc05ce4a4..5c834fba1dd8b89233f1dbc4e33c5f9a30fb42a4 100644 (file)
@@ -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<T extends INode> extends Node {
        private MapList<String, T> children = new MapList<String, T>();
 
        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<T extends INode> 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<T extends INode> extends Node {
                for (T child : nodes) {
                        if (children.remove(relName, (T) child)) {
                                fireNodeRemoved(child, relName);
-                           child.remove();
+                               child.remove();
                                child.setParent(null, null);
                                
                        }