org.apache.myfaces.custom.tree.model

Class DefaultTreeModel

Implemented Interfaces:
TreeModel

public class DefaultTreeModel
extends java.lang.Object
implements TreeModel

Version:
$Revision: 169651 $ $Date: 2005-05-11 18:14:23 +0200 (Wed, 11 May 2005) $
Author:
Oliver Rossmueller

Constructor Summary

DefaultTreeModel()
DefaultTreeModel(TreeNode root)

Method Summary

protected void
fireTreeNodesChanged(Object source, Object[] path, int[] childIndices, Object[] children)
Notify all listeners of a node change.
protected void
fireTreeNodesInserted(Object source, Object[] path, int[] childIndices, Object[] children)
Notify all listeners of structure change.
protected void
fireTreeNodesRemoved(Object source, Object[] path, int[] childIndices, Object[] children)
Notify all listeners of structure change.
protected void
fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children)
Notify all listeners of structure change.
protected void
fireTreeStructureChanged(Object source, TreePath path)
Notify all listeners of structure change.
Object
getChild(Object parent, int index)
int
getChildCount(Object parent)
int
getIndexOfChild(Object parent, Object child)
TreeNode[]
getPathToRoot(TreeNode node)
Collect all parent nodes up to the root node.
protected TreeNode[]
getPathToRoot(TreeNode node, int depth)
Recursivly collect parent nodes up the the root node.
Object
getRoot()
Collection
getTreeModelListeners()
boolean
isLeaf(Object node)
void
nodeChanged(TreeNode node)
Invoke this method after you've changed how node is to be represented in the tree.
void
nodeStructureChanged(TreeNode node)
Invoke this method if you've totally changed the children of node and its childrens children...
void
nodesChanged(TreeNode node, int[] childIndices)
Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.
void
nodesWereInserted(TreeNode node, int[] childIndices)
Invoke this method after you've inserted some TreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order.
void
nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren)
Invoke this method after you've removed some TreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order.
void
valueForPathChanged(TreePath path, Object newValue)

Constructor Details

DefaultTreeModel

public DefaultTreeModel()

DefaultTreeModel

public DefaultTreeModel(TreeNode root)

Method Details

fireTreeNodesChanged

protected void fireTreeNodesChanged(Object source,
                                    Object[] path,
                                    int[] childIndices,
                                    Object[] children)
Notify all listeners of a node change.
Parameters:
source - the node being changed
path - the path to the root node
childIndices - the indices of the changed elements
children - the changed elements

fireTreeNodesInserted

protected void fireTreeNodesInserted(Object source,
                                     Object[] path,
                                     int[] childIndices,
                                     Object[] children)
Notify all listeners of structure change.
Parameters:
source - the node where new elements are being inserted
path - the path to the root node
childIndices - the indices of the new elements
children - the new elements

fireTreeNodesRemoved

protected void fireTreeNodesRemoved(Object source,
                                    Object[] path,
                                    int[] childIndices,
                                    Object[] children)
Notify all listeners of structure change.
Parameters:
source - the node where elements are being removed
path - the path to the root node
childIndices - the indices of the removed elements
children - the removed elements

fireTreeStructureChanged

protected void fireTreeStructureChanged(Object source,
                                        Object[] path,
                                        int[] childIndices,
                                        Object[] children)
Notify all listeners of structure change.
Parameters:
source - the node where the tree model has changed
path - the path to the root node
childIndices - the indices of the affected elements
children - the affected elements

fireTreeStructureChanged

protected void fireTreeStructureChanged(Object source,
                                        TreePath path)
Notify all listeners of structure change.
Parameters:
source - the node where the tree model has changed
path - the path to the root node

getChild

public Object getChild(Object parent,
                       int index)
Specified by:
getChild in interface TreeModel

getChildCount

public int getChildCount(Object parent)
Specified by:
getChildCount in interface TreeModel

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Specified by:
getIndexOfChild in interface TreeModel

getPathToRoot

public TreeNode[] getPathToRoot(TreeNode node)
Collect all parent nodes up to the root node.
Parameters:
node - the TreeNode to get the path for

getPathToRoot

protected TreeNode[] getPathToRoot(TreeNode node,
                                   int depth)
Recursivly collect parent nodes up the the root node.
Parameters:
node - the TreeNode to get the path for
depth - number of steps already taken towards the root (on recursive calls)
Returns:
an array giving the path from the root to the specified node

getRoot

public Object getRoot()
Specified by:
getRoot in interface TreeModel

getTreeModelListeners

public Collection getTreeModelListeners()
Specified by:
getTreeModelListeners in interface TreeModel

isLeaf

public boolean isLeaf(Object node)
Specified by:
isLeaf in interface TreeModel

nodeChanged

public void nodeChanged(TreeNode node)
Invoke this method after you've changed how node is to be represented in the tree.

nodeStructureChanged

public void nodeStructureChanged(TreeNode node)
Invoke this method if you've totally changed the children of node and its childrens children... This will post a treeStructureChanged event.

nodesChanged

public void nodesChanged(TreeNode node,
                         int[] childIndices)
Invoke this method after you've changed how the children identified by childIndicies are to be represented in the tree.

nodesWereInserted

public void nodesWereInserted(TreeNode node,
                              int[] childIndices)
Invoke this method after you've inserted some TreeNodes into node. childIndices should be the index of the new elements and must be sorted in ascending order.

nodesWereRemoved

public void nodesWereRemoved(TreeNode node,
                             int[] childIndices,
                             Object[] removedChildren)
Invoke this method after you've removed some TreeNodes from node. childIndices should be the index of the removed elements and must be sorted in ascending order. And removedChildren should be the array of the children objects that were removed.

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Specified by:
valueForPathChanged in interface TreeModel