Chapter 7. Trees

7.1. TreeWidget & TreeNodeWidget

org.araneaframework.uilib.tree.TreeWidget allows representation of hierarchical data in a manner that has become traditional in GUIs, as an expandable tree. TreeWidget represents trees' root node, which is special in that it is not really rendered on-screen but serves as point where child nodes are attached. Child nodes of TreeWidget are either attached by the programmer or acquired from associated TreeDataProvider. The TreeWidget supports expanding and collapsing of all those nodes.

TreeDataProvider is a simple interface with ability to return the data under given tree node.

public interface TreeDataProvider extends Serializable {
  /**
   * Returns a list of child nodes for specified parent node.
   */
  List<TreeNodeWidget> getChildren(TreeNodeContext parent);

  /**
   * Returns if the specified tree node has any children.
   */
  boolean hasChildren(TreeNodeContext parent);
}

As is apparent from the definition of TreeDataProvider, descendants of the TreeWidget that are to be presented in a tree, must be of type TreeNodeWidget. TreeNodeWidget is the superclass of TreeWidget that also has child nodes and will be rendered too. Node rendering is done with display widget that is passed to TreeNodeWidget in its constructor.

public TreeNodeWidget(Widget display);
public TreeNodeWidget(Widget display, List nodes);
public TreeNodeWidget(Widget display, List nodes, boolean collapsed);

Display widget can be any widget that can render itself, it is rendered in the place of tree node instead of TreeNodeWidget, which is just a data holder. Very often, display widget is BaseUIWidget which renders itself according to some JSP template. TreeNodeWidget does not accept independent TreeDataProvider, its children are acquired from TreeWidget's TreeDataProvider.

TreeWidget enriches the Environment with TreeContext. TreeNodeWidget enriches the Environment of its display widget with TreeNodeContext. Through these contexts display widgets have access to owning tree node and root of the tree.

7.2. Tree JSP tags

7.2.1. <ui:tree>

Renders tree with given id.

Attributes

AttributeRequiredDescription
idyesID of the tree widget.

Examples

<?xml version="1.0" encoding="UTF-8"?>
<ui:tree id="simpleTree"/>
<!-- nothing more required, nodes' display widgets will take care of rendering the tree nodes.>