com.metamatrix.console.util
Class StaticTreeUtilities

java.lang.Object
  extended by com.metamatrix.console.util.StaticTreeUtilities

public class StaticTreeUtilities
extends java.lang.Object

Useful static methods that deal with trees.


Field Summary
static java.lang.String CONTEXT_FOR_DUPE_CHECKING
           
static int MSGLEVEL_FOR_DUPE_CHECKING
           
 
Constructor Summary
StaticTreeUtilities()
           
 
Method Summary
static javax.swing.tree.TreePath[] allExpandedPaths(javax.swing.JTree tree, TreeView treeView)
           
static javax.swing.tree.TreePath[] allTreePaths(javax.swing.tree.TreeModel tm, boolean populate)
           
static javax.swing.tree.TreePath[] allTreePaths(javax.swing.tree.TreeModel tm, boolean populate, TreeView treeView)
          Return an array of all tree paths in a tree model.
static javax.swing.tree.TreePath[] allTreePaths(javax.swing.tree.TreeModel tm, TreeView treeView)
           
static javax.swing.tree.TreePath[] allTreePathsToLeafNodes(javax.swing.tree.TreeModel tm)
           
static java.util.Collection allTreePathsToNode(java.lang.Object nodeUserObject, javax.swing.tree.TreeModel model)
           
static java.util.Collection allTreePathsToNode(java.lang.Object nodeUserObject, javax.swing.tree.TreeModel model, TreeView treeView)
          Return all tree paths where the last node is a given node.
static java.lang.String allTreePathsToString(javax.swing.JTree tree, TreeView treeView)
          Returns a String representing all of the tree paths in a tree, also showing whether or not each tree path is expanded.
static java.lang.String allTreePathsToString(javax.swing.tree.TreeModel model)
           
static java.lang.String allTreePathsToString(javax.swing.tree.TreeModel model, boolean classNamesOnly, TreeView treeView)
          Returns a String representing all of the tree paths in a tree, also showing whether or not each tree path is expanded.
static void collapse(javax.swing.JTree tree)
          Collapse an entire tree.
static java.util.List descendantsOfNode(DefaultTreeNode startingNode, boolean includeStartingNode)
          Return all of the descendants of a DefaultTreeNode as a List, optionally including the starting node.
static java.util.List descendantsOfNode(javax.swing.tree.TreeNode startingNode)
          Return all of the descendants of a javax.swing.tree.TreeNode as a List, never including the starting node.
static java.util.List descendantsOfNode(javax.swing.tree.TreeNode startingNode, boolean includeStartingNode)
          Return all of the descendants of a javax.swing.tree.TreeNode as a List, optionally including the starting node.
static java.util.List descendantsOfNode(TreeNode startingNode, boolean includeStartingNode, TreeView treeView)
          Return all of the descendants of a com.metamatrix.common.tree.TreeNode as a List, optionally including the starting node.
static void deselectAll(javax.swing.JTree tree)
          Deselect all selected tree paths in a JTree.
static void expandAll(javax.swing.JTree tree)
          Expand all rows of a JTree.
static TreePathExpansion[] expansionState(javax.swing.JTree tree)
           
static TreePathExpansion[] expansionState(javax.swing.JTree tree, boolean populate)
           
static TreePathExpansion[] expansionState(javax.swing.JTree tree, TreeView treeView, boolean populate)
           
static int indexInTreePath(java.lang.String name, javax.swing.tree.TreePath tp)
          Return the index of a given name in a tree path, using the toString() method of each node.
static int indexOfUserObject(javax.swing.tree.DefaultMutableTreeNode node, java.lang.Object userObject)
          Return the child index in a DefaultMutableTreeNode of a child whose user object equals the given object.
static int maxSelectedTreePathLength(javax.swing.JTree tree)
          Return the maximum length of any tree path selected.
static javax.swing.tree.DefaultMutableTreeNode nodeAtToStringPath(javax.swing.tree.TreeModel tm, java.lang.String[] tsp)
          Return the node at the end of a "path" consisting an array of Strings representing the toString() results of a corresponding tree node.
