Getting Started with the Simple Tree Model
Use
This section describes how to create, use, and destroy an instance of the SAP simple tree model.
Prerequisites
The process described here is an extension of the general process for using controls that is specific to the simple tree. It does not contain all of the steps required to produce a valid instance of the control.
Process
-
Create the Instance for the Backend Model
-
Define a reference variable for the simple tree model:
DATA simple_model TYPE REF TO cl_simple_tree_model.
-
Define a reference variable for the simple tree model:
CREATE OBJECT simple_model EXPORTING node_selection_mode = node_selection_mode hide_selection = hide_selection EXCEPTIONS illegal_node_selection_mode = 1.
-
-
Create the frontend control
-
Call the method create_tree_control for the simple_model instance. This creates the frontend control in which the data from the simple tree model is displayed.
CALL METHOD simple_model->create_tree_control EXPORTING parent = container EXCEPTIONS lifetime_error = 1 cntl_system_error = 2 create_error = 3 failed = 4 tree_control_already_created = 5.
-
-
Register the Events
-
Register the events of the simple tree model that you want to use. The control supports the following events:
Event Name
Meaning
NODE_DOUBLE_CLICK
User double-clicked a node
NODE_KEYPRESS
User pressed a certain key The keys that trigger this event must be registered beforehand
EXPAND_NO_CHILDREN
User expanded a node that has no child nodes
SELECTION_CHANGED
The selected node has changed
NODE_CONTEXT_MENU_REQUEST
Request of a context menu for a node
NODE_CONTEXT_MENU_SELECT
User selected an entry from the context menu
DEFAULT_CONTEXT_MENU_REQUEST
User requested a context menu with the cursor positioned on an empty space in the control
DEFAULT_CONTEXT_MENU_SELECT
User selected an entry from the context menu
-
-
Fill the Simple Tree Model with Nodes
-
Add nodes to the simple tree model.
Fill a node table with the relevant node information, then pass it to the tree model using the add_node method:
CALL METHOD simple_model->add_nodes EXPORTING nodes_table = nodes_table EXCEPTIONS error_in_node_table = 1.
-
-
Work with the Tree Model
-
Find out any node attributes that you need.
-
Change any node attributes as required.
-
-
Remove the Control
-
Remove the control container at the front end. This removes tree control instance contained within it as well.
CALL METHOD container->free.
-
Release the reference to the simple tree model. It will then be deleted by the garbage collector.
FREE simple_model.
-