org.apache.myfaces.custom.tree.model
Class DefaultTreeModel

java.lang.Object
  extended by org.apache.myfaces.custom.tree.model.DefaultTreeModel
All Implemented Interfaces:
Serializable, TreeModel

public class DefaultTreeModel
extends Object
implements TreeModel, Serializable

Version:
$Revision: 472638 $ $Date: 2006-11-08 15:54:13 -0500 (Wed, 08 Nov 2006) $
Author:
Oliver Rossmueller
See Also:
Serialized Form

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)
          Return the child of parent at index index in the parent's child array.
 int getChildCount(Object parent)
          Answer the number of children of parent.
 int getIndexOfChild(Object parent, Object child)
          Return the index of child in parent.
 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()
          Return the root of the tree.
 Collection getTreeModelListeners()
          Answer the mutable collection of tree model listeners.
 boolean isLeaf(Object node)
          Answer true if node is a leaf.
 void nodeChanged(TreeNode node)
          Invoke this method after you've changed how node is to be represented in the tree.
 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 nodeStructureChanged(TreeNode node)
          Invoke this method if you've totally changed the children of node and its childrens children...
 void nodesWereInserted(TreeNode node, int[] childIndices)
          Invoke this method after you've inserted some TreeNodes into node.
 void nodesWereRemoved(TreeNode node, int[] childIndices, Object[] removedChildren)
          Invoke this method after you've removed some TreeNodes from node.
 void valueForPathChanged(TreePath path, Object newValue)
          Called when the value for the item identified by path has changed to newValue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultTreeModel

public DefaultTreeModel()

DefaultTreeModel

public DefaultTreeModel(TreeNode root)
Method Detail

getRoot

public Object getRoot()
Description copied from interface: TreeModel
Return the root of the tree.

Specified by:
getRoot in interface TreeModel
Returns:
the root of the tree or null, it this tree has no nodes

getChild

public Object getChild(Object parent,
                       int index)
Description copied from interface: TreeModel
Return the child of parent at index index in the parent's child array.

Specified by:
getChild in interface TreeModel
Parameters:
parent - a node in the tree
Returns:
the child of parent at index index

getChildCount

public int getChildCount(Object parent)
Description copied from interface: TreeModel
Answer the number of children of parent.

Specified by:
getChildCount in interface TreeModel
Parameters:
parent - a node in the tree
Returns:
the number of children of the node parent

isLeaf

public boolean isLeaf(Object node)
Description copied from interface: TreeModel
Answer true if node is a leaf.

Specified by:
isLeaf in interface TreeModel
Parameters:
node - a node in the tree
Returns:
true if node is a leaf

valueForPathChanged

public void valueForPathChanged(TreePath path,
                                Object newValue)
Description copied from interface: TreeModel
Called when the value for the item identified by path has changed to newValue. If newValue signifies a truly new value the model should post a treeNodesChanged event.

Specified by:
valueForPathChanged in interface TreeModel
Parameters:
path - path to the node that has been altered
newValue - the new value from the TreeCellEditor

getIndexOfChild

public int getIndexOfChild(Object parent,
                           Object child)
Description copied from interface: TreeModel
Return the index of child in parent.

Specified by:
getIndexOfChild in interface TreeModel
Parameters:
parent - a node in the tree
child - the node we are interested in
Returns:
the index of the child in the parent, or -1 if either child or parent are null

getTreeModelListeners

public Collection getTreeModelListeners()
Description copied from interface: TreeModel
Answer the mutable collection of tree model listeners.

Specified by:
getTreeModelListeners in interface TreeModel
Returns:
Collection

nodeChanged

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


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.


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.


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.


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

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


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.