Package jaxx.runtime.swing.nav
Interface NavNode<M,N extends NavNode<M,N>>
- All Superinterfaces:
java.lang.Cloneable,java.io.Serializable,javax.swing.tree.TreeNode
- All Known Implementing Classes:
NavTreeNode,NavTreeTableNode
public interface NavNode<M,N extends NavNode<M,N>>
extends java.lang.Cloneable, javax.swing.tree.TreeNode, java.io.Serializable
Definition of a node with a optional
childLoador to build childs of
node.
A node is identified by an getId() of an associated data of type
getInternalClass().
Note:
While using a childLoador, we can not know before node
was loaded the exact count of his childs. As a matter of facts, real leaf
nodes appears at the beginning in ui as a not leaf (there is a root handler).
When node was loaded, a leaf node will be then displayed as required.
Why NavNode is generic ?
In a project, you should implements your own Node extending with one like this :
class MyNode extends NavNode<MyNode> { ... }
While in this class, you overrides every method with a node return type,
co-variance you'll be able to use this code :
MyNode parentNode = new MyNode(); MyNode node = parentNode.getFirstNode();So for final application this generic type avoid any cast for your own node type, this is quite convinient. Even if in your project, you wants to have a heriarchy of nodes, this will still works (if you use a genercic type on your abstract nodes).
Internal states
- internalClass : the type of data associated with the node
- context : an optinal context to distinguish different types of
node with same
internalclass - id : id of the data associated with the node
- dirty : flag sets to
truewhen node render MUST be recomputed - loaded : flag sets to
truewhen node was loaded - childLoador : optional loador of childs
Static nodes
Some nodes do not need auto-loading, we call themstatic nodes.
The method isStaticNode() gives this state.
Note: A static node has no childLoador.
Node loading
Initialy node has no data child nodes, (isLoaded() equals
false).
when model requires node's childs, it can load them via method
populateNode(NavBridge, NavDataProvider, boolean)
and populateChilds(NavBridge, NavDataProvider) methods.
Node rendering
theAbstractNavTreeCellRenderer looks the isDirty() state to
know when render should be (re-)compute and set back the state to false.
Each time, a node is modified, the isDirty() should be set to true.- Since:
- 2.1
- Author:
- Tony Chemit - chemit@codelutin.com
-
Method Summary
Modifier and Type Method Description voidadd(N node)NfindNodeById(java.lang.String id, NavBridge<M,N> bridge, NavDataProvider provider)Given anid, obtain the child with matching id.NgetChild(java.lang.String id, NavBridge<M,N> bridge, NavDataProvider provider)Given anid, obtain the child with matching id.NgetContainerNode()Gets the first node form this one to the root which has a noneStringtype.java.lang.StringgetContext()java.lang.StringgetId()java.lang.Class<?>getInternalClass()NgetParent()java.lang.ObjectgetUserObject()voidinsert(N node, int position)booleanisDirty()booleanisLeaf()booleanisLoaded()booleanisRoot()booleanisStaticNode()To know if the node is static.booleanisStringNode()Convinient method to known if the node is aStringtyped.voidpopulateChilds(NavBridge<M,N> bridge, NavDataProvider provider)To populate childs of the node (only when a none static node).voidpopulateNode(NavBridge<M,N> bridge, NavDataProvider provider, boolean populateChilds)To populate the node.voidremove(N node)voidsetDirty(boolean dirty)Changes theisDirty()state.java.lang.StringtoString()Methods inherited from interface javax.swing.tree.TreeNode
children, getAllowsChildren, getChildAt, getChildCount, getIndex
-
Method Details
-
getId
java.lang.String getId() -
getContext
java.lang.String getContext() -
getInternalClass
java.lang.Class<?> getInternalClass() -
isLoaded
boolean isLoaded() -
isDirty
boolean isDirty() -
isStringNode
boolean isStringNode()Convinient method to known if the node is aStringtyped.- Returns:
trueif the type of node if
-
isStaticNode
boolean isStaticNode()To know if the node is static. Astaticnode has nochildLoador.- Returns:
truewhen the node is static : says, the node has nochildLoador.
-
getContainerNode
N getContainerNode()Gets the first node form this one to the root which has a noneStringtype.- Returns:
- the first concrete node type
-
setDirty
void setDirty(boolean dirty)Changes theisDirty()state. As a side effect, when a renderer will use this node, it will force to reload the render from theNavDataProvider.- Parameters:
dirty- the new dirty value
-
isLeaf
boolean isLeaf()- Specified by:
isLeafin interfacejavax.swing.tree.TreeNode
-
getUserObject
java.lang.Object getUserObject() -
toString
java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
isRoot
boolean isRoot() -
getParent
N getParent()- Specified by:
getParentin interfacejavax.swing.tree.TreeNode
-
add
-
remove
-
insert
-