static java.lang.String nodesString(javax.swing.tree.DefaultTreeModel model)
          For debug.
static java.lang.String nodesString(javax.swing.JTree tree)
           
static javax.swing.tree.DefaultMutableTreeNode nodeWithObjectOf(javax.swing.tree.TreeModel tree, java.lang.Object userObj)
          Returns the first node found whose user object equals the given object.
static void populateTree(javax.swing.tree.TreeNode root)
          Given a root node, this method populates any nodes in a tree that are LazyBranchNodes.
static void populateTree(TreeNode root, TreeView treeView)
          Given a com.metamatrix.common.tree.TreeNode as a root starting point, not necessarily a real root, populate all of its descendant nodes.
static int removeNode(java.lang.Object node, javax.swing.tree.TreeModel model)
          Remove all occurrences of a node from a tree model.
static void restoreExpansionState(javax.swing.JTree tree, TreePathExpansion[] savedPathState, boolean expandNewPaths)
           
static void restoreExpansionState(javax.swing.JTree tree, TreePathExpansion[] savedPathState, boolean expandNewPaths, java.util.Collection selectionListeners, java.util.Collection willExpandListeners, java.util.Collection expansionListeners)
           
static void restoreExpansionState(javax.swing.JTree tree, TreePathExpansion[] savedPathState, boolean expandNewPaths, java.util.Collection selectionListeners, java.util.Collection willExpandListeners, java.util.Collection expansionListeners, TreeView treeView)
           
static void restoreExpansionState(javax.swing.JTree tree, TreePathExpansion[] savedPathState, boolean expandNewPaths, TreeView treeView)
           
static boolean treePathsEqual(javax.swing.tree.TreePath tp1, javax.swing.tree.TreePath tp2)
          Compare two tree paths using toString()
static javax.swing.tree.TreePath treePathToNode(javax.swing.JTree tree, java.lang.Object node)
           
static javax.swing.tree.TreePath treePathToNodeUsingEquals(javax.swing.JTree tree, java.lang.Object node)
           
static java.lang.String treePathToString(javax.swing.tree.TreeNode node)
           
static java.lang.String treePathToString(javax.swing.tree.TreeNode node, boolean classNamesOnly)
          For debug.
static java.lang.String treePathToString(javax.swing.tree.TreePath tp)
           
static java.lang.String treePathToString(javax.swing.tree.TreePath tp, boolean classNamesOnly)
          For debug.
static java.lang.String[] treePathToStrings(javax.swing.tree.TreePath tp)
          Return a String array representing the toString() results of each element in a TreePath.
static void userTabPaintProblemDuplicateNodeCheck(javax.swing.JTree tree)
          Method inserted specifically to help solve a User tab painting problem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTEXT_FOR_DUPE_CHECKING

public static final java.lang.String CONTEXT_FOR_DUPE_CHECKING
See Also:
Constant Field Values

MSGLEVEL_FOR_DUPE_CHECKING

public static final int MSGLEVEL_FOR_DUPE_CHECKING
See Also:
Constant Field Values
Constructor Detail

StaticTreeUtilities

public StaticTreeUtilities()
Method Detail

maxSelectedTreePathLength

public static int maxSelectedTreePathLength(javax.swing.JTree tree)
Return the maximum length of any tree path selected.


expandAll

public static final void expandAll(javax.swing.JTree tree)
Expand all rows of a JTree. (If there is a method to do this in JTree I cannot find it. BWP)


descendantsOfNode

public static java.util.List descendantsOfNode(javax.swing.tree.TreeNode startingNode,
                                               boolean includeStartingNode)
Return all of the descendants of a javax.swing.tree.TreeNode as a List, optionally including the starting node.


descendantsOfNode

public static java.util.List descendantsOfNode(DefaultTreeNode startingNode,
                                               boolean includeStartingNode)
Return all of the descendants of a DefaultTreeNode as a List, optionally including the starting node.


descendantsOfNode

public static java.util.List descendantsOfNode(TreeNode startingNode,
                                               boolean includeStartingNode,
                                               TreeView treeView)
Return all of the descendants of a com.metamatrix.common.tree.TreeNode as a List, optionally including the starting node.


