Effect picture
Code as bellow
*&---------------------------------------------------------------------* *& Include TLIST_TREE_CONTROL_DEMOTOP * *& * *&---------------------------------------------------------------------* REPORT SAPTLIST_TREE_CONTROL_DEMO MESSAGE-ID TREE_CONTROL_MSG. CLASS LCL_APPLICATION DEFINITION DEFERRED. CLASS CL_GUI_CFW DEFINITION LOAD. * CAUTION: MTREEITM is the name of the item structure which must * be defined by the programmer. DO NOT USE MTREEITM! TYPES: ITEM_TABLE_TYPE LIKE STANDARD TABLE OF MTREEITM WITH DEFAULT KEY. DATA: G_APPLICATION TYPE REF TO LCL_APPLICATION, G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER, G_TREE TYPE REF TO CL_GUI_LIST_TREE, G_OK_CODE TYPE SY-UCOMM. * Fields on Dynpro 100 DATA: G_EVENT(30), G_NODE_KEY TYPE TV_NODEKEY, G_ITEM_NAME TYPE TV_ITMNAME. CONSTANTS: BEGIN OF c_nodekey, root TYPE tv_nodekey VALUE 'Root', "#EC NOTEXT child1 TYPE tv_nodekey VALUE 'Child1', "#EC NOTEXT child2 TYPE tv_nodekey VALUE 'Child2', "#EC NOTEXT new1 TYPE tv_nodekey VALUE 'New1', "#EC NOTEXT new2 TYPE tv_nodekey VALUE 'New2', "#EC NOTEXT new3 TYPE tv_nodekey VALUE 'New3', "#EC NOTEXT new4 TYPE tv_nodekey VALUE 'New4', "#EC NOTEXT END OF c_nodekey.
*----------------------------------------------------------------------* * INCLUDE TLIST_TREE_CONTROL_DEMOCL1 * *----------------------------------------------------------------------* CLASS LCL_APPLICATION DEFINITION. PUBLIC SECTION. METHODS: HANDLE_NODE_DOUBLE_CLICK FOR EVENT NODE_DOUBLE_CLICK OF CL_GUI_LIST_TREE IMPORTING NODE_KEY, HANDLE_EXPAND_NO_CHILDREN FOR EVENT EXPAND_NO_CHILDREN OF CL_GUI_LIST_TREE IMPORTING NODE_KEY, HANDLE_ITEM_DOUBLE_CLICK FOR EVENT ITEM_DOUBLE_CLICK OF CL_GUI_LIST_TREE IMPORTING NODE_KEY ITEM_NAME, HANDLE_BUTTON_CLICK FOR EVENT BUTTON_CLICK OF CL_GUI_LIST_TREE IMPORTING NODE_KEY ITEM_NAME, HANDLE_LINK_CLICK FOR EVENT LINK_CLICK OF CL_GUI_LIST_TREE IMPORTING NODE_KEY ITEM_NAME, HANDLE_CHECKBOX_CHANGE FOR EVENT CHECKBOX_CHANGE OF CL_GUI_LIST_TREE IMPORTING NODE_KEY ITEM_NAME CHECKED. ENDCLASS. "LCL_APPLICATION DEFINITION *----------------------------------------------------------------------* * CLASS LCL_APPLICATION IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS LCL_APPLICATION IMPLEMENTATION. METHOD HANDLE_NODE_DOUBLE_CLICK. " this method handles the node double click event of the tree " control instance " show the key of the double clicked node in a dynpro field G_EVENT = 'NODE_DOUBLE_CLICK'. G_NODE_KEY = NODE_KEY. ENDMETHOD. "HANDLE_NODE_DOUBLE_CLICK METHOD HANDLE_ITEM_DOUBLE_CLICK. " this method handles the item double click event of the tree " control instance " show the key of the node and the name of the item " of the double clicked item in a dynpro field G_EVENT = 'ITEM_DOUBLE_CLICK'. G_NODE_KEY = NODE_KEY. G_ITEM_NAME = ITEM_NAME. ENDMETHOD. "HANDLE_ITEM_DOUBLE_CLICK METHOD HANDLE_LINK_CLICK. " this method handles the link click event of the tree " control instance " show the key of the node and the name of the item " of the clicked link in a dynpro field G_EVENT = 'LINK_CLICK'. G_NODE_KEY = NODE_KEY. G_ITEM_NAME = ITEM_NAME. ENDMETHOD. "HANDLE_LINK_CLICK METHOD HANDLE_BUTTON_CLICK. " this method handles the button click event of the tree " control instance " show the key of the node and the name of the item " of the clicked button in a dynpro field G_EVENT = 'BUTTON_CLICK'. G_NODE_KEY = NODE_KEY. G_ITEM_NAME = ITEM_NAME. ENDMETHOD. "HANDLE_BUTTON_CLICK METHOD HANDLE_CHECKBOX_CHANGE. " this method handles the checkbox_change event of the tree " control instance " show the key of the node and the name of the item " of the clicked checkbox in a dynpro field G_EVENT = 'CHECKBOX_CHANGE'. G_NODE_KEY = NODE_KEY. G_ITEM_NAME = ITEM_NAME. ENDMETHOD. "HANDLE_CHECKBOX_CHANGE METHOD HANDLE_EXPAND_NO_CHILDREN. DATA: NODE_TABLE TYPE TREEV_NTAB, NODE TYPE TREEV_NODE, ITEM_TABLE TYPE ITEM_TABLE_TYPE, ITEM TYPE MTREEITM. * show the key of the expanded node in a dynpro field G_EVENT = 'EXPAND_NO_CHILDREN'. G_NODE_KEY = NODE_KEY. IF node_key = c_nodekey-child2. * add the children for node with key 'Child2' * Node with key 'New3' CLEAR NODE. node-node_key = c_nodekey-new3. node-relatkey = c_nodekey-child2. NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD. APPEND NODE TO NODE_TABLE. * Node with key 'New4' CLEAR NODE. node-node_key = c_nodekey-new4. node-relatkey = c_nodekey-child2. NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD. APPEND NODE TO NODE_TABLE. * Items of node with key 'New3' CLEAR ITEM. item-node_key = c_nodekey-new3. ITEM-ITEM_NAME = '1'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 11. ITEM-USEBGCOLOR = 'X'. " ITEM-TEXT = 'SAPTROX1'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new3. ITEM-ITEM_NAME = '2'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Kommentar zu SAPTROX1'(001). APPEND ITEM TO ITEM_TABLE. * Items of node with key 'New4' CLEAR ITEM. item-node_key = c_nodekey-new4. ITEM-ITEM_NAME = '1'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 11. ITEM-USEBGCOLOR = 'X'. " ITEM-TEXT = 'SAPTRIXTROX'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new4. ITEM-ITEM_NAME = '2'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Kommentar zu SAPTRIXTROX'(002). APPEND ITEM TO ITEM_TABLE. ENDIF. CALL METHOD G_TREE->ADD_NODES_AND_ITEMS EXPORTING NODE_TABLE = NODE_TABLE ITEM_TABLE = ITEM_TABLE ITEM_TABLE_STRUCTURE_NAME = 'MTREEITM' EXCEPTIONS FAILED = 1 CNTL_SYSTEM_ERROR = 3 ERROR_IN_TABLES = 4 DP_ERROR = 5 TABLE_STRUCTURE_NAME_NOT_FOUND = 6. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. ENDMETHOD. "HANDLE_EXPAND_NO_CHILDREN ENDCLASS. "LCL_APPLICATION IMPLEMENTATION
*------------------------------------------------------------------- ***INCLUDE list_tree_control_demoO01 . *------------------------------------------------------------------- *&---------------------------------------------------------------------* *& Module PBO_0400 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE PBO_100 OUTPUT. SET PF-STATUS 'MAIN'. IF G_TREE IS INITIAL. " The Tree Control has not been created yet. " Create a Tree Control and insert nodes into it. PERFORM CREATE_AND_INIT_TREE. ENDIF. ENDMODULE. " PBO_0100 OUTPUT *** INCLUDE list_tree_control_demoO01 *------------------------------------------------------------------- ***INCLUDE list_tree_control_demoI01 . *------------------------------------------------------------------- *&---------------------------------------------------------------------* *& Module PAI_0400 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE PAI_100 INPUT. data: return_code type i. * CL_GUI_CFW=>DISPATCH must be called if events are registered * that trigger PAI * this method calls the event handler method of an event CALL METHOD CL_GUI_CFW=>DISPATCH importing return_code = return_code. if return_code <> cl_gui_cfw=>rc_noevent. " a control event occured => exit PAI clear g_ok_code. exit. endif. CASE G_OK_CODE. WHEN 'BACK'. " Finish program IF NOT G_CUSTOM_CONTAINER IS INITIAL. " destroy tree container (detroys contained tree control, too) CALL METHOD G_CUSTOM_CONTAINER->FREE EXCEPTIONS CNTL_SYSTEM_ERROR = 1 CNTL_ERROR = 2. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. CLEAR G_CUSTOM_CONTAINER. CLEAR G_TREE. ENDIF. LEAVE PROGRAM. ENDCASE. * CAUTION: clear ok code! CLEAR G_OK_CODE. ENDMODULE. " PAI_0100 INPUT *** INCLUDE list_tree_control_demoI01
*------------------------------------------------------------------- ***INCLUDE list_tree_control_demoF01 . *------------------------------------------------------------------- *&---------------------------------------------------------------------* *& Form CREATE_AND_INIT_TREE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM CREATE_AND_INIT_TREE. DATA: NODE_TABLE TYPE TREEV_NTAB, ITEM_TABLE TYPE ITEM_TABLE_TYPE, EVENTS TYPE CNTL_SIMPLE_EVENTS, event type cntl_simple_event. * create a container for the tree control CREATE OBJECT G_CUSTOM_CONTAINER EXPORTING " the container is linked to the custom control with the " name 'TREE_CONTAINER' on the dynpro CONTAINER_NAME = 'TREE_CONTAINER' EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 LIFETIME_DYNPRO_DYNPRO_LINK = 5. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. * create a list tree CREATE OBJECT g_tree EXPORTING PARENT = G_CUSTOM_CONTAINER NODE_SELECTION_MODE = CL_GUI_LIST_TREE=>NODE_SEL_MODE_SINGLE ITEM_SELECTION = 'X' WITH_HEADERS = ' ' EXCEPTIONS CNTL_SYSTEM_ERROR = 1 CREATE_ERROR = 2 FAILED = 3 ILLEGAL_NODE_SELECTION_MODE = 4 LIFETIME_ERROR = 5. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. * define the events which will be passed to the backend " node double click event-eventid = CL_GUI_list_TREE=>EVENTID_NODE_DOUBLE_CLICK. event-appl_event = 'X'. " append event to events. " item double click EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_ITEM_DOUBLE_CLICK. event-appl_event = 'X'. append event to events. " expand no children EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_EXPAND_NO_CHILDREN. event-appl_event = 'X'. append event to events. " link click EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_LINK_CLICK. event-appl_event = 'X'. append event to events. " button click EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_BUTTON_CLICK. event-appl_event = 'X'. append event to events. " checkbox change EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_CHECKBOX_CHANGE. event-appl_event = 'X'. append event to events. CALL METHOD G_TREE->SET_REGISTERED_EVENTS EXPORTING EVENTS = EVENTS EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 ILLEGAL_EVENT_COMBINATION = 3. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. * assign event handlers in the application class to each desired event SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR G_TREE. SET HANDLER G_APPLICATION->HANDLE_ITEM_DOUBLE_CLICK FOR G_TREE. SET HANDLER G_APPLICATION->HANDLE_EXPAND_NO_CHILDREN FOR G_TREE. SET HANDLER G_APPLICATION->HANDLE_LINK_CLICK FOR G_TREE. SET HANDLER G_APPLICATION->HANDLE_BUTTON_CLICK FOR G_TREE. SET HANDLER G_APPLICATION->HANDLE_CHECKBOX_CHANGE FOR G_TREE. * add some nodes to the tree control * NOTE: the tree control does not store data at the backend. If an * application wants to access tree data later, it must store the * tree data itself. PERFORM BUILD_NODE_AND_ITEM_TABLE USING NODE_TABLE ITEM_TABLE. CALL METHOD G_TREE->ADD_NODES_AND_ITEMS EXPORTING NODE_TABLE = NODE_TABLE ITEM_TABLE = ITEM_TABLE ITEM_TABLE_STRUCTURE_NAME = 'MTREEITM' EXCEPTIONS FAILED = 1 CNTL_SYSTEM_ERROR = 3 ERROR_IN_TABLES = 4 DP_ERROR = 5 TABLE_STRUCTURE_NAME_NOT_FOUND = 6. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. ENDFORM. " CREATE_AND_INIT_TREE *&---------------------------------------------------------------------* *& Form build_node_and_item_table *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM BUILD_NODE_AND_ITEM_TABLE USING NODE_TABLE TYPE TREEV_NTAB ITEM_TABLE TYPE ITEM_TABLE_TYPE. DATA: NODE TYPE TREEV_NODE, ITEM TYPE MTREEITM. * Build the node table. * Caution: The nodes are inserted into the tree according to the order * in which they occur in the table. In consequence, a node must not * must not occur in the node table before its parent node. * Node with key 'Root' node-node_key = c_nodekey-root. " Key of the node CLEAR NODE-RELATKEY. " Special case: A root node has no parent CLEAR NODE-RELATSHIP. " node. NODE-HIDDEN = ' '. " The node is visible, NODE-DISABLED = ' '. " selectable, NODE-ISFOLDER = 'X'. " a folder. CLEAR NODE-N_IMAGE. " Folder-/ Leaf-Symbol in state "closed": " use default. CLEAR NODE-EXP_IMAGE. " Folder-/ Leaf-Symbol in state "open": " use default CLEAR NODE-EXPANDER. " see below. " the width of the item is adjusted to its content (text) APPEND NODE TO NODE_TABLE. * Node with key 'Child1' CLEAR NODE. node-node_key = c_nodekey-child1. " Key of the node " Node is inserted as child of the node with key 'Root'. node-relatkey = c_nodekey-root. NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD. NODE-ISFOLDER = 'X'. APPEND NODE TO NODE_TABLE. * Node with key 'New1' CLEAR NODE. node-node_key = c_nodekey-new1. node-relatkey = c_nodekey-child1. NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD. APPEND NODE TO NODE_TABLE. * Node with key 'New2' CLEAR NODE. node-node_key = c_nodekey-new2. node-relatkey = c_nodekey-child1. NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD. APPEND NODE TO NODE_TABLE. * Node with key 'Child2' CLEAR NODE. node-node_key = c_nodekey-child2. node-relatkey = c_nodekey-root. NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD. NODE-ISFOLDER = 'X'. NODE-EXPANDER = 'X'. " The node is marked with a '+', although " it has no children. When the user clicks on the " + to open the node, the event expand_nc is " fired. The programmerr can " add the children of the " node within the event handler of the expand_nc " event (see callback handle_expand_nc). APPEND NODE TO NODE_TABLE. * The items of the nodes: * Node with key 'Root' CLEAR ITEM. item-node_key = c_nodekey-root. ITEM-ITEM_NAME = '1'. " Item with name '1' ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. " Text Item " the with of the item is adjusted to its content (text) ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. " use proportional font for the item ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Objekte'(003). APPEND ITEM TO ITEM_TABLE. * Node with key 'Child1' CLEAR ITEM. item-node_key = c_nodekey-child1. ITEM-ITEM_NAME = '1'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Dynpros'(004). APPEND ITEM TO ITEM_TABLE. * Node with key 'Child2' CLEAR ITEM. item-node_key = c_nodekey-child2. ITEM-ITEM_NAME = '1'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Programme'(005). APPEND ITEM TO ITEM_TABLE. * Items of node with key 'New1' CLEAR ITEM. item-node_key = c_nodekey-new1. ITEM-ITEM_NAME = '1'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 4. " the width of the item is 4 characters ITEM-IGNOREIMAG = 'X'. " see documentation of Structure " TREEV_ITEM ITEM-USEBGCOLOR = 'X'. " item has light grey background ITEM-T_IMAGE = '@01@'. " icon of the item APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new1. ITEM-ITEM_NAME = '2'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 4. ITEM-USEBGCOLOR = 'X'. ITEM-TEXT = '0100'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new1. ITEM-ITEM_NAME = '3'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 11. ITEM-USEBGCOLOR = 'X'. " ITEM-TEXT = 'MUELLER'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new1. ITEM-ITEM_NAME = '4'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Kommentar zu Dynpro 100'(006). APPEND ITEM TO ITEM_TABLE. * Items of node with key 'New2' CLEAR ITEM. item-node_key = c_nodekey-new2. ITEM-ITEM_NAME = '1'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 4. " the width of the item is 2 characters ITEM-IGNOREIMAG = 'X'. " see documentation of Structure " TREEV_ITEM ITEM-USEBGCOLOR = 'X'. " item has light grey background ITEM-T_IMAGE = '@02@'. " icon of the item APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new2. ITEM-ITEM_NAME = '2'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 4. ITEM-USEBGCOLOR = 'X'. ITEM-TEXT = '0200'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new2. ITEM-ITEM_NAME = '3'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-LENGTH = 11. ITEM-USEBGCOLOR = 'X'. " ITEM-TEXT = 'HARRYHIRSCH'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-new2. ITEM-ITEM_NAME = '4'. ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO. ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP. item-text = 'Kommentar zu Dynpro 200'(007). APPEND ITEM TO ITEM_TABLE. ENDFORM. " build_node_and_item_table *** INCLUDE tlist_tree_control_demoF01
START-OF-SELECTION. * create the application object * this object is needed to handle the ABAP Objects Events of * Controls CREATE OBJECT G_APPLICATION. SET SCREEN 100.