Package docking.widgets.tree
Class AbstractGTreeNode
- java.lang.Object
-
- docking.widgets.tree.AbstractGTreeNode
-
- All Implemented Interfaces:
GTreeNode,java.lang.Comparable<GTreeNode>,java.lang.Iterable<GTreeNode>
- Direct Known Subclasses:
AbstractGTreeRootNode,DomainFileNode,FSBFileNode,GTreeLazyNode,GTreeSlowLoadingNode,InProgressGTreeNode
public abstract class AbstractGTreeNode extends java.lang.ObjectBase class for GTNodes. To create a simple GTNode where nodes will be added immediately using the addNode() methods, simply extend this class and implement the following methods:- getName()
- getToolTip()
- isLeaf()
- getIcon()
- The equals() method: The GTree has the ability to remember expanded and
selected states. This will only work if the nodes in the saved state can be matched
with the nodes in the GTree. Java will do this by using the equals() method.
There is a potential problem with this usage. If nodes within the GTree get rebuilt (
i.e., new nodes are created), then, by default, the expanded and selected state
feature will be unable to find the correct nodes, since the default equals()
method on GTreeNode performs a comparison based upon instances. To fix this problem you
must override the equals() method that can find the same logical nodes when
the instances in memory have changed; typically this is done by overriding equals()
to compare by node name.
The GTreeNode has already overridden
hashCode()so that the node name is used to generate the correct value. If you override theObject.equals(Object)method, and you do not compare only byGTreeNode.getName(), then you must also override thehashCode()method to generate a value based upon the same algorithm used by the new equals() method.
As a rule of thumb, unless you want to allow multiple nodes under one parent with the same name, then it is a swell idea to override the equals() method to compare on
GTreeNode.getName(), as outlined above.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractGTreeNode.AllPathsIterator
-
Constructor Summary
Constructors Constructor Description AbstractGTreeNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddNode(int index, GTreeNode node)Adds the given node at the given index as a child to this node.voidaddNode(GTreeNode node)Adds the given node as a child to this node.java.lang.Iterable<javax.swing.tree.TreePath>allPaths()voidclearFilter()Removes any filtering on this subtree.intcompareTo(GTreeNode node)voiddispose()Disposes this node and all of its descendants.protected voiddoAddNode(int index, GTreeNode child)protected java.util.List<GTreeNode>doGetActiveChildren()protected intdoGetAllChildCount()protected java.util.List<GTreeNode>doGetAllChildren()protected GTreeNodedoGetChild(int index)protected intdoGetChildCount()protected intdoGetIndexOfChild(GTreeNode node)protected intdoGetIndexOfChild(GTreeNode node, java.util.List<GTreeNode> children)Subclasses can override this method to perform faster lookups of a node; for example, if the subclass has a sorted list of children, then a binary search can be used.protected voiddoResetActiveChildren()Convenience method to clear any filtered items by restoring the active children of this node to be the complete set of children.protected voiddoSetActiveChildren(java.util.List<GTreeNode> childList)protected voiddoSetChildren(java.util.List<GTreeNode> childList, boolean notify)voidfilter(GTreeFilter filter, TaskMonitor monitor, int min, int max)Applies the the given filter to the subtree of this node.voidfireNodeChanged(GTreeNode parentNode, GTreeNode node)Notifies the tree that a node has changed.voidfireNodeStructureChanged(GTreeNode node)Notifies the tree that the node has different children.intgetAllChildCount()Returns the number of all children of this node.java.util.List<GTreeNode>getAllChildren()Returns the list of children including those that have been filtered out.GTreeNodegetChild(int index)Returns the child node at the given index.GTreeNodegetChild(java.lang.String name)Returns the child node of this node with the given name.intgetChildCount()Returns the number of visible children of this node.java.util.List<GTreeNode>getChildren()Returns all of the visible children of this node.protected GTreeFiltergetFilter()intgetIndexInParent()Returns the index of this node within its parent node.intgetIndexOfChild(GTreeNode node)Returns the index of the given node within this node.intgetLeafCount()Returns the total number of leaf nodes in the subtree from this node.intgetNodeCount()Returns the total number of nodes in the subtree rooted at this node.GTreeNodegetParent()Returns the parent of this node.GTreeRootNodegetRoot()Returns the rootNode for this tree or null if there is no parent path to a GTRootNode.GTreegetTree()Returns the GTTree that contains this node.javax.swing.tree.TreePathgetTreePath()Returns the TreePath for this node.inthashCode()booleanisAncestor(GTreeNode node)Returns true if the given node is a child of this node or one of its children.protected booleanisChildrenLoaded()booleanisChildrenLoadedOrInProgress()booleanisEditable()Returns true if this node is allowed to be edited in the tree.booleanisFilteredOut()Returns true if this node is filtered and not in the current viewbooleanisInProgress()Returns true if this node is currently being modified.java.util.Iterator<GTreeNode>iterator()protected voidloadChildren()This will be called when it is time to load children.voidremoveAll()Removes all children from this node.voidremoveNode(GTreeNode node)Remove the given node from this node.voidsetChildren(java.util.List<GTreeNode> childList)Sets the children on this node.protected voidsetInProgress()protected voidswingSetChildren(java.util.List<GTreeNode> childList, boolean notify, boolean onlyIfInProgress)java.lang.StringtoString()voidvalueChanged(java.lang.Object newValue)Notification method called when a cell editor completes editing to notify this node that its value has changed.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface docking.widgets.tree.GTreeNode
getIcon, getName, getToolTip, isLeaf
-
-
-
-
Method Detail
-
loadChildren
protected void loadChildren()
This will be called when it is time to load children. Some subclasses may not use this method, but may instead have children externally added.
-
addNode
public void addNode(GTreeNode node)
Description copied from interface:GTreeNodeAdds the given node as a child to this node.- Parameters:
node- the node to add as a child.
-
addNode
public void addNode(int index, GTreeNode node)Description copied from interface:GTreeNodeAdds the given node at the given index as a child to this node.- Parameters:
index- the index to place the node.node- the node to add as a child of this node.
-
compareTo
public int compareTo(GTreeNode node)
-
getAllChildren
public java.util.List<GTreeNode> getAllChildren()
Description copied from interface:GTreeNodeReturns the list of children including those that have been filtered out.- Returns:
- the list of all children of this node including those that are filtered out.
-
getChildren
public java.util.List<GTreeNode> getChildren()
Description copied from interface:GTreeNodeReturns all of the visible children of this node. If there are filtered nodes, then they will not be returned.- Returns:
- all of the visible children of this node. If there are filtered nodes, then they will not be returned.
-
getChildCount
public int getChildCount()
Description copied from interface:GTreeNodeReturns the number of visible children of this node. Does not include nodes that are current filtered out.- Returns:
- the number of visible children of this node.
-
getAllChildCount
public int getAllChildCount()
Description copied from interface:GTreeNodeReturns the number of all children of this node. Includes nodes that are currently filtered out.- Returns:
- the number of all
-
getChild
public GTreeNode getChild(java.lang.String name)
Description copied from interface:GTreeNodeReturns the child node of this node with the given name.- Parameters:
name- the name of the child to be returned.- Returns:
- the child with the given name.
-
getChild
public GTreeNode getChild(int index)
Description copied from interface:GTreeNodeReturns the child node at the given index. Returns null if the index is out of bounds.- Parameters:
index- the index of the child to be returned.- Returns:
- the child at the given index.
-
getNodeCount
public int getNodeCount()
Description copied from interface:GTreeNodeReturns the total number of nodes in the subtree rooted at this node. Leaf nodes return 1.- Returns:
- the number of nodes from this node downward.
-
getLeafCount
public int getLeafCount()
Description copied from interface:GTreeNodeReturns the total number of leaf nodes in the subtree from this node.- Returns:
- the total number of leaf nodes in the subtree from this node.
-
getIndexInParent
public int getIndexInParent()
Description copied from interface:GTreeNodeReturns the index of this node within its parent node.- Returns:
- the index of this node within its parent node.
-
getIndexOfChild
public int getIndexOfChild(GTreeNode node)
Description copied from interface:GTreeNodeReturns the index of the given node within this node. -1 is returned if the node is not a child of this node.- Parameters:
node- whose index we want.- Returns:
- the index of the given node within this node.
-
getTreePath
public javax.swing.tree.TreePath getTreePath()
Description copied from interface:GTreeNodeReturns the TreePath for this node.- Returns:
- the TreePath for this node.
-
removeAll
public void removeAll()
Description copied from interface:GTreeNodeRemoves all children from this node. The children nodes will be disposed.
-
setChildren
public void setChildren(java.util.List<GTreeNode> childList)
Description copied from interface:GTreeNodeSets the children on this node. Any existing current children will be dispose.- Parameters:
childList- this list of nodes to be set as children of this node.
-
isAncestor
public boolean isAncestor(GTreeNode node)
Description copied from interface:GTreeNodeReturns true if the given node is a child of this node or one of its children.- Parameters:
node- the potential descendant node to check
-
allPaths
public java.lang.Iterable<javax.swing.tree.TreePath> allPaths()
-
iterator
public java.util.Iterator<GTreeNode> iterator()
-
filter
public void filter(GTreeFilter filter, TaskMonitor monitor, int min, int max) throws CancelledException
Description copied from interface:GTreeNodeApplies the the given filter to the subtree of this node. Nodes will be filtered out if the node and all of its descendants are not accepted by the filter. In other words, a node will remain if it or any of its descendants are accepted by the filter.- Parameters:
filter- the filter being applied.monitor- a TaskMonitor for tracking the progress and cancelling.min- the min value to use for the progress bar for this subtree.max- the max value to use for the progress bar for this subtree.- Throws:
CancelledException- if the operation is cancelled via the TaskMonitor.
-
clearFilter
public void clearFilter()
Description copied from interface:GTreeNodeRemoves any filtering on this subtree.
-
isFilteredOut
public boolean isFilteredOut()
Description copied from interface:GTreeNodeReturns true if this node is filtered and not in the current view
-
valueChanged
public void valueChanged(java.lang.Object newValue)
Description copied from interface:GTreeNodeNotification method called when a cell editor completes editing to notify this node that its value has changed. If you override this method you must also overrideGTreeNode.isEditable().- Parameters:
newValue- the new value provided by the cell editor.- See Also:
GTreeNode.isEditable()
-
isEditable
public boolean isEditable()
Description copied from interface:GTreeNodeReturns true if this node is allowed to be edited in the tree. You must override this method to allow a node to be edited. You must also overrideGTreeNode.valueChanged(Object)to handle the result of the edit.- Returns:
- true if this node is allowed to be edited in the tree.
- See Also:
GTreeNode.valueChanged(Object)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getRoot
public GTreeRootNode getRoot()
Description copied from interface:GTreeNodeReturns the rootNode for this tree or null if there is no parent path to a GTRootNode.- Returns:
- the rootNode for this tree.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getTree
public GTree getTree()
Description copied from interface:GTreeNodeReturns the GTTree that contains this node.- Returns:
- the GTTree that contains this node.
-
getFilter
protected GTreeFilter getFilter()
-
getParent
public GTreeNode getParent()
Description copied from interface:GTreeNodeReturns the parent of this node.
-
dispose
public void dispose()
Description copied from interface:GTreeNodeDisposes this node and all of its descendants.
-
isInProgress
public boolean isInProgress()
Description copied from interface:GTreeNodeReturns true if this node is currently being modified.- Specified by:
isInProgressin interfaceGTreeNode- Returns:
- true if this node is currently being modified.
-
setInProgress
protected void setInProgress()
-
isChildrenLoadedOrInProgress
public boolean isChildrenLoadedOrInProgress()
-
isChildrenLoaded
protected boolean isChildrenLoaded()
-
doGetChildCount
protected int doGetChildCount()
-
doGetAllChildCount
protected int doGetAllChildCount()
-
doGetAllChildren
protected java.util.List<GTreeNode> doGetAllChildren()
-
doGetActiveChildren
protected java.util.List<GTreeNode> doGetActiveChildren()
-
doGetChild
protected GTreeNode doGetChild(int index)
-
doGetIndexOfChild
protected int doGetIndexOfChild(GTreeNode node)
-
doGetIndexOfChild
protected int doGetIndexOfChild(GTreeNode node, java.util.List<GTreeNode> children)
Subclasses can override this method to perform faster lookups of a node; for example, if the subclass has a sorted list of children, then a binary search can be used.- Parameters:
node- the node whose index we seekchildren- the children who contain the given node (may be null)- Returns:
- the index of the given child in the given list
-
doAddNode
protected void doAddNode(int index, GTreeNode child)
-
removeNode
public void removeNode(GTreeNode node)
Description copied from interface:GTreeNodeRemove the given node from this node.- Specified by:
removeNodein interfaceGTreeNode- Parameters:
node- the to be removed.
-
doSetChildren
protected void doSetChildren(java.util.List<GTreeNode> childList, boolean notify)
-
swingSetChildren
protected void swingSetChildren(java.util.List<GTreeNode> childList, boolean notify, boolean onlyIfInProgress)
-
doSetActiveChildren
protected void doSetActiveChildren(java.util.List<GTreeNode> childList)
-
doResetActiveChildren
protected void doResetActiveChildren()
Convenience method to clear any filtered items by restoring the active children of this node to be the complete set of children.
-
fireNodeChanged
public void fireNodeChanged(GTreeNode parentNode, GTreeNode node)
Description copied from interface:GTreeNodeNotifies the tree that a node has changed.- Specified by:
fireNodeChangedin interfaceGTreeNode- Parameters:
parentNode- the node that contains the node that was changed.node- the that changed.
-
fireNodeStructureChanged
public void fireNodeStructureChanged(GTreeNode node)
Description copied from interface:GTreeNodeNotifies the tree that the node has different children. This method- Specified by:
fireNodeStructureChangedin interfaceGTreeNode- Parameters:
node- the node that has changed.
-
-