org.zaval.data
Interface TreeModel

All Known Implementing Classes:
Tree

public interface TreeModel

This interface is used to manipulate tree-like data structures. The interface provides following three abilities:


Method Summary
 void add(Item to, Item item)
          Adds the item into the tree as a child of the parent item.
 void addTreeListener(TreeListener l)
          Adds the specified tree listener to receive the tree events.
 Item getChildAt(Item item, int index)
          Returns a child item for the given parent item at the specified index.
 int getChildIndex(Item item)
          Searches for the first occurence of the given item in the parent items vector, testing for equality using the equals method and returns the child index.
 int getChildrenCount(Item item)
          Returns a number of child items for the given parent item.
 int getItemsCount()
          Gets the total items number that are contained by the tree.
 Item getParent(Item item)
          Returns a parent for the given item.
 Item getRoot()
          Gets the root item of the tree model.
 boolean hasChildren(Item item)
          Tests if the item has one or more child items.
 void insert(Item to, Item item, int index)
          Inserts the specified item into the tree as a child of the parent item, at the specified index.
 void remove(Item item)
          Removes the specified item from the tree.
 void removeTreeListener(TreeListener l)
          Removes the specified tree listener so that it no longer receives tree events from this tree model.
 void set(Item item, java.lang.Object value)
          Sets the specified value for the given tree item.
 

Method Detail

getRoot

public Item getRoot()
Gets the root item of the tree model.
Returns:
a root item of the tree model.

getItemsCount

public int getItemsCount()
Gets the total items number that are contained by the tree.
Returns:
a total items number.

getParent

public Item getParent(Item item)
Returns a parent for the given item.
Parameters:
item - the specified item to define it parent.
Returns:
a parent item of the child item.

getChildAt

public Item getChildAt(Item item,
                       int index)
Returns a child item for the given parent item at the specified index.
Parameters:
item - the item that is used as a parent to get a child item by the index.
index - the index into this parent child items vector.
Returns:
the item at the specified index.

getChildIndex

public int getChildIndex(Item item)
Searches for the first occurence of the given item in the parent items vector, testing for equality using the equals method and returns the child index.
Parameters:
item - the specified item to define it index.
Returns:
the index of the first occurrence of the item in this parent items vector. Returns -1 if the item is not member of the model.

getChildrenCount

public int getChildrenCount(Item item)
Returns a number of child items for the given parent item.
Parameters:
item - the parent item to define a number of child items.
Returns:
a number of child items. Actually the method gets a size of the item child vector.

hasChildren

public boolean hasChildren(Item item)
Tests if the item has one or more child items.
Parameters:
item - the item to test.
Returns:
true if the item has one or more child items; false otherwise

add

public void add(Item to,
                Item item)
Adds the item into the tree as a child of the parent item. The parent item has to belong to the tree.
Parameters:
to - the parent item.
item - the child item that has to be added.

insert

public void insert(Item to,
                   Item item,
                   int index)
Inserts the specified item into the tree as a child of the parent item, at the specified index. The parent item has to belong to the tree.
Parameters:
to - the specified parent item.
item - the specified child item that has to be added.
index - the specified index where the child has to be inserted.

set

public void set(Item item,
                java.lang.Object value)
Sets the specified value for the given tree item.
Parameters:
item - the item.
o - the specified value.

remove

public void remove(Item item)
Removes the specified item from the tree. If the item has child items than the children will be removed too. The method is recursive to remove all hierarchy that is bound with this item.
Parameters:
item - the item that has to be removed.

addTreeListener

public void addTreeListener(TreeListener l)
Adds the specified tree listener to receive the tree events.
Parameters:
l - the tree listener.

removeTreeListener

public void removeTreeListener(TreeListener l)
Removes the specified tree listener so that it no longer receives tree events from this tree model.
Parameters:
l - the tree listener.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org