!--a11y-->
Creating the Context for the
TreeViewBefore you create the context for the TreeView, you must decide which data you want to display in the tree. This includes visible data, for example the text of a node, and invisible data, for example, whether a node can be selected.
The objective of this example application is to display a file structure in a tree and display the name of the selected file. This means that you need an attribute in the context in which the currently selected name is stored and can be displayed. Several context attributes are required for the nodes of the tree. The application requirements are as follows:
· Each node must be labeled
· A file must have a different icon to a folder
· A file is a leaf and can therefore have no further leaves or nodes
· A node must already be opened
· Selecting a file must trigger an event that displays the name of the file on the screen; selecting a folder must not trigger an event.
This results in several context attributes that you create in the TreeView context.
The TreeView is already contained in the template.
Context Element |
Type |
Properties |
Value |
|
Value node |
|
|
|
Recursion Node |
TreeView.treeNode |
|
|
Value attribute |
Type |
|
|
Value attribute |
Type |
|
|
Value attribute |
Type |
|
|
Value attribute |
Type |
|
|
Value attribute |
Type |
|
|
Value attribute |
Type |
A
tree represents a hierarchy as it is saved in the context. If, unlike in this
example, the tree is not recursive, you must implement the whole structure in
the context by using nodes and attributes. Make sure that the context nodes to
which the tree and the TreeNodes are bound have their singleton
property set to false, unless they are independent context nodes
located directly under the context root node (that is, at the top
level).
The treeNode context element later displays a folder or a file in the tree of the TreeView. The name of the folder or the file is saved in the text attribute. The hasChildren attribute specifies whether the node is to be a node or a leaf. You can use this attribute to set the iconSource to a folder icon or file icon. The isExpanded attribute is required to expand a node initially. You use the ignoreAction attribute to define whether or not the event onAction is triggered when this node is selected.
The recursive childNode node links to the treeNode, which can thus be nested as deeply as you like.
The TreeView context is defined and its file structure can be nested as deeply as is required. It also has the corresponding properties for displaying the tree as requested.
