to.etc.domui.component.tree
Class TreeNodeModelBase<T extends ITreeNode<T>>

java.lang.Object
  extended by to.etc.domui.component.tree.TreeNodeModelBase<T>
All Implemented Interfaces:
ITreeModel<T>

public class TreeNodeModelBase<T extends ITreeNode<T>>
extends java.lang.Object
implements ITreeModel<T>

Concrete implementation of a tree node model using AbstractTreeNodeBase thingies.

Author:
Frits Jalvingh Created on Oct 21, 2008

Constructor Summary
TreeNodeModelBase(T root)
           
 
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.
protected  java.util.List<ITreeModelChangedListener<T>> getListeners()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNodeModelBase

public TreeNodeModelBase(T root)
Method Detail

addChangeListener

public void addChangeListener(ITreeModelChangedListener<T> l)
Description copied from interface: ITreeModel
Add a listener to be called when nodes on the tree change.

Specified by:
addChangeListener in interface ITreeModel<T extends ITreeNode<T>>

removeChangeListener

public void removeChangeListener(ITreeModelChangedListener<T> l)
Description copied from interface: ITreeModel
Remove a registered change listener. Fails silently when the listener was not registered at all.

Specified by:
removeChangeListener in interface ITreeModel<T extends ITreeNode<T>>

getListeners

protected java.util.List<ITreeModelChangedListener<T>> getListeners()

getChild

public T getChild(T parent,
                  int index)
                                throws java.lang.Exception
Description copied from interface: ITreeModel
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.

Specified by:
getChild in interface ITreeModel<T extends ITreeNode<T>>
Returns:
Throws:
java.lang.Exception

getChildCount

public int getChildCount(T item)
                  throws java.lang.Exception
Description copied from interface: ITreeModel
Returns the #of children for this object. This must return the actual number.

Specified by:
getChildCount in interface ITreeModel<T extends ITreeNode<T>>
Returns:
Throws:
java.lang.Exception

getParent

public T getParent(T child)
                                 throws java.lang.Exception
Description copied from interface: ITreeModel
Get the parent node of a child in the tree. This may only return null for the root node.

Specified by:
getParent in interface ITreeModel<T extends ITreeNode<T>>
Returns:
Throws:
java.lang.Exception

getRoot

public T getRoot()
                               throws java.lang.Exception
Description copied from interface: ITreeModel
Get the root object of the tree.

Specified by:
getRoot in interface ITreeModel<T extends ITreeNode<T>>
Returns:
Throws:
java.lang.Exception

hasChildren

public boolean hasChildren(T item)
                    throws java.lang.Exception
Description copied from interface: ITreeModel
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.

Specified by:
hasChildren in interface ITreeModel<T extends ITreeNode<T>>
Returns:
Throws:
java.lang.Exception

expandChildren

public void expandChildren(T item)
                    throws java.lang.Exception
Description copied from interface: ITreeModel
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.

Specified by:
expandChildren in interface ITreeModel<T extends ITreeNode<T>>
Throws:
java.lang.Exception

collapseChildren

public void collapseChildren(T item)
                      throws java.lang.Exception
Description copied from interface: ITreeModel
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.

Specified by:
collapseChildren in interface ITreeModel<T extends ITreeNode<T>>
Throws:
java.lang.Exception