descendantsOfNode

public static java.util.List descendantsOfNode(javax.swing.tree.TreeNode startingNode)
Return all of the descendants of a javax.swing.tree.TreeNode as a List, never including the starting node.


collapse

public static void collapse(javax.swing.JTree tree)
Collapse an entire tree.


nodesString

public static java.lang.String nodesString(javax.swing.tree.DefaultTreeModel model)
For debug. Represent a tree as a string, with children indented. Assumes all nodes are DefaultMutableTreeNodes.


nodesString

public static java.lang.String nodesString(javax.swing.JTree tree)

treePathToString

public static java.lang.String treePathToString(javax.swing.tree.TreePath tp,
                                                boolean classNamesOnly)
For debug. toString() implementation for a TreePath, given the TreePath;


treePathToString

public static java.lang.String treePathToString(javax.swing.tree.TreePath tp)

treePathToString

public static java.lang.String treePathToString(javax.swing.tree.TreeNode node,
                                                boolean classNamesOnly)
For debug. toString() implementation for a TreePath, given the path's last node.


treePathToString

public static java.lang.String treePathToString(javax.swing.tree.TreeNode node)

allTreePaths

public static javax.swing.tree.TreePath[] allTreePaths(javax.swing.tree.TreeModel tm,
                                                       boolean populate,
                                                       TreeView treeView)
                                                throws java.lang.Exception
Return an array of all tree paths in a tree model.

Throws:
java.lang.Exception

allTreePaths

public static javax.swing.tree.TreePath[] allTreePaths(javax.swing.tree.TreeModel tm,
                                                       TreeView treeView)
                                                throws java.lang.Exception
Throws:
java.lang.Exception

allTreePaths

public static javax.swing.tree.TreePath[] allTreePaths(javax.swing.tree.TreeModel tm,
                                                       boolean populate)
                                                throws java.lang.Exception
Throws:
java.lang.Exception

allTreePathsToLeafNodes

public static javax.swing.tree.TreePath[] allTreePathsToLeafNodes(javax.swing.tree.TreeModel tm)

allTreePathsToString

public static java.lang.String allTreePathsToString(javax.swing.JTree tree,
                                                    TreeView treeView)
Returns a String representing all of the tree paths in a tree, also showing whether or not each tree path is expanded.


allTreePathsToString

public static java.lang.String allTreePathsToString(javax.swing.tree.TreeModel model,
                                                    boolean classNamesOnly,
                                                    TreeView treeView)
Returns a String representing all of the tree paths in a tree, also showing whether or not each tree path is expanded.


allTreePathsToString

public static java.lang.String allTreePathsToString(javax.swing.tree.TreeModel model)

allTreePathsToNode

public static java.util.Collection allTreePathsToNode(java.lang.Object nodeUserObject,
                                                      javax.swing.tree.TreeModel model,
                                                      TreeView treeView)
Return all tree paths where the last node is a given node. This will return those tree paths whose last node is a DefaultMutableTreeNode having a user object which matches the given object, using the equals() method. Does NOT populate any unpopulated LazyBranchNodes.


allTreePathsToNode

public static java.util.Collection allTreePathsToNode(java.lang.Object nodeUserObject,
                                                      javax.swing.tree.TreeModel model)

indexInTreePath

public static int indexInTreePath(java.lang.String name,
                                  javax.swing.tree.TreePath tp)
Return the index of a given name in a tree path, using the toString() method of each node. Return -1 if not found.


populateTree

public static void populateTree(javax.swing.tree.TreeNode root)
                         throws java.lang.Exception
Given a root node, this method populates any nodes in a tree that are LazyBranchNodes. Unfortunately, this may be required so that it can be known whether or not a child node is eligible to be added. If it is an ancestor node of the group then it is not eligible, and the tree must be populated to find out.

Throws:
java.lang.Exception

populateTree

public static void populateTree(TreeNode root,
                                TreeView treeView)
Given a com.metamatrix.common.tree.TreeNode as a root starting point, not necessarily a real root, populate all of its descendant nodes. This is done by repetitively calling getChildren();


