Posted: Wed Mar 04, 2009 5:05 pm Post subject: Column Tree and Docking Template
Version 2.0
Author WATTO
Source from: http: /www.watto.org/program/abap/download/Z_TREE_DOCK_TEMPLATE.abap
Description: A template program for building a report that has a docked window on the left which contains a tree with columns. Includes the following functionality...
Features:
- Create a docking window
- Create a tree with columns
- Adding tree nodes with images
- Adding tree columns as text or checkboxes
- Handling of double-clicks and checkbox clicks of the tree
*----------------------------------------------------------------------
* 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_column_tree
IMPORTING node_key,
handle_checkbox_change
FOR EVENT checkbox_change
OF cl_gui_column_tree
IMPORTING node_key item_name checked.
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
*---------------------------------------------------------------------*
* METHOD HANDLE_CHECKBOX_CHANGE
*---------------------------------------------------------------------*
* [+] Processes a double-click on a node
*---------------------------------------------------------------------*
METHOD handle_checkbox_change.
WRITE: / node_key.
WRITE: / item_name.
WRITE: / checked.
ENDMETHOD. "handle_checkbox_change
ENDCLASS. "cl_tree_events IMPLEMENTATION
************************************************************************
***
*** MAIN PROCESSING
***
************************************************************************
************************************************************************
***
*** DOCKING AND TREE OBJECT METHODS
***
************************************************************************
*----------------------------------------------------------------------
* FORM BUILD_DOCKED_WINDOW
*----------------------------------------------------------------------
* [+] Constructs and loads the data into the docked window...
* [+] Builds the dock
* [+] Builds the tree
* [+] Loads the tree nodes
*----------------------------------------------------------------------
FORM build_docked_window.
* Local variables
DATA: li_events TYPE cntl_simple_events, "events
lv_events TYPE cntl_simple_event, "events
lo_dock TYPE REF TO cl_gui_docking_container, "docked window
lv_repid TYPE syrepid, "report ID
lv_tree_header TYPE treev_hhdr.
* Setting variables
lv_repid = sy-repid.
* Create the dock window object
CREATE OBJECT lo_dock
EXPORTING
repid = lv_repid
dynnr = sy-dynnr
side = lo_dock->dock_at_left
extension = 400.
* header of the tree
lv_tree_header-heading = 'My Tree :)'.
lv_tree_header-width = 30.
* Create the tree object
CREATE OBJECT o_tree
EXPORTING
parent = lo_dock
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
hierarchy_column_name = 'TreeColumn' " the column that contains the node names
hierarchy_header = lv_tree_header.
* Define the columns (excluding the column with the node names 'TreeColumn')
* code size name
PERFORM define_column USING 'Column1' 5 'Check'.
PERFORM define_column USING 'Column2' 15 'My Column 2'.
* Define the events to listen for
lv_events-eventid = cl_gui_column_tree=>eventid_node_double_click.
lv_events-appl_event = 'X'. " process PAI if event occurs
APPEND lv_events TO li_events.
lv_events-eventid = cl_gui_column_tree=>eventid_checkbox_change.
lv_events-appl_event = 'X'.
APPEND lv_events TO li_events.
* Set the event listeners
SET HANDLER o_tree_listener->handle_node_double_click FOR o_tree.
SET HANDLER o_tree_listener->handle_checkbox_change FOR o_tree.
* Build the tree
PERFORM build_tree.
* expand the node with key 'Root'
CALL METHOD o_tree->expand_node
EXPORTING
node_key = 'Root'.
ENDFORM. "build_docked_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!
* node column value
PERFORM add_checkbox_column USING 'Leaf1' 'Column1'.
PERFORM add_checkbox_column USING 'Leaf2' 'Column1'.
PERFORM add_text_column USING 'Leaf2' 'Column2' 'Hello World!'.
PERFORM add_checkbox_column USING 'Leaf3' 'Column1'.
PERFORM add_text_column USING 'Leaf3' 'Column2' 'Guess What?'.
* Adds the nodes to the tree.
CALL METHOD o_tree->add_nodes_and_items
EXPORTING
node_table = i_nodes
item_table = i_items
item_table_structure_name = 'MTREEITM'.
ENDFORM. "build_tree
*----------------------------------------------------------------------
* FORM DEFINE_COLUMN
*----------------------------------------------------------------------
* [+] Defines a column
*----------------------------------------------------------------------
FORM define_column
USING
p_code TYPE c
p_size TYPE i
p_name TYPE c.
*----------------------------------------------------------------------
* FORM ADD_CHECKBOX_COLUMN
*----------------------------------------------------------------------
* [+] Adds a checkbox column to a node
*----------------------------------------------------------------------
FORM add_checkbox_column
USING
p_node_name TYPE c
p_column_name TYPE c.
*----------------------------------------------------------------------
* FORM ADD_TEXT_COLUMN
*----------------------------------------------------------------------
* [+] Adds a text column to a node
*----------------------------------------------------------------------
FORM add_text_column
USING
p_node_name TYPE c
p_column_name TYPE c
p_value TYPE c.
*----------------------------------------------------------------------
* FORM ADD_NODE
*----------------------------------------------------------------------
* [+] Adds a node to the tree
* [+] Adds a single column for the node
*----------------------------------------------------------------------
FORM add_node
USING
p_folder TYPE c
p_code TYPE c
p_parent TYPE c
p_image TYPE c
p_name TYPE c.
* add the column that displays the node name
v_items-node_key = p_code.
v_items-item_name = 'TreeColumn'.
v_items-text = p_name.
v_items-class = cl_gui_column_tree=>item_class_text.
APPEND v_items TO i_items.
*----------------------------------------------------------------------
* MODULE LOAD_DOCK
*----------------------------------------------------------------------
* [+] Loads the docked window and tree
*----------------------------------------------------------------------
MODULE load_dock OUTPUT.
SET PF-STATUS 'MAIN'.
IF o_tree IS INITIAL.
* build the tree/dock
PERFORM build_docked_window.
ENDIF.
ENDMODULE. "load_dock 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.
* Otherwise, the user didn't click the tree, they clicked something
* else (such as a button), so process as normal.
CASE v_ok_code.
WHEN 'BACK'.
CLEAR o_tree.
LEAVE TO SCREEN 0.
ENDCASE.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.