From 230cebfd3b10b2b134d7525786b9cef7884d8da6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 29 May 2008 08:53:45 +0200 Subject: [PATCH] add removeAll() set parent of removed children to null --- .../pterodactylus/util/swing/SortableTreeNode.java | 28 +++++++++++++++------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/net/pterodactylus/util/swing/SortableTreeNode.java b/src/net/pterodactylus/util/swing/SortableTreeNode.java index dbdeb68..01cc3b1 100644 --- a/src/net/pterodactylus/util/swing/SortableTreeNode.java +++ b/src/net/pterodactylus/util/swing/SortableTreeNode.java @@ -139,6 +139,13 @@ public class SortableTreeNode implements MutableTreeNode { return children.isEmpty(); } + /** + * {@inheritDoc} + */ + public Enumeration children() { + return Collections.enumeration(children); + } + // // ACTIONS // @@ -159,13 +166,14 @@ public class SortableTreeNode implements MutableTreeNode { */ public void insert(MutableTreeNode child, int index) { children.add(index, child); + child.setParent(this); } /** * {@inheritDoc} */ public void remove(int index) { - children.remove(index); + children.remove(index).setParent(null); } /** @@ -173,6 +181,7 @@ public class SortableTreeNode implements MutableTreeNode { */ public void remove(MutableTreeNode node) { children.remove(node); + node.setParent(null); } /** @@ -186,6 +195,16 @@ public class SortableTreeNode implements MutableTreeNode { } /** + * Removes all children of this node. + */ + public void removeAll() { + for (MutableTreeNode childNode: children) { + childNode.setParent(null); + } + children.clear(); + } + + /** * {@inheritDoc} */ public void setParent(MutableTreeNode newParent) { @@ -235,13 +254,6 @@ public class SortableTreeNode implements MutableTreeNode { /** * {@inheritDoc} */ - public Enumeration children() { - return Collections.enumeration(children); - } - - /** - * {@inheritDoc} - */ @Override public String toString() { return (userObject != null) ? userObject.toString() : null; -- 2.7.4