Wt  3.2.1
Public Types | Public Member Functions | Protected Member Functions
Wt::WTreeNode Class Reference

A single node in a tree. More...

#include <Wt/WTreeNode>

Inheritance diagram for Wt::WTreeNode:
Inheritance graph
[legend]

List of all members.

Public Types

enum  LoadPolicy { LazyLoading, PreLoading, NextLevelLoading }
 An enumeration for the policy to load children. More...
enum  ChildCountPolicy { Disabled, Enabled, Lazy }
 An enumeration for the policy to display the child count. More...

Public Member Functions

 WTreeNode (const WString &labelText, WIconPair *labelIcon=0, WTreeNode *parentNode=0)
 Creates a tree node with the given label.
 ~WTreeNode ()
 Destructor.
virtual WTreetree () const
 Returns the tree.
WTextlabel () const
 Returns the label.
WIconPairlabelIcon () const
 Returns the label icon.
void setLabelIcon (WIconPair *labelIcon)
 Sets the label icon.
virtual void insertChildNode (int index, WTreeNode *node)
 Inserts a child node.
void addChildNode (WTreeNode *node)
 Adds a child node.
void removeChildNode (WTreeNode *node)
 Removes a child node.
const std::vector< WTreeNode * > & childNodes () const
 Returns the list of children.
virtual int displayedChildCount () const
 Returns the number of children that should be displayed.
void setChildCountPolicy (ChildCountPolicy policy)
 Configures how and when the child count should be displayed.
ChildCountPolicy childCountPolicy () const
 Returns the child count policy.
void setImagePack (const std::string &url)
 Sets the image pack for this (sub)tree (deprecated).
void setLoadPolicy (LoadPolicy loadPolicy)
 Sets the load policy for this tree.
bool isExpanded () const
 Returns whether this node is expanded.
void setSelectable (bool selectable)
 Allows this node to be selected.
virtual bool isSelectable () const
 Returns if this node may be selected.
WTreeNodeparentNode () const
 Returns the parent node.
void setNodeVisible (bool visible)
 Sets the visibility of the node itself.
void setChildrenDecorated (bool decorated)
 Sets whether this node's children are decorated.
void setInteractive (bool interactive)
 Sets whether this node is interactive.
void expand ()
 Expands this node.
void collapse ()
 Collapses this node.
EventSignal< WMouseEvent > & expanded ()
 Signal emitted when the node is expanded by the user.
EventSignal< WMouseEvent > & collapsed ()
 Signal emitted when the node is collapsed by the user.
Signal< bool > & selected ()
 Signal that is emitted when the node is added or removed from the selection

Protected Member Functions

 WTreeNode (WTreeNode *parentNode=0)
 Creates a tree node with empty labelArea().
WTableCelllabelArea ()
 Accesses the container widget that holds the label area.
virtual void populate ()
 Populates the node dynamically on loading.
bool populated () const
 Returns whether this node has already been populated.
virtual bool expandable ()
 Returns whether this node can be expanded.
virtual void renderSelected (bool selected)
 Renders the node to be selected.
std::string imagePack () const
 The image pack that is used for this tree node (deprecated).
virtual void descendantRemoved (WTreeNode *node)
 Reacts to the removal of a descendant node.
virtual void descendantAdded (WTreeNode *node)
 Reacts to the addition of a descendant node.
virtual void doExpand ()
 The actual expand.
virtual void doCollapse ()
 The actual collapse.
virtual void undoDoExpand ()
 Undo method for doCollapse() stateless implementation.
virtual void undoDoCollapse ()
 Undo method for doCollapse() stateless implementation.
WIconPairexpandIcon ()
 Accesses the icon pair that allows expansion of the tree node.

Detailed Description

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):

The default policy is WTreeNode::LazyLoading. 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 labelArea()) or if you want to modify or augment the event collapse/expand event handling (see doExpand() and doCollapse()).

See WTree for a usage example.

CSS

The tree is styled by the current CSS theme. The look can be overridden using the Wt-tree CSS class and the following selectors:

.Wt-tree .Wt-trunk          : vertical line, trunk
.Wt-tree .Wt-end            : vertical line, last item
.Wt-tree .Wt-collapse       : collapse icon (img *)
.Wt-tree .Wt-expand         : expand icon (img *)
.Wt-tree .Wt-noexpand       : leaf icon

.Wt-tree .Wt-label          : the node label
.Wt-tree .Wt-childcount     : the node child count
.Wt-tree .Wt-node           : the node's table row

* The collapse and expand icons are fetched themselves as images, nav-plus.gif and nav-minus.gif.

See also:
WTree, WTreeTableNode

Member Enumeration Documentation

An enumeration for the policy to display the child count.

Enumerator:
Disabled 

Do not display a child count.

Enabled 

Always display a child count.

Lazy 

Only display a child count when the node is populated.

An enumeration for the policy to load children.

Enumerator:
LazyLoading 

Load-on-demand of child nodes.

