to.etc.domui.component.tree
Interface ITreeModel<T>

All Known Implementing Classes:
TreeNodeModelBase

public interface ITreeModel<T>

The base model for a Tree. This encapsulates the knowledge about a tree, and returns tree-based context information for when the tree is being built.

Author:
Frits Jalvingh Created on Oct 17, 2008

Method Summary
 void addChangeListener(ITreeModelChangedListener<T> l)
          Add a listener to be called when nodes on the tree change.
 void collapseChildren(T item)
          Called when this node's children are to be collapsed.
 void expandChildren(T item)
          Called when this node is attempted to be expanded.
 T getChild(T parent, int index)
          Returns the nth child in the parent's list.
 int getChildCount(T item)
          Returns the #of children for this object.
 T getParent(T child)
          Get the parent node of a child in the tree.
 T getRoot()
          Get the root object of the tree.
 boolean hasChildren(T item)
          If possible this should quickly decide if a tree node has children or not.
 void removeChangeListener(ITreeModelChangedListener<T> l)
          Remove a registered change listener.
 

Method Detail

getChildCount

int getChildCount(@Nonnull
                  T item)
                  throws java.lang.Exception
Returns the #of children for this object. This must return the actual number.

Parameters:
item -
Returns:
Throws:
java.lang.Exception

hasChildren

boolean hasChildren(@Nonnull
                    T item)
                    throws java.lang.Exception
If possible this should quickly decide if a tree node has children or not. This is used to render an expanded node's state icons. If determining whether a node has children is an expensive option this method should return TRUE always; this causes the state icon to display as if children are available and the user has the possibility to expand that node. At that time we'll call getChildCount() which must determine the #of children. If that returns zero it will at that time properly re-render the state of the node, showing that the node is actually a leaf and cannot be expanded further.

Parameters:
item -
Returns:
Throws:
java.lang.Exception

getRoot

@Nonnull
T getRoot()
          throws java.lang.Exception
Get the root object of the tree.

Returns:
Throws:
java.lang.Exception

getChild

@Nonnull
T getChild(@Nonnull
                   T parent,
                   int index)
           throws java.lang.Exception
Returns the nth child in the parent's list. This call can do actual expansion the first time it's called when a tree is lazily-loaded.

Parameters:
parent -
index -
Returns:
Throws:
java.lang.Exception

getParent

T getParent(@Nonnull
            T child)
            throws java.lang.Exception
Get the parent node of a child in the tree. This may only return null for the root node.

Parameters:
child -
Returns:
Throws:
java.lang.Exception

addChangeListener

void addChangeListener(@Nonnull
                       ITreeModelChangedListener<T> l)
Add a listener to be called when nodes on the tree change.

Parameters:
l -

removeChangeListener

void removeChangeListener(@Nonnull
                          ITreeModelChangedListener<T> l)
Remove a registered change listener. Fails silently when the listener was not registered at all.

Parameters:
l -

expandChildren

void expandChildren(@Nonnull
                    T item)
                    throws java.lang.Exception
Called when this node is attempted to be expanded. This call can be used to refresh/lazily load the children of the passed node. This call is issued every time this node's tree is expanded so take care to only reload when needed.

Parameters:
item -
Throws:
java.lang.Exception

collapseChildren

void collapseChildren(@Nonnull
                      T item)
                      throws java.lang.Exception
Called when this node's children are to be collapsed. This call is executed for every node that was expanded but is collapsed. It can be used to release resources for collapsed nodes.

Parameters:
item -
Throws:
java.lang.Exception