Entering content frame

Procedure documentation Creating Actions for the Tree

Before you define actions, you must clarify which options will be available to the user of the application.

You want the user of this application to be able to expand the folders of the tree and select files. When a folder is expanded, you want all the files it contains to be displayed, as well as any subfolders. If a file is selected, you want the name of the file to be displayed on the screen. Nothing happens when a folder is selected.

There are two ways to implement the expansion of the folder. It is possible to load the whole file structure into the TreeView context during initialization of the TreeView. This variant is not suitable in this case, since the large file structure would mean a long loading process and transfer of a large amount of data. A more performance-efficient solution would be preferable.

For this reason, the nodes of a tree UI element have the event onLoadChildren, which is triggered whenever a node with no data is expanded. You can bind an action to this event to load all the necessary data belonging to the current node. In this tutorial, the data to be loaded comprises the folders and files located directly underneath the selected folder. A parameter value must be transferred to the action event handler, to enable it to know which node has been selected.

A tree node also has the event onAction. This is triggered whenever the user selects a tree entry. In this example, the user can select a file or a folder, but the event is only triggered when a file is selected. To be able to react when a file is selected, you must define a suitable action that is bound to the event of the tree node. You must also declare a parameter for this action to save the selected element.

Procedure

...

       1.      To open the View Designer, double-click TreeView in the project structure.

       2.      Choose the Actions tab page.

       3.      Choose New to create a new action with the name LoadChildren and choose Next.

       4.      To add a new parameter, choose New. Give this parameter the name element and for Type, choose This graphic is explained in the accompanying text.

       5.      In the dialog box that appears, select Java Native Type, then choose Browse... In the next dialog box that appears, enter ITreeNodeElement.

       6.      Choose OK twice and Finish twice.

       7.      Repeat steps 3 to 6 for another action with the name Select and the parameter selectedElement of the same type as in LoadChildren.

 

Result

You have defined the necessary actions that you will bind to the corresponding events of the tree later. These actions enable you to react to user entries. The implementation of the methods is covered later in the tutorial.

 

Next step:

Creating UI Elements

 

Leaving content frame