REPORT z_tree_template. ************************************************************************ *** *** VARIABLES *** ************************************************************************ *** CLASSES *** CLASS: cl_tree_events DEFINITION DEFERRED, cl_gui_cfw DEFINITION LOAD. *** INTERNAL TABLES *** DATA: v_nodes TYPE mtreesnode, i_nodes TYPE STANDARD TABLE OF mtreesnode. *** OBJECTS *** DATA: o_tree_listener TYPE REF TO cl_tree_events, o_tree TYPE REF TO cl_gui_simple_tree. ************************************************************************ *** *** CLASSES *** ************************************************************************ *---------------------------------------------------------------------- * CLASS CL_TREE_EVENTS DEFINITION *---------------------------------------------------------------------- * [+] Class for handling events on o_tree *---------------------------------------------------------------------- CLASS cl_tree_events DEFINITION. PUBLIC SECTION. METHODS: handle_node_double_click FOR EVENT node_double_click OF cl_gui_simple_tree IMPORTING node_key. ENDCLASS. "cl_tree_events DEFINITION *---------------------------------------------------------------------- * CLASS CL_TREE_EVENTS IMPLEMENTATION *---------------------------------------------------------------------- * [+] Class for handling events on o_tree *---------------------------------------------------------------------- CLASS cl_tree_events IMPLEMENTATION. *---------------------------------------------------------------------* * METHOD HANDLE_NODE_DOUBLE_CLICK *---------------------------------------------------------------------* * [+] Processes a double-click on a node *---------------------------------------------------------------------* METHOD handle_node_double_click. WRITE: / node_key. ENDMETHOD. "handle_node_double_click ENDCLASS. "cl_tree_events IMPLEMENTATION ************************************************************************ *** *** MAIN PROCESSING *** ************************************************************************ *---------------------------------------------------------------------- * START-OF-SELECTION *---------------------------------------------------------------------- START-OF-SELECTION. * Create the event listener object CREATE OBJECT o_tree_listener. SET SCREEN 100. ************************************************************************ *** *** DOCKING AND TREE OBJECT METHODS *** ************************************************************************ *---------------------------------------------------------------------- * FORM BUILD_WINDOW *---------------------------------------------------------------------- * [+] Constructs and loads the data into the window... * [+] Builds the tree * [+] Loads the tree nodes *---------------------------------------------------------------------- FORM build_window. * Local variables DATA: li_events TYPE cntl_simple_events, "events lv_events TYPE cntl_simple_event, "events lv_repid TYPE syrepid. "report ID * Setting variables lv_repid = sy-repid. * Create the tree object CREATE OBJECT o_tree EXPORTING parent = parent_container node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single. * Define the events to listen for lv_events-eventid = cl_gui_simple_tree=>eventid_node_double_click. lv_events-appl_event = 'X'. " process PAI if event occurs APPEND lv_events TO li_events. CALL METHOD o_tree->set_registered_events EXPORTING events = li_events. * Set the event listeners SET HANDLER o_tree_listener->handle_node_double_click FOR o_tree. * Build the tree PERFORM build_tree. ENDFORM. "build_window *---------------------------------------------------------------------- * FORM BUILD_TREE *---------------------------------------------------------------------- * [+] Loads the tree nodes *---------------------------------------------------------------------- FORM build_tree. * NODES ARE INSERTED IN THE ORDER SHOWN. * DO NOT DEFINE A CHILD BEFORE ITS PARENT NODE! * Root Node CLEAR v_nodes. v_nodes-node_key = 'Root'. v_nodes-isfolder = 'X'. v_nodes-text = 'Root Node'. APPEND v_nodes TO i_nodes. * First Branch * folder code parent image name PERFORM add_node USING 'X' 'Child1' 'Root' '' 'Child Node 1'. PERFORM add_node USING ' ' 'Leaf1' 'Child1' '' 'Leaf Node 1'. PERFORM add_node USING ' ' 'Leaf2' 'Child1' '@10@' 'Leaf Node 2'. * Second Branch * folder code parent image name PERFORM add_node USING 'X' 'Child2' 'Root' '' 'Child Node 2'. PERFORM add_node USING ' ' 'Leaf3' 'Child2' '' 'Leaf Node 3'. * Adds the nodes to the tree. CALL METHOD o_tree->add_nodes EXPORTING table_structure_name = 'MTREESNODE' node_table = i_nodes. ENDFORM. "build_tree *---------------------------------------------------------------------- * FORM ADD_NODE *---------------------------------------------------------------------- * [+] Adds a node to the tree *---------------------------------------------------------------------- FORM add_node USING p_folder TYPE c p_code TYPE c p_parent TYPE c p_image TYPE c p_name TYPE c. CLEAR: v_nodes. v_nodes-node_key = p_code. v_nodes-relatkey = p_parent. v_nodes-relatship = cl_gui_simple_tree=>relat_last_child. v_nodes-isfolder = p_folder. v_nodes-text = p_name. v_nodes-n_image = p_image. APPEND v_nodes TO i_nodes. ENDFORM. "add_node ************************************************************************ *** *** MODULES *** ************************************************************************ *---------------------------------------------------------------------- * MODULE LOAD_TREE *---------------------------------------------------------------------- * [+] Loads the tree *---------------------------------------------------------------------- MODULE load_tree OUTPUT. SET PF-STATUS 'MAIN'. IF o_tree IS INITIAL. * build the tree PERFORM build_window. ENDIF. ENDMODULE. "load_tree OUTPUT *---------------------------------------------------------------------- * MODULE PROCESS_EVENTS_0100 *---------------------------------------------------------------------- * [+] Processes the events from the dock/tree *---------------------------------------------------------------------- MODULE process_events_0100 INPUT. DATA: lv_tree_return_code TYPE i. * If the tree made an event that affects PAI, * then dont process the event here. CALL METHOD cl_gui_cfw=>dispatch IMPORTING return_code = lv_tree_return_code. IF lv_tree_return_code <> cl_gui_cfw=>rc_noevent. CLEAR v_ok_code. EXIT. ENDIF. CASE v_ok_code. WHEN 'BACK'. CLEAR o_tree. LEAVE TO SCREEN 0. ENDCASE. CLEAR v_ok_code. ENDMODULE. "process_events_0100 INPUT