com.cc.framework.util
Class TreeHelp

java.lang.Object
  extended bycom.cc.framework.util.TreeHelp

public abstract class TreeHelp
extends java.lang.Object

Helper class for managing tree structures.

Since:
1.0
Version:
$Revision: 1.32 $
Author:
Harald Schulz

Field Summary
private static org.apache.commons.logging.Log log
          Logging instance
 
Constructor Summary
private TreeHelp()
          Constructor
 
Method Summary
private static int calcCheckState(TreeIterator.LevelIterator iter)
          Returns the check state of a given tree node.
static int calcVisibleNodes(TreeNodeDataModel node, TreeStateModel state, Principal principal)
          Expand nodes top down
static void checkNode(TreeNodeDataModel node, boolean check)
          Sets the checked state for the specified Node
static void checkNodes(TreeNodeDataModel root, boolean check)
          Sets the checked state for all items on the specified (Sub-) Tree.
static void checkNodes(TreeNodeDataModel root, java.util.Set checked)
          Applies the checked nodes from the key set
static void connectOutline(java.util.Collection nodes)
          Connects all nodes with a parent child relationship a collection.
static java.util.Map createHashtable(TreeNodeDataModel root)
          Inserts all nodes of the specified tree in a Hashtable
static TreeGroupDataModel createOutline(java.util.Collection nodes)
          Creates a Tree from a Collection.
static TreeGroupDataModel createOutline(TreeGroupDataModel root, java.util.Collection nodes)
          Creates a Tree from an ArrayList.
static TreeGroupDataModel createOutline(TreeGroupDataModel root, java.util.Map elements)
          Creates a Tree from an Hashtable.
static void expandToLevel(TreeGroupDataModel root, int level, TreeStateModel state)
          Expand nodes top down
static java.util.Map getCheckedItems(TreeNodeDataModel node)
          Returns an Array including all the matching row beans of the tree.
static java.util.Map getCheckedItems(TreeNodeDataModel node, java.lang.String property)
          Returns an Array including all the matching row beans in a tree.
static int getCheckState(TreeNodeDataModel root)
          Returns the check state of a given tree node.
static java.util.Map getItemsByState(TreeNodeDataModel node, CheckState state)
          Returns a collection for all element in the tree which fits the specified check state.
static java.util.Map getItemsByState(TreeNodeDataModel node, java.lang.String property, CheckState state)
          Returns a collection for all element in the tree which fits the specified check state.
static TreeNodeDataModel getNodeByKey(TreeNodeDataModel root, java.lang.String key)
          Returns a node for a given key
static java.util.Map getUncheckedItems(TreeNodeDataModel node)
          Returns an Array including all the matching row beans of the tree.
static java.util.Map getUncheckedItems(TreeNodeDataModel node, java.lang.String property)
          Returns an Array including all the matching row beans of the tree.
static boolean isNodeInSubtree(TreeGroupDataModel subTreeRoot, TreeGroupDataModel node)
          Checks if the given node is a member of the subtree.
static TreeNodeDataModel iterateNodes(TreeIterator iter, Algorithm alg)
          This method processes an algorithm for all elements (nodes) in the tree.
static TreeNodeDataModel iterateNodes(TreeIterator iter, Algorithm alg, AlgorithmFilter filter)
          This method processes an algorithm for all elements (nodes) in the tree.
static TreeNodeDataModel iterateNodes(TreeNodeDataModel root, Algorithm alg)
          This method processes an algorithm for all elements (nodes) in the tree.
static TreeNodeDataModel iterateNodes(TreeNodeDataModel root, Algorithm alg, AlgorithmFilter filter)
          This method processes an algorithm for all elements (nodes) in the tree.
static TreeNodeDataModel iterateNodes(TreeNodeDataModel root, TreeStateModel state, Algorithm alg, AlgorithmFilter filter)
          This method processes an algorithm for all elements (nodes) in the tree.
static void uncheck(TreeNodeDataModel root, java.lang.String property, AlgorithmFilter filter)
          Unchecks all tree nodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Logging instance

Constructor Detail

TreeHelp

private TreeHelp()
Constructor

Method Detail

getCheckState

public static int getCheckState(TreeNodeDataModel root)
Returns the check state of a given tree node. The method can handle Checkable and Non Checkable Nodes

Parameters:
root - TreeNodeDataModel
Returns:
integer
See Also:
CheckState

calcCheckState

