Interface NavNode<M,N extends NavNode<M,N>>
-
- All Superinterfaces:
Cloneable,Serializable,TreeNode
- All Known Implementing Classes:
NavTreeNode,NavTreeTableNode
public interface NavNode<M,N extends NavNode<M,N>> extends Cloneable, TreeNode, Serializable
Definition of a node with a optionalchildLoadorto build childs of node. A node is identified by angetId()of an associated data of typegetInternalClass(). 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 methodisStaticNode()gives this state. Note: A static node has nochildLoador.Node loading
Initialy node has no data child nodes, (isLoaded()equalsfalse). when model requires node's childs, it can load them via methodpopulateNode(NavBridge, NavDataProvider, boolean)andpopulateChilds(NavBridge, NavDataProvider)methods.Node rendering
theAbstractNavTreeCellRendererlooks theisDirty()state to know when render should be (re-)compute and set back the state tofalse. Each time, a node is modified, theisDirty()should be set totrue.- Since:
- 2.1
- Author:
- Tony Chemit - dev@tchemit.fr
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadd(N node)NfindNodeById(String id, NavBridge<M,N> bridge, NavDataProvider provider)Given anid, obtain the child with matching id.NgetChild(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.StringgetContext()StringgetId()Class<?>getInternalClass()NgetParent()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.StringtoString()-
Methods inherited from interface javax.swing.tree.TreeNode
children, getAllowsChildren, getChildAt, getChildCount, getIndex
-
-
-
-
Method Detail
-
getId
String getId()
-
getContext
String getContext()
-
getInternalClass
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
-
findNodeById
N findNodeById(String id, NavBridge<M,N> bridge, NavDataProvider provider)
Given anid, obtain the child with matching id. If node is NOTloaded, then first loads it (methodpopulateChilds(NavBridge, NavDataProvider)) then do search on direct childs of the node recursivly.- Parameters:
id- the id of the researched nodebridge- model owner of nodesprovider- data provider- Returns:
- the found node or
nullif not found
-
getChild
N getChild(String id, NavBridge<M,N> bridge, NavDataProvider provider)
Given anid, obtain the child with matching id. If node is NOTloaded, then first loads it (methodpopulateChilds(NavBridge, NavDataProvider)) then return on direct childs of the node.- Parameters:
id- the id of the researched nodebridge- model owner of nodesprovider- data provider- Returns:
- the found node or
nullif not found
-
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
-
getUserObject
Object getUserObject()
-
populateNode
void populateNode(NavBridge<M,N> bridge, NavDataProvider provider, boolean populateChilds)
To populate the node. A side-effect of this method is to setdirtythe node (renderer will recompute the render of the node). IfpopulateChildsis set totrue, then also populate childs of the node using the givendataProvider.- Parameters:
bridge- le delegate modèles content le noeudprovider- le provider de donnéespopulateChilds- un drapeau pour charger aussi les fils du noeud courant
-
populateChilds
void populateChilds(NavBridge<M,N> bridge, NavDataProvider provider)
To populate childs of the node (only when a none static node). A side-effect of this method is to setloadedof the node. For a static node, do nothing.- Parameters:
bridge- model owner of the nodeprovider- data provider
-
isRoot
boolean isRoot()
-
add
void add(N node)
-
remove
void remove(N node)
-
insert
void insert(N node, int position)
-
-