Class WTreeNode
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WWidget
-
- eu.webtoolkit.jwt.WCompositeWidget
-
- eu.webtoolkit.jwt.WTreeNode
-
- Direct Known Subclasses:
WTreeTableNode
public class WTreeNode extends WCompositeWidget
A single node in a tree.A tree list is constructed by combining several tree node objects in a tree hierarchy, by passing the parent tree node as the last argument in the child node constructor, or by using
addChildNode(), to add a child to its parent.Each tree node has a label, and optionally a label icon pair. The icon pair offers the capability to show a different icon depending on the state of the node (expanded or collapsed). When the node has any children, a child count may be displayed next to the label using
setChildCountPolicy().Expanding a tree node it will collapse all its children, so that a user may collapse/expand a node as a short-cut to collapsing all children.
The treenode provides several policies to communicate the current contents of the tree to the client (if possible):
ContentLoading.Eager: the entire tree is transmitted to the client, and all tree navigation requires no further communication.- ContentLoading::Lazy: only the minimum is transmitted to the client. When expanding a node for the first time, only then it is transmitted to the client, and this may thus have some latency.
ContentLoading.NextLevel: all leafs of visible children are transmitted, but not their children. This provides a good trade-off between bandwith use and interactivity, since expanding any tree node will happen instantly, and at the same time trigger some communication in the back-ground to load the next level of invisible nodes.
The default policy is ContentLoading::Lazy. Another load policy may be specified using
setLoadPolicy()on the root node and before adding any children. The load policy is inherited by all children in the tree.There are a few scenarios where it makes sense to specialize the WTreeNode class. One scenario is create a tree that is populated dynamically while browsing. For this purpose you should reimplement the
populate()method, whose default implementation does nothing. This method is called when 'loading' the node. The exact moment for loading a treenode depends on the LoadPolicy.A second scenario that is if you want to customize the look of the tree label (see
getLabelArea()) or if you want to modify or augment the event collapse/expand event handling (seedoExpand()anddoCollapse()).See
WTreefor a usage example.- See Also:
WTree,WTreeTableNode
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedWTreeNode()Creates a tree node with emptygetLabelArea().protectedWTreeNode(WTreeNode parentNode)Creates a tree node with emptygetLabelArea().WTreeNode(java.lang.CharSequence labelText)Creates a tree node with the given label.WTreeNode(java.lang.CharSequence labelText, WIconPair labelIcon)Creates a tree node with the given label.WTreeNode(java.lang.CharSequence labelText, WIconPair labelIcon, WTreeNode parentNode)Creates a tree node with the given label.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WTreeNodeaddChildNode(WTreeNode node)Adds a child node.voidcollapse()Collapses this node.EventSignal1<WMouseEvent>collapsed()Signal emitted when the node is collapsed by the user.protected voiddescendantAdded(WTreeNode node)Reacts to the addition of a descendant node.protected voiddescendantRemoved(WTreeNode node)Reacts to the removal of a descendant node.protected voiddoCollapse()The actual collapse.protected voiddoExpand()The actual expand.voidexpand()Expands this node.EventSignal1<WMouseEvent>expanded()Signal emitted when the node is expanded by the user.ChildCountPolicygetChildCountPolicy()Returns the child count policy.java.util.List<WTreeNode>getChildNodes()Returns the list of children.intgetDisplayedChildCount()Returns the number of children that should be displayed.protected WIconPairgetExpandIcon()Accesses the icon pair that allows expansion of the tree node.protected WTemplategetImpl()WTextgetLabel()Returns the label.protected WContainerWidgetgetLabelArea()Accesses the container widget that holds the label area.WIconPairgetLabelIcon()Returns the label icon.WTreeNodegetParentNode()Returns the parent node.WTreegetTree()Returns the tree.voidinsertChildNode(int index, WTreeNode node)Inserts a child node.protected booleanisExpandable()Returns whether this node can be expanded.booleanisExpanded()Returns whether this node is expanded.protected booleanisPopulated()Returns whether this node has already been populated.booleanisSelectable()Returns if this node may be selected.protected voidpopulate()Populates the node dynamically on loading.voidremove()Destructor.WTreeNoderemoveChildNode(WTreeNode node)Removes a child node.protected voidrenderSelected(boolean isSelected)Renders the node to be selected.Signal1<java.lang.Boolean>selected()Signal that is emitted when the node is added or removed from the selectionvoidsetChildCountPolicy(ChildCountPolicy policy)Configures how and when the child count should be displayed.voidsetChildrenDecorated(boolean decorated)Sets whether this node's children are decorated.voidsetInteractive(boolean interactive)Sets whether this node is interactive.voidsetLabelIcon(WIconPair labelIcon)Sets the label icon.voidsetLoadPolicy(ContentLoading loadPolicy)Sets the load policy for this tree.voidsetNodeVisible(boolean visible)Sets the visibility of the node itself.voidsetSelectable(boolean selectable)Allows this node to be selected.protected voidundoDoCollapse()Undo method fordoCollapse()stateless implementation.protected voidundoDoExpand()Undo method fordoCollapse()stateless implementation.-
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, findById, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getObjectName, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getTakeImplementation, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, load, propagateSetEnabled, propagateSetVisible, refresh, removeStyleClass, removeWidget, render, resize, scrollVisibilityChanged, setAttributeValue, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
-
-
-
Constructor Detail
-
WTreeNode
public WTreeNode(java.lang.CharSequence labelText, WIconPair labelIcon, WTreeNode parentNode)Creates a tree node with the given label.The labelIcon, if specified, will appear just before the label and its state reflect the expand/collapse state of the node.
The node is initialized to be collapsed.
-
WTreeNode
public WTreeNode(java.lang.CharSequence labelText)
Creates a tree node with the given label.
-
WTreeNode
public WTreeNode(java.lang.CharSequence labelText, WIconPair labelIcon)Creates a tree node with the given label.
-
WTreeNode
protected WTreeNode(WTreeNode parentNode)
Creates a tree node with emptygetLabelArea().This tree node has no label or labelicon, and is therefore ideally suited to provide a custom look.
-
WTreeNode
protected WTreeNode()
Creates a tree node with emptygetLabelArea().Calls
this((WTreeNode)null)
-
-
Method Detail
-
remove
public void remove()
Destructor.- Overrides:
removein classWCompositeWidget- See Also:
WWidget.removeWidget(WWidget widget)
-
getTree
public WTree getTree()
Returns the tree.By default if this node has no parent the result will be 0.
-
getLabel
public WText getLabel()
Returns the label.
-
getLabelIcon
public WIconPair getLabelIcon()
Returns the label icon.
-
setLabelIcon
public void setLabelIcon(WIconPair labelIcon)
Sets the label icon.
-
insertChildNode
public void insertChildNode(int index, WTreeNode node)Inserts a child node.Inserts the node
nodeat indexindex.
-
addChildNode
public WTreeNode addChildNode(WTreeNode node)
Adds a child node.Equivalent to:
insertChildNode(childNodes().size(), std::move(node));
-
getChildNodes
public java.util.List<WTreeNode> getChildNodes()
Returns the list of children.
-
getDisplayedChildCount
public int getDisplayedChildCount()
Returns the number of children that should be displayed.This is used to display the count in the count label. The default implementation simply returns
getChildNodes().size().
-
setChildCountPolicy
public void setChildCountPolicy(ChildCountPolicy policy)
Configures how and when the child count should be displayed.By default, no child count indication is disabled (this is the behaviour since 2.1.1). Use this method to enable child count indications.
The child count policy is inherited by all children in the tree.
-
getChildCountPolicy
public ChildCountPolicy getChildCountPolicy()
Returns the child count policy.
-
setLoadPolicy
public void setLoadPolicy(ContentLoading loadPolicy)
Sets the load policy for this tree.This may only be set on the root of a tree, and before adding any children.
-
isExpanded
public boolean isExpanded()
Returns whether this node is expanded.
-
setSelectable
public void setSelectable(boolean selectable)
Allows this node to be selected.By default, all nodes may be selected.
- Overrides:
setSelectablein classWCompositeWidget- See Also:
isSelectable(),WTree.select(WTreeNode node, boolean selected)
-
isSelectable
public boolean isSelectable()
Returns if this node may be selected.- See Also:
setSelectable(boolean selectable)
-
getParentNode
public WTreeNode getParentNode()
Returns the parent node.- See Also:
getChildNodes()
-
setNodeVisible
public void setNodeVisible(boolean visible)
Sets the visibility of the node itself.If
false, then the node itself is not displayed, but only its children. This is typically used to hide the root node of a tree.
-
setChildrenDecorated
public void setChildrenDecorated(boolean decorated)
Sets whether this node's children are decorated.By default, node's children have expand/collapse and other lines to display their linkage and offspring.
By setting
decoratedtofalse, you can hide the decorations for the node's children.
-
setInteractive
public void setInteractive(boolean interactive)
Sets whether this node is interactive.Interactive nodes can be clicked upon and will populate a list of children when clicked. By disabling the interactivity, a node will not react to a click event.
-
expand
public void expand()
Expands this node.Besides the actual expansion of the node, this may also trigger the loading and population of the node children, or of the children's children.
- See Also:
collapse(),doExpand()
-
collapse
public void collapse()
Collapses this node.- See Also:
expand(),doCollapse()
-
expanded
public EventSignal1<WMouseEvent> expanded()
Signal emitted when the node is expanded by the user.- See Also:
collapsed()
-
collapsed
public EventSignal1<WMouseEvent> collapsed()
Signal emitted when the node is collapsed by the user.- See Also:
expanded()
-
selected
public Signal1<java.lang.Boolean> selected()
Signal that is emitted when the node is added or removed from the selection- See Also:
WTree.itemSelectionChanged()
-
getLabelArea
protected WContainerWidget getLabelArea()
Accesses the container widget that holds the label area.Use this to customize how the label should look like.
-
populate
protected void populate()
Populates the node dynamically on loading.Reimplement this method if you want to populate the widget dynamically, as the tree is being browsed and therefore loaded. This is only usefull with LazyLoading or NextLevelLoading strategies.
-
isPopulated
protected boolean isPopulated()
Returns whether this node has already been populated.- See Also:
populate()
-
isExpandable
protected boolean isExpandable()
Returns whether this node can be expanded.The default implementation populates the node if necessary, and then checks if there are any child nodes.
You may wish to reimplement this method if you reimplement
populate(), and you have a quick default for determining whether a node may be expanded (which does not require populating the node).- See Also:
populate()
-
renderSelected
protected void renderSelected(boolean isSelected)
Renders the node to be selected.The default implementation changes the style class of the
getLabelArea()to "selected".
-
descendantRemoved
protected void descendantRemoved(WTreeNode node)
Reacts to the removal of a descendant node.Reimplement this method if you wish to react on the removal of a descendant node. The default implementation simply propagates the event to the parent.
-
descendantAdded
protected void descendantAdded(WTreeNode node)
Reacts to the addition of a descendant node.Reimplement this method if you wish to react on the addition of a descendant node. The default implementation simply propagates the event to the parent.
-
doExpand
protected void doExpand()
The actual expand.This method, which is implemented as a stateless slot, performs the actual expansion of the node.
You may want to reimplement this function (and
undoDoExpand()) if you wish to do additional things on node expansion.- See Also:
doCollapse(),expand()
-
doCollapse
protected void doCollapse()
The actual collapse.This method, which is implemented as a stateless slot, performs the actual collapse of the node.
You may want to reimplement this function (and
undoDoCollapse()) if you wish to do additional things on node expansion.- See Also:
doExpand(),collapse()
-
undoDoExpand
protected void undoDoExpand()
Undo method fordoCollapse()stateless implementation.- See Also:
doCollapse()
-
undoDoCollapse
protected void undoDoCollapse()
Undo method fordoCollapse()stateless implementation.- See Also:
doExpand()
-
getExpandIcon
protected WIconPair getExpandIcon()
Accesses the icon pair that allows expansion of the tree node.
-
getImpl
protected WTemplate getImpl()
-
-