private static int calcCheckState(TreeIterator.LevelIterator iter)
Returns the check state of a given tree node. The method can handle Checkable and Non Checkable Nodes

Parameters:
iter - Iterator
Returns:
integer
See Also:
CheckState

isNodeInSubtree

public static boolean isNodeInSubtree(TreeGroupDataModel subTreeRoot,
                                      TreeGroupDataModel node)
Checks if the given node is a member of the subtree.

Parameters:
subTreeRoot - the root node of the subtree
node - the node to check
Returns:
true when the node is a member of the subtree

expandToLevel

public static void expandToLevel(TreeGroupDataModel root,
                                 int level,
                                 TreeStateModel state)
Expand nodes top down

Parameters:
root - Root of the current sub tree
level - a value greater or equal to zero indicates that this node should be expanded
state - The TreeStateModel that holds the expansion information

calcVisibleNodes

public static int calcVisibleNodes(TreeNodeDataModel node,
                                   TreeStateModel state,
                                   Principal principal)
Expand nodes top down

Parameters:
node - Root of the current sub tree
state - The TreeStateModel that holds the expansion information
principal - The principal Object that has the information which node is visible for the current user
Returns:
returns the number of visible nodes or -1 if the number is unknown

checkNode

public static void checkNode(TreeNodeDataModel node,
                             boolean check)
Sets the checked state for the specified Node

Parameters:
node - TreeNode
check - true or false

connectOutline

public static void connectOutline(java.util.Collection nodes)
                           throws TreeStructureException
Connects all nodes with a parent child relationship a collection. The elements of the collection must implements the TreeNodeDataModel interface.

Parameters:
nodes - Collection of TreeNodeDataModel's
Throws:
TreeStructureException - if an error in the structure of the tree is detected

createOutline

public static TreeGroupDataModel createOutline(java.util.Collection nodes)
                                        throws TreeStructureException
Creates a Tree from a Collection. The elements in the Collection must implement the TreeNodeDataModel interface. The List must contain one root element

Parameters:
nodes - Collection of TreeNodeDataModel's
Returns:
TreeGroupDataModel
Throws:
TreeStructureException - if an error in the structure of the tree is detected

createOutline

public static TreeGroupDataModel createOutline(TreeGroupDataModel root,
                                               java.util.Collection nodes)
                                        throws TreeStructureException
Creates a Tree from an ArrayList. The elements in the ArrayList must implement the TreeNodeDataModel interface. The Nodes in the ArrayList will be appended to the specified Node (root Argument).

Parameters:
root - TreeGroupDataModel
nodes - Collection of TreeNodeDataModel's
Returns:
TreeGroupDataModel
Throws:
TreeStructureException - if an error in the structure of the tree is detected

createOutline

public static TreeGroupDataModel createOutline(TreeGroupDataModel root,
                                               java.util.Map elements)
                                        throws TreeStructureException
Creates a Tree from an Hashtable. The elements in the ArrayList must implement the TreeNodeDataModel interface. The Nodes in the ArrayList will be appended to the specified Node (root Argument).

Parameters:
root - the root element
elements - Hashtable
Returns:
TreeGroupDataModel
Throws:
TreeStructureException - if an error in the structur of the tree is detected

createHashtable

public static java.util.Map createHashtable(TreeNodeDataModel root)
Inserts all nodes of the specified tree in a Hashtable

Parameters:
root - TreeNodeDataModel
Returns:
Hashtable

getNodeByKey

public static TreeNodeDataModel getNodeByKey(TreeNodeDataModel root,
                                             java.lang.String key)
Returns a node for a given key

Parameters:
root - TreeNodeDataModel
key - The key
Returns:
TreeNodeDataModel

checkNodes

public static void checkNodes(TreeNodeDataModel root,
                              boolean check)
Sets the checked state for all items on the specified (Sub-) Tree.

Parameters:
root - TreeNode
check - true or false

checkNodes

public static void checkNodes(TreeNodeDataModel root,
                              java.util.Set checked)
                       throws java.lang.Exception
Applies the checked nodes from the key set

Parameters:
root - The root node
checked - Set with all the checked keys
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

uncheck

public static void uncheck(TreeNodeDataModel root,
                           java.lang.String property,
                           AlgorithmFilter filter)
                    throws java.lang.Exception
Unchecks all tree nodes

Parameters:
root - TreeNode
property - The check property
filter - Node filter
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

getCheckedItems