expansionState

public static TreePathExpansion[] expansionState(javax.swing.JTree tree,
                                                 TreeView treeView,
                                                 boolean populate)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

expansionState

public static TreePathExpansion[] expansionState(javax.swing.JTree tree)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

expansionState

public static TreePathExpansion[] expansionState(javax.swing.JTree tree,
                                                 boolean populate)
                                          throws java.lang.Exception
Throws:
java.lang.Exception

restoreExpansionState

public static void restoreExpansionState(javax.swing.JTree tree,
                                         TreePathExpansion[] savedPathState,
                                         boolean expandNewPaths,
                                         java.util.Collection selectionListeners,
                                         java.util.Collection willExpandListeners,
                                         java.util.Collection expansionListeners,
                                         TreeView treeView)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

restoreExpansionState

public static void restoreExpansionState(javax.swing.JTree tree,
                                         TreePathExpansion[] savedPathState,
                                         boolean expandNewPaths,
                                         java.util.Collection selectionListeners,
                                         java.util.Collection willExpandListeners,
                                         java.util.Collection expansionListeners)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

restoreExpansionState

public static void restoreExpansionState(javax.swing.JTree tree,
                                         TreePathExpansion[] savedPathState,
                                         boolean expandNewPaths,
                                         TreeView treeView)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

restoreExpansionState

public static void restoreExpansionState(javax.swing.JTree tree,
                                         TreePathExpansion[] savedPathState,
                                         boolean expandNewPaths)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

allExpandedPaths

public static javax.swing.tree.TreePath[] allExpandedPaths(javax.swing.JTree tree,
                                                           TreeView treeView)

treePathsEqual

public static boolean treePathsEqual(javax.swing.tree.TreePath tp1,
                                     javax.swing.tree.TreePath tp2)
Compare two tree paths using toString()


nodeWithObjectOf

public static javax.swing.tree.DefaultMutableTreeNode nodeWithObjectOf(javax.swing.tree.TreeModel tree,
                                                                       java.lang.Object userObj)
Returns the first node found whose user object equals the given object. This method assumes that all nodes in the given tree are DefaultMutableTreeNodes, and may throw an exception if this is not true.


deselectAll

public static void deselectAll(javax.swing.JTree tree)
Deselect all selected tree paths in a JTree.


removeNode

public static int removeNode(java.lang.Object node,
                             javax.swing.tree.TreeModel model)
Remove all occurrences of a node from a tree model. Assumes the model contains only DefaultMutableTreeNode objects, and uses the "equals" method to compare the user object of each node to the given parameter. Returns number of occurrences of the node that were removed.


indexOfUserObject

public static int indexOfUserObject(javax.swing.tree.DefaultMutableTreeNode node,
                                    java.lang.Object userObject)
Return the child index in a DefaultMutableTreeNode of a child whose user object equals the given object. Returns -1 if not found.


treePathToStrings

public static java.lang.String[] treePathToStrings(javax.swing.tree.TreePath tp)
Return a String array representing the toString() results of each element in a TreePath.


nodeAtToStringPath

public static javax.swing.tree.DefaultMutableTreeNode nodeAtToStringPath(javax.swing.tree.TreeModel tm,
                                                                         java.lang.String[] tsp)
Return the node at the end of a "path" consisting an array of Strings representing the toString() results of a corresponding tree node.


userTabPaintProblemDuplicateNodeCheck

public static void userTabPaintProblemDuplicateNodeCheck(javax.swing.JTree tree)
Method inserted specifically to help solve a User tab painting problem. Duplicates of nodes are sporadically being seen in the User tab's trees. The goal is to call this method when painting, to see if the duplicates are also in the tree model. This method will check the tree's model, and will log a message to System.err if it finds a duplicate of any node.


treePathToNode

public static javax.swing.tree.TreePath treePathToNode(javax.swing.JTree tree,
                                                       java.lang.Object node)

treePathToNodeUsingEquals

public static javax.swing.tree.TreePath treePathToNodeUsingEquals(javax.swing.JTree tree,
                                                                  java.lang.Object node)


Copyright © 2009. All Rights Reserved.