What Happens at Runtime: Disclosing Row Data

10-32 Web User Interface Developers Guide for Oracle Application Development Framework

10.5 Displaying Data in Trees

The ADF Faces tree component displays hierarchical data, such as organization charts or hierarchical directory structures. In data of these types, there may be a series of top-level nodes, and each element in the structure may expand to contain other elements. As an example, in an organization chart, each element, that is, each employee, in the hierarchy may have any number of child elements direct reports. The tree component supports multiple root elements. It displays the data in a form that represents the structure, with each element indented to the appropriate level to indicate its level in the hierarchy, and connected to its parent. Users can expand and collapse portions of the hierarchy. Figure 10–19 shows a tree used to display directories in the File Explorer application. Figure 10–19 Tree Component in the File Explorer Application The ADF Faces tree component uses a model to access the data in the underlying hierarchy. The specific model class is oracle.adf.view.rich.model.TreeModel, which extends CollectionModel, described in Section 10.2, Displaying Data in Tables. You must create your own tree model to support your tree. The tree model is a collection of rows. It has an isContainer method that returns true if the current row contains child rows. To access the children of the current row, you call the enterContainer method. Calling this method results in the TreeModel instance changing to become a collection of the child rows. To revert back up to the parent collection, you call the exitContainer method. You may find the oracle.adf.view.rich.model.ChildPropertyTreeModel class useful when constructing a TreeModel class, as shown in Example 10–10 . Example 10–10 Constructing a TreeModel ListTreeNode root = new ArrayListTreeNode; forint i = 0; i firstLevelSize; i++ { ListTreeNode level1 = new ArrayListTreeNode; forint j = 0; j i; j++ { ListTreeNode level2 = new ArrayListTreeNode; forint k=0; kj; k++ Using Tables and Trees 10-33 { TreeNode z = new TreeNodenull, _nodeVali,j,k; level2.addz; } TreeNode c = new TreeNodelevel2, _nodeVali,j; level1.addc; } TreeNode n = new TreeNodelevel1, _nodeVali; root.addn; } ChildPropertyTreeModel model = new ChildPropertyTreeModelroot, children; private String _nodeValInteger... args { StringBuilder s = new StringBuilder; forInteger i : args s.appendi; return s.toString; } You can manipulate the tree similar to the way you can manipulate a table. You can do the following: ■ To make a node current, call the setRowIndex method on the tree with the appropriate index into the list. Alternatively, call the setRowKey method with the appropriate rowKey object. ■ To access a particular node, first make that node current, and then call the getRowData method on the tree. ■ To access rows for expanded or collapsed nodes, call getAddedSet and getRemovedSet methods on the RowDisclosureEvent. For more information, see Section 10.5.4, What You May Need to Know About Programmatically Expanding and Collapsing Nodes. ■ To manipulate the node’s child collection, call the enterContainer method before calling the setRowIndex and setRowKey methods. Then call the exitContainer method to return to the parent node. ■ To point to a rowKey for a node inside the tree at any level use the focusRowKey attribute. The focusRowKey attribute is set when the user right-clicks on a node and selects the Show as top context menu item or the Show as top toolbar button in the panelCollection component. When the focusRowKey attribute is set, the tree renders the node pointed to by the focusRowKey attribute as the root node in the Tree and displays a Hierarchical Selector icon next to the root node. Clicking the Hierarchical Selector icon displays a Hierarchical Selector dialog which shows the path to the focusRowKey object from the root node of the tree. How this displays depends on the components placed in the pathStamp facet. As with tables, trees use stamping to display content for the individual nodes. Trees contain a nodeStamp facet, which is a holder for the component used to display the Note: If your application uses the Fusion technology stack, then you can use data controls to create trees and the model will be created for you. For more information see the Displaying Master-Detail Data chapter of the Oracle Fusion Middleware Web User Interface Developers Guide for Oracle Application Development Framework