PreLoading 

Pre-load all child nodes.

NextLevelLoading 

Pre-load one level of child nodes.


Constructor & Destructor Documentation

Wt::WTreeNode::WTreeNode ( const WString labelText,
WIconPair labelIcon = 0,
WTreeNode parentNode = 0 
)

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.

Wt::WTreeNode::WTreeNode ( WTreeNode parentNode = 0) [protected]

Creates a tree node with empty labelArea().

This tree node has no label or labelicon, and is therefore ideally suited to provide a custom look.


Member Function Documentation

void Wt::WTreeNode::addChildNode ( WTreeNode node)

Adds a child node.

Equivalent to:

 insertChildNode(childNodes().size(), node);
See also:
insertChildNode()
ChildCountPolicy Wt::WTreeNode::childCountPolicy ( ) const

Returns the child count policy.

See also:
setChildCountPolicy(ChildCountPolicy policy)
void Wt::WTreeNode::collapse ( )

Collapses this node.

See also:
expand()
doCollapse()
EventSignal< WMouseEvent > & Wt::WTreeNode::collapsed ( )

Signal emitted when the node is collapsed by the user.

See also:
expanded()
void Wt::WTreeNode::descendantAdded ( WTreeNode node) [protected, virtual]

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.

void Wt::WTreeNode::descendantRemoved ( WTreeNode node) [protected, virtual]

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.

int Wt::WTreeNode::displayedChildCount ( ) const [virtual]

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 childNodes().size().

void Wt::WTreeNode::doCollapse ( ) [protected, virtual]

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()
void Wt::WTreeNode::doExpand ( ) [protected, virtual]

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()
void Wt::WTreeNode::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()
bool Wt::WTreeNode::expandable ( ) [protected, virtual]

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()
EventSignal< WMouseEvent > & Wt::WTreeNode::expanded ( )

Signal emitted when the node is expanded by the user.

See also:
collapsed()
std::string Wt::WTreeNode::imagePack ( ) const [protected]

The image pack that is used for this tree node (deprecated).

Deprecated:
This method returns "" since Wt 3.1.1, as the image pack is no longer used in favour of the CSS themes.
void Wt::WTreeNode::insertChildNode ( int  index,
WTreeNode node 
) [virtual]

Inserts a child node.

Inserts the node node at index index.

Reimplemented in Wt::WTreeTableNode.

virtual bool Wt::WTreeNode::isSelectable ( ) const [virtual]

Returns if this node may be selected.

See also:
setSelectable(bool)
WTableCell * Wt::WTreeNode::labelArea ( ) [protected]

Accesses the container widget that holds the label area.

Use this to customize how the label should look like.

WTreeNode* Wt::WTreeNode::parentNode ( ) const

Returns the parent node.

See also:
childNodes()
void Wt::WTreeNode::populate ( ) [protected, virtual]

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.

bool Wt::WTreeNode::populated ( ) const [protected]

Returns whether this node has already been populated.

See also:
populate()
void Wt::WTreeNode::removeChildNode ( WTreeNode node)

Removes a child node.

The child node itself is not deleted

void Wt::WTreeNode::renderSelected ( bool  selected) [protected, virtual]

Renders the node to be selected.

The default implementation changes the style class of the labelArea() to "selected".

Signal<bool>& Wt::WTreeNode::selected ( )

Signal that is emitted when the node is added or removed from the selection

See also:
WTree::itemSelectionChanged
void Wt::WTreeNode::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.

void Wt::WTreeNode::setChildrenDecorated ( bool  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 decorated to false, you can hide the decorations for the node's children.

void Wt::WTreeNode::setImagePack ( const std::string &  url)

Sets the image pack for this (sub)tree (deprecated).

Deprecated:
This method does not do anything since Wt 3.1.1, as the tree is now styled based on the current CSS theme.
void Wt::WTreeNode::setInteractive ( bool  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.

void Wt::WTreeNode::setLoadPolicy ( LoadPolicy  loadPolicy)

Sets the load policy for this tree.

This may only be set on the root of a tree, and before adding any children.

void Wt::WTreeNode::setNodeVisible ( bool  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.

void Wt::WTreeNode::setSelectable ( bool  selectable) [virtual]

Allows this node to be selected.

By default, all nodes may be selected.

See also:
isSelectable(), WTree::select(WTreeNode *, bool)

Reimplemented from Wt::WCompositeWidget.

WTree * Wt::WTreeNode::tree ( ) const [virtual]

Returns the tree.

By default if this node has no parent the result will be 0.

void Wt::WTreeNode::undoDoCollapse ( ) [protected, virtual]

Undo method for doCollapse() stateless implementation.

See also:
doExpand()
void Wt::WTreeNode::undoDoExpand ( ) [protected, virtual]

Undo method for doCollapse() stateless implementation.

See also:
doCollapse()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator

Generated on Fri Mar 30 2012 for the C++ Web Toolkit (Wt) by doxygen 1.7.5.1