Author: sletellier Date: 2009-09-08 17:26:56 +0200 (Tue, 08 Sep 2009) New Revision: 1531 Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Item.java trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java Log: Adding usefulls methods to manipulate Items Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Item.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Item.java 2009-08-29 20:44:00 UTC (rev 1530) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/Item.java 2009-09-08 15:26:56 UTC (rev 1531) @@ -135,6 +135,28 @@ } /** + * Remove child node a new child node + * + * @param item to remove + */ + public void removeChild(Item item) { + if (children != null) { + children.remove(item); + } + } + + /** + * Remove all childs nodes + * + * @param list of items to remove + */ + public void removeChilds(List<Item> items) { + if (children != null) { + children.removeAll(items); + } + } + + /** * Returns a list of this item's children. * * @return a list of all nested child nodes @@ -156,6 +178,15 @@ return parent; } + /** + * Set the parent of this item + * + * @return the item parent (or null) + */ + public void setParent(Item parent) { + this.parent = parent; + } + private PropertyChangeSupport getPropertyChangeSupport() { if (propertyChangeSupport == null) { propertyChangeSupport = new SwingPropertyChangeSupport(this); Modified: trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java =================================================================== --- trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java 2009-08-29 20:44:00 UTC (rev 1530) +++ trunk/jaxx-runtime-swing/src/main/java/jaxx/runtime/swing/JAXXTree.java 2009-09-08 15:26:56 UTC (rev 1531) @@ -78,7 +78,7 @@ /* This is an inefficient implementation, but hand-coded tree structures are unlikely to contain enough nodes for that to really matter. This could be sped up with caching. */ - private Item findItem(Object value) { + public Item findItem(Object value) { return findItem(root, value); } @@ -115,6 +115,9 @@ @Override public int getChildCount(Object parent) { Item node = findItem(parent); + if (node == null){ + return 0; + } return node.getChildren().size(); } @@ -205,6 +208,12 @@ }); } + public void setItem(Item items) { + List<Item> newItems = new ArrayList<Item>(); + newItems.add(items); + setItems(newItems); + } + public void setItems(List<Item> items) { JAXXTreeModel model = new JAXXTreeModel(items); if (model.getRoot() != null) {