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.Object
Base 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 class
AbstractGTreeNode.AllPathsIterator
-
Constructor Summary
Constructors Constructor Description AbstractGTreeNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNode(int index, GTreeNode node)
Adds the given node at the given index as a child to this node.void
addNode(GTreeNode node)
Adds the given node as a child to this node.java.lang.Iterable<javax.swing.tree.TreePath>
allPaths()
void
clearFilter()
Removes any filtering on this subtree.int
compareTo(GTreeNode node)
void
dispose()
Disposes this node and all of its descendants.protected void
doAddNode(int index, GTreeNode child)
protected java.util.List<GTreeNode>
doGetActiveChildren()
protected int
doGetAllChildCount()
protected java.util.List<GTreeNode>
doGetAllChildren()
protected GTreeNode
doGetChild(int index)
protected int
doGetChildCount()
protected int
doGetIndexOfChild(GTreeNode node)
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.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.protected void
doSetActiveChildren(java.util.List<GTreeNode> childList)
protected void
doSetChildren(java.util.List<GTreeNode> childList, boolean notify)
void
filter(GTreeFilter filter, TaskMonitor monitor, int min, int max)
Applies the the given filter to the subtree of this node.void
fireNodeChanged(GTreeNode parentNode, GTreeNode node)
Notifies the tree that a node has changed.void
fireNodeStructureChanged(GTreeNode node)
Notifies the tree that the node has different children.int
getAllChildCount()
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.GTreeNode
getChild(int index)
Returns the child node at the given index.GTreeNode
getChild(java.lang.String name)
Returns the child node of this node with the given name.int
getChildCount()
Returns the number of visible children of this node.java.util.List<GTreeNode>
getChildren()
Returns all of the visible children of this node.protected GTreeFilter
getFilter()
int
getIndexInParent()
Returns the index of this node within its parent node.int
getIndexOfChild(GTreeNode node)
Returns the index of the given node within this node.int
getLeafCount()
Returns the total number of leaf nodes in the subtree from this node.int
getNodeCount()
Returns the total number of nodes in the subtree rooted at this node.GTreeNode
getParent()
Returns the parent of this node.GTreeRootNode
getRoot()
Returns the rootNode for this tree or null if there is no parent path to a GTRootNode.GTree
getTree()
Returns the GTTree that contains this node.javax.swing.tree.TreePath
getTreePath()
Returns the TreePath for this node.int
hashCode()
boolean
isAncestor(GTreeNode node)
Returns true if the given node is a child of this node or one of its children.protected boolean
isChildrenLoaded()
boolean
isChildrenLoadedOrInProgress()
boolean
isEditable()
Returns true if this node is allowed to be edited in the tree.boolean
isFilteredOut()
Returns true if this node is filtered and not in the current viewboolean
isInProgress()
Returns true if this node is currently being modified.java.util.Iterator<GTreeNode>
iterator()
protected void
loadChildren()
This will be called when it is time to load children.void
removeAll()
Removes all children from this node.void
removeNode(GTreeNode node)
Remove the given node from this node.void
setChildren(java.util.List<GTreeNode> childList)
Sets the children on this node.protected void
setInProgress()
protected void
swingSetChildren(java.util.List<GTreeNode> childList, boolean notify, boolean onlyIfInProgress)
java.lang.String
toString()
void
valueChanged(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:GTreeNode
Adds 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:GTreeNode
Adds 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns 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:GTreeNode
Returns the TreePath for this node.- Returns:
- the TreePath for this node.
-
removeAll
public void removeAll()
Description copied from interface:GTreeNode
Removes all children from this node. The children nodes will be disposed.
-
setChildren
public void setChildren(java.util.List<GTreeNode> childList)
Description copied from interface:GTreeNode
Sets 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:GTreeNode
Returns 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:GTreeNode
Applies 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:GTreeNode
Removes any filtering on this subtree.
-
isFilteredOut
public boolean isFilteredOut()
Description copied from interface:GTreeNode
Returns true if this node is filtered and not in the current view
-
valueChanged
public void valueChanged(java.lang.Object newValue)
Description copied from interface:GTreeNode
Notification 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:GTreeNode
Returns 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:
hashCode
in classjava.lang.Object
-
getRoot
public GTreeRootNode getRoot()
Description copied from interface:GTreeNode
Returns 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:
toString
in classjava.lang.Object
-
getTree
public GTree getTree()
Description copied from interface:GTreeNode
Returns 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:GTreeNode
Returns the parent of this node.
-
dispose
public void dispose()
Description copied from interface:GTreeNode
Disposes this node and all of its descendants.
-
isInProgress
public boolean isInProgress()
Description copied from interface:GTreeNode
Returns true if this node is currently being modified.- Specified by:
isInProgress
in 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:GTreeNode
Remove the given node from this node.- Specified by:
removeNode
in 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:GTreeNode
Notifies the tree that a node has changed.- Specified by:
fireNodeChanged
in 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:GTreeNode
Notifies the tree that the node has different children. This method- Specified by:
fireNodeStructureChanged
in interfaceGTreeNode
- Parameters:
node
- the node that has changed.
-
-