public static java.util.Map getCheckedItems(TreeNodeDataModel node)
                                     throws java.lang.Exception
Returns an Array including all the matching row beans of the tree. Therefore the elements in the tree must implement the checkabel interface. Only the checked itmes (1) will be returned!

Parameters:
node - The root node
Returns:
An Hashtable including the checked elements
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

getCheckedItems

public static java.util.Map getCheckedItems(TreeNodeDataModel node,
                                            java.lang.String property)
                                     throws java.lang.Exception
Returns an Array including all the matching row beans in a tree. Only the checked itmes (1) will be returned!

Parameters:
node - The root node
property - The check property
Returns:
An Hashtable including the checked elements
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

getUncheckedItems

public static java.util.Map getUncheckedItems(TreeNodeDataModel node)
                                       throws java.lang.Exception
Returns an Array including all the matching row beans of the tree. Therefore the elements in the tree must implement the checkabel interface. Only the unchecked itmes (0) will be returned!

Parameters:
node - The root node
Returns:
An Hashtable including the unchecked elements
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

getUncheckedItems

public static java.util.Map getUncheckedItems(TreeNodeDataModel node,
                                              java.lang.String property)
                                       throws java.lang.Exception
Returns an Array including all the matching row beans of the tree. Only the unchecked itmes (0) will be returned!

Parameters:
node - The root node
property - The check property
Returns:
An Hashtable including the unchecked elements
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

getItemsByState

public static java.util.Map getItemsByState(TreeNodeDataModel node,
                                            CheckState state)
                                     throws java.lang.Exception
Returns a collection for all element in the tree which fits the specified check state. Therefore the elements in the tree must implement the checkabel interface.

Parameters:
node - The root node
state - The checkstate
Returns:
An Hashtable including the row beans
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

getItemsByState

public static java.util.Map getItemsByState(TreeNodeDataModel node,
                                            java.lang.String property,
                                            CheckState state)
                                     throws java.lang.Exception
Returns a collection for all element in the tree which fits the specified check state.

Parameters:
node - The root node
property - The check property
state - The checkstate
Returns:
An Hashtable including the row beans
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm

iterateNodes

public static TreeNodeDataModel iterateNodes(TreeNodeDataModel root,
                                             Algorithm alg)
                                      throws java.lang.Exception
This method processes an algorithm for all elements (nodes) in the tree.

Parameters:
root - TreeNodeDataModel
alg - Algorithm to execute
Returns:
The object where the iteration terminated or null
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm
See Also:
Algorithm.execute(String, Object)

iterateNodes

public static TreeNodeDataModel iterateNodes(TreeNodeDataModel root,
                                             Algorithm alg,
                                             AlgorithmFilter filter)
                                      throws java.lang.Exception
This method processes an algorithm for all elements (nodes) in the tree.

Parameters:
root - TreeNodeDataModel
alg - Algorithm to execute
filter - The row filter
Returns:
The object where the iteration terminated or null
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm
See Also:
Algorithm.execute(String, Object)

iterateNodes

public static TreeNodeDataModel iterateNodes(TreeNodeDataModel root,
                                             TreeStateModel state,
                                             Algorithm alg,
                                             AlgorithmFilter filter)
                                      throws java.lang.Exception
This method processes an algorithm for all elements (nodes) in the tree.

Parameters:
root - TreeNodeDataModel
state - TreeStateModel
alg - Algorithm to execute
filter - The row filter
Returns:
The object where the iteration terminated or null
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm
See Also:
Algorithm.execute(String, Object)

iterateNodes

public static TreeNodeDataModel iterateNodes(TreeIterator iter,
                                             Algorithm alg)
                                      throws java.lang.Exception
This method processes an algorithm for all elements (nodes) in the tree.

Parameters:
iter - TreeIterator
alg - Algorithm to execute
Returns:
The object where the iteration terminated or null
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm
See Also:
Algorithm.execute(String, Object)

iterateNodes

public static TreeNodeDataModel iterateNodes(TreeIterator iter,
                                             Algorithm alg,
                                             AlgorithmFilter filter)
                                      throws java.lang.Exception
This method processes an algorithm for all elements (nodes) in the tree.

Parameters:
iter - TreeIterator
alg - Algorithm to execute
filter - The row filter
Returns:
The object where the iteration terminated or null
Throws:
java.lang.Exception - Indicates an error while iterating and executing the algorithm
See Also:
Algorithm.execute(String, Object)


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.