SAP List Tree
效果
源代码
*&---------------------------------------------------------------------* *& Modulpool SAPSIMPLE_TREE_CONTROL_DEMO * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* INCLUDE TLIST_TREE_CONTROL_DEMOTOP. INCLUDE TLIST_TREE_CONTROL_DEMOCL1. INCLUDE TLIST_TREE_CONTROL_DEMOO01. INCLUDE TLIST_TREE_CONTROL_DEMOI01. 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.
*&---------------------------------------------------------------------* *& 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_DEMOTOP
*----------------------------------------------------------------------* * 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. clear g_item_name. 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
*&---------------------------------------------------------------------* *& Report RSDEMO_DRAG_DROP_EDIT_TREE * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* REPORT rsdemo_drag_drop_edit_tree . DATA ok_code TYPE sy-ucomm. DATA node_itab LIKE node_str OCCURS 0. DATA node LIKE node_str. DATA container TYPE REF TO cl_gui_custom_container. DATA splitter TYPE REF TO cl_gui_easy_splitter_container. DATA right TYPE REF TO cl_gui_container. DATA left TYPE REF TO cl_gui_container. DATA editor TYPE REF TO cl_gui_textedit. DATA tree TYPE REF TO cl_gui_simple_tree. DATA behaviour_left TYPE REF TO cl_dragdrop. DATA behaviour_right TYPE REF TO cl_dragdrop. DATA handle_tree TYPE i. *---------------------------------------------------------------------* * CLASS lcl_treeobject DEFINITION *---------------------------------------------------------------------* * Definition of Data Container * *---------------------------------------------------------------------* CLASS lcl_drag_object DEFINITION. PUBLIC SECTION. DATA text TYPE mtreesnode-text. ENDCLASS. *---------------------------------------------------------------------* * CLASS dragdrop_receiver DEFINITION *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* CLASS lcl_dragdrop_receiver DEFINITION. PUBLIC SECTION. METHODS: flavor_select FOR EVENT on_get_flavor OF cl_gui_textedit IMPORTING index line pos flavors dragdrop_object, left_drag FOR EVENT on_drag OF cl_gui_simple_tree IMPORTING node_key drag_drop_object, right_drop FOR EVENT ON_DROP OF cl_gui_textedit IMPORTING index line pos dragdrop_object, drop_complete FOR EVENT on_drop_complete OF cl_gui_simple_tree IMPORTING node_key drag_drop_object. ENDCLASS. ************************************************************************ ************************************************************************ START-OF-SELECTION. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Module START OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE start OUTPUT. SET PF-STATUS 'BASE'. IF container is initial. CREATE OBJECT container EXPORTING container_name = 'CONTAINER'. CREATE OBJECT splitter EXPORTING parent = container orientation = 1. left = splitter->top_left_container. right = splitter->bottom_right_container. CREATE OBJECT editor EXPORTING parent = right. CREATE OBJECT tree EXPORTING parent = left node_selection_mode = tree->node_sel_mode_single. * Definition of drag drop behaviour CREATE OBJECT behaviour_left. CALL METHOD behaviour_left->add EXPORTING flavor = 'Tree_move_to_Edit' dragsrc = 'X' droptarget = ' ' effect = cl_dragdrop=>copy. CALL METHOD behaviour_left->add EXPORTING flavor = 'Tree_copy_to_Edit' dragsrc = 'X' droptarget = ' ' effect = cl_dragdrop=>copy. CALL METHOD behaviour_left->get_handle IMPORTING handle = handle_tree. * Drag Drop behaviour of tree control nodes are defined in the node * structure PERFORM fill_tree. CALL METHOD tree->add_nodes EXPORTING node_table = node_itab table_structure_name = 'NODE_STR'. CREATE OBJECT behaviour_right. CALL METHOD behaviour_right->add EXPORTING flavor = 'Tree_move_to_Edit' dragsrc = ' ' droptarget = 'X' effect = cl_dragdrop=>copy. CALL METHOD behaviour_right->add EXPORTING flavor = 'Tree_copy_to_Edit' dragsrc = ' ' droptarget = 'X' effect = cl_dragdrop=>copy. CALL METHOD editor->set_dragdrop EXPORTING dragdrop = behaviour_right. * registration of drag and drop events DATA dragdrop TYPE REF TO lcl_dragdrop_receiver. CREATE OBJECT dragdrop. SET HANDLER dragdrop->flavor_select FOR editor. SET HANDLER dragdrop->left_drag FOR tree. SET HANDLER dragdrop->right_drop FOR editor. set handler dragdrop->drop_complete for tree. CALL METHOD tree->expand_node EXPORTING node_key = 'Root'. ENDIF. ENDMODULE. " START OUTPUT *&---------------------------------------------------------------------* *& Module EXIT INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE exit INPUT. LEAVE PROGRAM. ENDMODULE. " EXIT INPUT *&---------------------------------------------------------------------* *& Form fill_tree *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM fill_tree. DATA: node LIKE mtreesnode. * node table of the left tree CLEAR node. node-node_key = 'Root'. node-isfolder = 'X'. node-text = 'Texte'. node-dragdropid = ' '. APPEND node TO node_itab. CLEAR node. node-node_key = 'Child1'. node-relatkey = 'Root'. node-relatship = cl_gui_simple_tree=>relat_last_child. node-text = 'DragDrop Text 1'. node-dragdropid = handle_tree. " handle of behaviour APPEND node TO node_itab. CLEAR node. node-node_key = 'Child2'. node-relatkey = 'Root'. node-relatship = cl_gui_simple_tree=>relat_last_child. node-text = 'DragDrop Text 2'. node-dragdropid = handle_tree. " handle of behaviour APPEND node TO node_itab. ENDFORM. " fill_tree *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CALL METHOD cl_gui_cfw=>dispatch. ENDMODULE. " USER_COMMAND_0100 INPUT *---------------------------------------------------------------------* * CLASS DRAGDROP_RECEIVER IMPLEMENTATION *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* CLASS lcl_dragdrop_receiver IMPLEMENTATION. METHOD flavor_select. IF line > 5. SEARCH flavors FOR 'Tree_move_to_Edit'. IF sy-subrc = 0. CALL METHOD dragDROP_OBJECT->SET_FLAVOR EXPORTING newflavor = 'Tree_move_to_Edit'. ELSE. CALL METHOD dragdrop_object->abort. ENDIF. ELSE. SEARCH flavors FOR 'Tree_copy_to_Edit'. IF sy-subrc = 0. CALL METHOD dragdrop_object->set_flavor EXPORTING newflavor = 'Tree_copy_to_Edit'. ELSE. CALL METHOD dragdrop_object->abort. ENDIF. ENDIF. ENDMETHOD. METHOD left_drag. DATA drag_object TYPE REF TO lcl_drag_object. READ TABLE node_itab WITH KEY node_key = node_key INTO node. CREATE OBJECT drag_object. drag_object->text = node-text. drag_drop_object->object = drag_object. ENDMETHOD. METHOD right_drop. DATA textline(256). DATA text_table LIKE STANDARD TABLE OF textline. DATA drag_object TYPE REF TO lcl_drag_object. CATCH SYSTEM-EXCEPTIONS move_cast_error = 1. drag_object ?= dragdrop_object->object. ENDCATCH. IF sy-subrc = 1. " data object has unexpected class " => cancel Drag & Drop operation CALL METHOD dragdrop_object->abort. EXIT. ENDIF. CALL METHOD editor->get_text_as_stream IMPORTING text = text_table. * Synchronize Automation Queue after Get Methods CALL METHOD cl_gui_cfw=>flush. textline = drag_object->text. * Insert text in internal table INSERT textline INTO text_table INDEX 1. * Send modified table to frontend CALL METHOD editor->set_text_as_stream EXPORTING text = text_table EXCEPTIONS error_dp = 1 error_dp_create = 2. ENDMETHOD. METHOD drop_complete. IF drag_drop_object->flavor = 'Tree_move_to_Edit'. CALL METHOD tree->delete_node EXPORTING node_key = node_key. delete node_itab where node_key = node_key. ENDIF. ENDMETHOD. ENDCLASS.
Column Tree
效果
源代码
INCLUDE COLUMN_TREE_CONTROL_DEMOTOP. *INCLUDE COLUMN_TREE_CONTROL_DEMOTOP. INCLUDE COLUMN_TREE_CONTROL_DEMOCL1. *INCLUDE COLUMN_TREE_CONTROL_DEMOCL1. INCLUDE COLUMN_TREE_CONTROL_DEMOO01. *INCLUDE COLUMN_TREE_CONTROL_DEMOO01. INCLUDE COLUMN_TREE_CONTROL_DEMOI01. *INCLUDE COLUMN_TREE_CONTROL_DEMOI01. INCLUDE COLUMN_TREE_CONTROL_DEMOF01. *INCLUDE COLUMN_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.
*&---------------------------------------------------------------------* *& Include COLUMN_TREE_CONTROL_DEMOTOP * *& * *&---------------------------------------------------------------------* REPORT SAPCOLUMN_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_COLUMN_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, G_HEADER_NAME TYPE TV_HDRNAME. 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, BEGIN OF c_column, column1 TYPE tv_itmname VALUE 'Column1', "#EC NOTEXT column2 TYPE tv_itmname VALUE 'Column2', "#EC NOTEXT column3 TYPE tv_itmname VALUE 'Column3', "#EC NOTEXT END OF c_column. *** INCLUDE COLUMN_TREE_CONTROL_DEMOTOP
*----------------------------------------------------------------------* * INCLUDE COLUMN_TREE_CONTROL_DEMOCL1 * *----------------------------------------------------------------------* CLASS LCL_APPLICATION DEFINITION. PUBLIC SECTION. METHODS: HANDLE_NODE_DOUBLE_CLICK FOR EVENT NODE_DOUBLE_CLICK OF CL_GUI_COLUMN_TREE IMPORTING NODE_KEY, HANDLE_HEADER_CLICK FOR EVENT HEADER_CLICK OF CL_GUI_COLUMN_TREE IMPORTING HEADER_NAME, HANDLE_EXPAND_NO_CHILDREN FOR EVENT EXPAND_NO_CHILDREN OF CL_GUI_COLUMN_TREE IMPORTING NODE_KEY, HANDLE_ITEM_DOUBLE_CLICK FOR EVENT ITEM_DOUBLE_CLICK OF CL_GUI_COLUMN_TREE IMPORTING NODE_KEY ITEM_NAME, HANDLE_BUTTON_CLICK FOR EVENT BUTTON_CLICK OF CL_GUI_COLUMN_TREE IMPORTING NODE_KEY ITEM_NAME, HANDLE_LINK_CLICK FOR EVENT LINK_CLICK OF CL_GUI_COLUMN_TREE IMPORTING NODE_KEY ITEM_NAME, HANDLE_CHECKBOX_CHANGE FOR EVENT CHECKBOX_CHANGE OF CL_GUI_COLUMN_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. CLEAR: G_ITEM_NAME, G_HEADER_NAME. ENDMETHOD. "HANDLE_NODE_DOUBLE_CLICK METHOD HANDLE_HEADER_CLICK. " this method handles header click event of the tree " control instance " show the name of the clicked header in a dynpro field G_EVENT = 'HEADER_CLICK'. G_HEADER_NAME = HEADER_NAME. CLEAR: G_NODE_KEY, G_ITEM_NAME. ENDMETHOD. "HANDLE_HEADER_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. CLEAR G_HEADER_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. CLEAR G_HEADER_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. CLEAR G_HEADER_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. CLEAR G_HEADER_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. CLEAR: G_ITEM_NAME, G_HEADER_NAME. IF node_key = c_nodekey-child1. * add two nodes * Node with key 'New1' CLEAR NODE. node-node_key = c_nodekey-New1. node-relatkey = c_nodekey-child1. NODE-RELATSHIP = CL_GUI_COLUMN_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_COLUMN_TREE=>RELAT_LAST_CHILD. NODE-N_IMAGE = '@10@'. APPEND NODE TO NODE_TABLE. * Items of node with key 'New1' CLEAR ITEM. item-node_key = c_nodekey-New1. item-item_name = c_column-Column1. item-class = cl_gui_column_tree=>item_class_text. item-text = 'New1 Col. 1'(n11). APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-New1. item-item_name = c_column-Column2. ITEM-CLASS = CL_GUI_COLUMN_TREE=>ITEM_CLASS_LINK. item-t_image = '@3C@'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-New1. item-item_name = c_column-Column3. item-class = cl_gui_column_tree=>item_class_text. item-text = 'New1 Col. 3'(n13). APPEND ITEM TO ITEM_TABLE. * Items of node with key 'New2' CLEAR ITEM. item-node_key = c_nodekey-New2. item-item_name = c_column-Column1. item-class = cl_gui_column_tree=>item_class_text. item-text = 'New2 Col. 1'(n21). APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-New2. item-item_name = c_column-Column2. item-class = cl_gui_column_tree=>item_class_text. item-text = 'New2 Col. 2'(n22). APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-New2. item-item_name = c_column-Column3. item-class = cl_gui_column_tree=>item_class_text. item-text = 'New2 Col. 3'(n23). APPEND ITEM TO 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. endif. ENDMETHOD. "HANDLE_EXPAND_NO_CHILDREN ENDCLASS. "LCL_APPLICATION IMPLEMENTATION
*------------------------------------------------------------------- ***INCLUDE column_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 column_tree_control_demoO01
*------------------------------------------------------------------- ***INCLUDE column_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 column_tree_control_demoI01
*------------------------------------------------------------------- ***INCLUDE column_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, event type cntl_simple_event, EVENTS TYPE CNTL_SIMPLE_EVENTS, HIERARCHY_HEADER TYPE TREEV_HHDR. * 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. * setup the hierarchy header hierarchy_header-heading = 'Hierarchy Header'(roo). " heading HIERARCHY_HEADER-WIDTH = 30. " 30 characters * create a tree control * After construction, the control contains one column in the * hierarchy area. The name of this column * is defined via the constructor parameter HIERACHY_COLUMN_NAME. CREATE OBJECT G_TREE EXPORTING PARENT = G_CUSTOM_CONTAINER NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE ITEM_SELECTION = 'X' hierarchy_column_name = c_column-Column1 HIERARCHY_HEADER = HIERARCHY_HEADER EXCEPTIONS CNTL_SYSTEM_ERROR = 1 CREATE_ERROR = 2 FAILED = 3 ILLEGAL_NODE_SELECTION_MODE = 4 ILLEGAL_COLUMN_NAME = 5 LIFETIME_ERROR = 6. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. * define the events which will be passed to the backend " node double click event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_NODE_DOUBLE_CLICK. event-appl_event = 'X'. " process PAI if event occurs append event to events. " item double click event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_ITEM_DOUBLE_CLICK. event-appl_event = 'X'. append event to events. " expand no children event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_EXPAND_NO_CHILDREN. event-appl_event = 'X'. append event to events. " link click event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_LINK_CLICK. event-appl_event = 'X'. append event to events. " button click event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_button_click. event-appl_event = 'X'. append event to events. " checkbox change event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_checkbox_change. event-appl_event = 'X'. append event to events. " header click event-eventid = CL_GUI_COLUMN_TREE=>EVENTID_header_click. 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. SET HANDLER G_APPLICATION->HANDLE_HEADER_CLICK FOR G_TREE. * insert two additional columns * Column2 CALL METHOD G_TREE->ADD_COLUMN EXPORTING name = c_column-Column2 width = 21 header_text = 'Column2'(co2) EXCEPTIONS COLUMN_EXISTS = 1 ILLEGAL_COLUMN_NAME = 2 TOO_MANY_COLUMNS = 3 ILLEGAL_ALIGNMENT = 4 DIFFERENT_COLUMN_TYPES = 5 CNTL_SYSTEM_ERROR = 6 FAILED = 7 PREDECESSOR_COLUMN_NOT_FOUND = 8. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. * Column3 CALL METHOD G_TREE->ADD_COLUMN EXPORTING name = c_column-Column3 width = 21 alignment = cl_gui_column_tree=>align_right header_text = 'Column3'(co3) EXCEPTIONS COLUMN_EXISTS = 1 ILLEGAL_COLUMN_NAME = 2 TOO_MANY_COLUMNS = 3 ILLEGAL_ALIGNMENT = 4 DIFFERENT_COLUMN_TYPES = 5 CNTL_SYSTEM_ERROR = 6 FAILED = 7 PREDECESSOR_COLUMN_NOT_FOUND = 8. IF SY-SUBRC <> 0. MESSAGE A000. ENDIF. * 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. * expand the node with key 'Root' CALL METHOD G_TREE->EXPAND_NODE EXPORTING node_key = c_nodekey-Root EXCEPTIONS FAILED = 1 ILLEGAL_LEVEL_COUNT = 2 CNTL_SYSTEM_ERROR = 3 NODE_NOT_FOUND = 4 CANNOT_EXPAND_LEAF = 5. 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. APPEND NODE TO NODE_TABLE. * Node with key 'Child1' 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_COLUMN_TREE=>RELAT_LAST_CHILD. NODE-HIDDEN = ' '. NODE-DISABLED = ' '. NODE-ISFOLDER = 'X'. CLEAR NODE-N_IMAGE. CLEAR NODE-EXP_IMAGE. 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 = c_column-Column1. " Item of Column 'Column1' item-class = cl_gui_column_tree=>item_class_text. " Text Item item-text = 'Root Col. 1'(ro1). APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-Root. item-item_name = c_column-Column2. " Item of Column 'Column2' item-class = cl_gui_column_tree=>item_class_text. item-text = 'Root Col. 2'(ro2). APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-Root. item-item_name = c_column-Column3. " Item of Column 'Column3' " Item is a link (click on link fires event LINK_CLICK) item-class = cl_gui_column_tree=>item_class_link. item-text = 'Root Col. 3'(ro3). APPEND ITEM TO ITEM_TABLE. * Node with key 'Child1' CLEAR ITEM. item-node_key = c_nodekey-Child1. item-item_name = c_column-Column1. item-class = cl_gui_column_tree=>item_class_text. item-text = 'Child1 Col. 1'(c11). APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-Child1. item-item_name = c_column-Column2. " item-class = cl_gui_column_tree=>item_class_button. " Item is a button item-text = 'Child1 Col. 2'(c12). ITEM-T_IMAGE = '@0B@'. APPEND ITEM TO ITEM_TABLE. CLEAR ITEM. item-node_key = c_nodekey-Child1. item-item_name = c_column-Column3. " Item is a checkbox ITEM-CLASS = CL_GUI_COLUMN_TREE=>ITEM_CLASS_CHECKBOX. ITEM-EDITABLE = 'X'. item-text = 'Child1 Col. 3'(c13). ITEM-T_IMAGE = '@0C@'. APPEND ITEM TO ITEM_TABLE. ENDFORM. " build_node_and_item_table *** INCLUDE column_tree_control_demoF01
可拖拽的树形结构
效果
源代码
*&---------------------------------------------------------------------* *& Report RSDEMO_DRAG_DROP_EDIT_TREE * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* REPORT rsdemo_drag_drop_edit_tree . DATA ok_code TYPE sy-ucomm. DATA node_itab_left LIKE node_str OCCURS 0. DATA node_itab_right LIKE node_str OCCURS 0. DATA node LIKE node_str. DATA container TYPE REF TO cl_gui_custom_container. DATA splitter TYPE REF TO cl_gui_easy_splitter_container. DATA right TYPE REF TO cl_gui_container. DATA left TYPE REF TO cl_gui_container. DATA tree_right TYPE REF TO cl_gui_simple_tree. DATA tree_left TYPE REF TO cl_gui_simple_tree. DATA behaviour_left TYPE REF TO cl_dragdrop. DATA behaviour_right TYPE REF TO cl_dragdrop. DATA handle_tree_left TYPE i. DATA handle_tree_right TYPE i. *---------------------------------------------------------------------* * CLASS lcl_treeobject DEFINITION *---------------------------------------------------------------------* * Definition of Data Container * *---------------------------------------------------------------------* CLASS lcl_drag_object DEFINITION. PUBLIC SECTION. DATA text TYPE STANDARD TABLE OF mtreesnode-text. ENDCLASS. *---------------------------------------------------------------------* * CLASS dragdrop_receiver DEFINITION *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* CLASS lcl_dragdrop_receiver DEFINITION. PUBLIC SECTION. METHODS: flavor_select FOR EVENT on_drop_get_flavor OF cl_gui_simple_tree IMPORTING node_key flavors drag_drop_object, left_drag FOR EVENT on_drag_multiple OF cl_gui_simple_tree IMPORTING node_key_table drag_drop_object, right_drop FOR EVENT on_drop OF cl_gui_simple_tree IMPORTING node_key drag_drop_object, drop_complete FOR EVENT on_drop_complete_multiple OF cl_gui_simple_tree IMPORTING node_key_table drag_drop_object. ENDCLASS. ************************************************************************ ************************************************************************ START-OF-SELECTION. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Module START OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE start OUTPUT. SET PF-STATUS 'BASE'. IF container is initial. CREATE OBJECT container EXPORTING container_name = 'CONTAINER'. CREATE OBJECT splitter EXPORTING parent = container orientation = 1. left = splitter->top_left_container. right = splitter->bottom_right_container. CREATE OBJECT tree_right EXPORTING parent = right node_selection_mode = tree_right->node_sel_mode_multiple. CREATE OBJECT tree_left EXPORTING parent = left node_selection_mode = tree_left->node_sel_mode_multiple. * Definition of drag drop behaviour CREATE OBJECT behaviour_left. CALL METHOD behaviour_left->add EXPORTING ##NO_TEXT flavor = 'Tree_move' dragsrc = 'X' droptarget = ' ' effect = cl_dragdrop=>copy. CALL METHOD behaviour_left->add EXPORTING ##NO_TEXT flavor = 'Tree_copy' dragsrc = 'X' droptarget = ' ' effect = cl_dragdrop=>copy. CALL METHOD behaviour_left->get_handle IMPORTING handle = handle_tree_left. * Drag Drop behaviour of tree control nodes are defined in the node * structure PERFORM fill_tree CHANGING handle_tree_left node_itab_left. CALL METHOD tree_left->add_nodes EXPORTING node_table = node_itab_left table_structure_name = 'NODE_STR'. CREATE OBJECT behaviour_right. CALL METHOD behaviour_right->add EXPORTING ##NO_TEXT flavor = 'Tree_copy' dragsrc = ' ' droptarget = 'X' effect = cl_dragdrop=>copy. CALL METHOD behaviour_right->add EXPORTING ##NO_TEXT flavor = 'Tree_move' dragsrc = ' ' droptarget = 'X' effect = cl_dragdrop=>copy. CALL METHOD behaviour_right->get_handle IMPORTING handle = handle_tree_right. PERFORM fill_tree CHANGING handle_tree_right node_itab_right. CALL METHOD tree_right->add_nodes EXPORTING node_table = node_itab_right table_structure_name = 'NODE_STR'. * registration of drag and drop events DATA dragdrop TYPE REF TO lcl_dragdrop_receiver. CREATE OBJECT dragdrop. SET HANDLER dragdrop->flavor_select FOR tree_right. SET HANDLER dragdrop->left_drag FOR tree_left. SET HANDLER dragdrop->right_drop FOR tree_right. SET HANDLER dragdrop->drop_complete FOR tree_left. CALL METHOD tree_left->expand_node ##NO_TEXT EXPORTING node_key = 'Root'. CALL METHOD tree_right->expand_node ##NO_TEXT EXPORTING node_key = 'Root'. ENDIF. ENDMODULE. " START OUTPUT *&---------------------------------------------------------------------* *& Module EXIT INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE exit INPUT. LEAVE PROGRAM. ENDMODULE. " EXIT INPUT *&---------------------------------------------------------------------* *& Form fill_tree *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM fill_tree CHANGING handle_tree TYPE i node_itab LIKE node_itab_left. DATA: node LIKE mtreesnode. * node table of the left tree CLEAR node. ##NO_TEXT node-node_key = 'Root'. node-isfolder = 'X'. ##NO_TEXT node-text = 'Texte'. node-dragdropid = ' '. APPEND node TO node_itab. CLEAR node. ##NO_TEXT node-node_key = 'Child1'. ##NO_TEXT node-relatkey = 'Root'. node-isfolder = 'X'. node-relatship = cl_gui_simple_tree=>relat_last_child. ##NO_TEXT node-text = 'DragDrop Text 1'. node-dragdropid = handle_tree. " handle of behaviour APPEND node TO node_itab. CLEAR node. ##NO_TEXT node-node_key = 'Child2'. ##NO_TEXT node-relatkey = 'Root'. node-isfolder = 'X'. node-relatship = cl_gui_simple_tree=>relat_last_child. ##NO_TEXT node-text = 'DragDrop Text 2'. node-dragdropid = handle_tree. " handle of behaviour APPEND node TO node_itab. ENDFORM. " fill_tree *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CALL METHOD cl_gui_cfw=>dispatch. ENDMODULE. " USER_COMMAND_0100 INPUT *---------------------------------------------------------------------* * CLASS DRAGDROP_RECEIVER IMPLEMENTATION *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* CLASS lcl_dragdrop_receiver IMPLEMENTATION. METHOD flavor_select. ##NO_TEXT IF node_key <> 'Root'. ##NO_TEXT SEARCH flavors FOR 'Tree_move'. IF sy-subrc = 0. CALL METHOD drag_drop_object->set_flavor ##NO_TEXT EXPORTING newflavor = 'Tree_move'. ELSE. CALL METHOD drag_drop_object->abort. ENDIF. ELSE. ##NO_TEXT SEARCH flavors FOR 'Tree_copy'. IF sy-subrc = 0. CALL METHOD drag_drop_object->set_flavor ##NO_TEXT EXPORTING newflavor = 'Tree_copy'. ELSE. CALL METHOD drag_drop_object->abort. ENDIF. ENDIF. ENDMETHOD. METHOD left_drag. DATA drag_object TYPE REF TO lcl_drag_object. DATA node_key TYPE node_str-node_key. CREATE OBJECT drag_object. LOOP AT node_key_table INTO node_key. READ TABLE node_itab_left WITH KEY node_key = node_key INTO node. APPEND node-text TO drag_object->text. ENDLOOP. drag_drop_object->object = drag_object. ENDMETHOD. METHOD right_drop. DATA drag_object TYPE REF TO lcl_drag_object. data new_nodes like node_itab_right. data new_node type node_str. CATCH SYSTEM-EXCEPTIONS move_cast_error = 1. drag_object ?= drag_drop_object->object. ENDCATCH. IF sy-subrc = 1. " data object has unexpected class " => cancel Drag & Drop operation CALL METHOD drag_drop_object->abort. EXIT. ENDIF. loop at drag_object->text into new_node-text. perform add_node changing node_key new_node new_nodes node_itab_left. endloop. call method tree_right->add_nodes exporting node_table = new_nodes table_structure_name = 'NODE_STR'. ENDMETHOD. METHOD drop_complete. DATA node_key TYPE node_str-node_key. IF drag_drop_object->flavor = 'Tree_move_to_Edit'. LOOP AT node_key_table INTO node_key. CALL METHOD tree_left->delete_node EXPORTING node_key = node_key. DELETE node_itab_left WHERE node_key = node_key. ENDLOOP. ENDIF. ENDMETHOD. ENDCLASS. *&---------------------------------------------------------------------* *& Form ADD_NODE *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_NEW_NODE text * <--P_NEW_NODES text * <--P_NODE_ITAB_LEFT text *----------------------------------------------------------------------* FORM ADD_NODE CHANGING node_key NEW_NODE type node_str NEW_NODES like node_itab_left NODE_ITAB_LEFT like node_itab_left. data lines type i. describe table node_itab_left lines lines. new_node-node_key = lines. new_node-isfolder = 'X'. new_node-dragdropid = handle_tree_right. new_node-relatkey = node_key. APPEND new_node TO new_nodes. append new_node to node_itab_left. ENDFORM. " ADD_NODE
效果
*&---------------------------------------------------------------------* *& Report RSDEMO_DRAG_DROP_EDIT_TREE * *& * *&---------------------------------------------------------------------* *& * *& * *&---------------------------------------------------------------------* REPORT rsdemo_drag_drop_edit_tree . DATA ok_code TYPE sy-ucomm. DATA node_itab LIKE node_str OCCURS 0. DATA node LIKE node_str. DATA container TYPE REF TO cl_gui_custom_container. DATA splitter TYPE REF TO cl_gui_easy_splitter_container. DATA right TYPE REF TO cl_gui_container. DATA left TYPE REF TO cl_gui_container. DATA editor TYPE REF TO cl_gui_textedit. DATA tree TYPE REF TO cl_gui_simple_tree. DATA behaviour_left TYPE REF TO cl_dragdrop. DATA behaviour_right TYPE REF TO cl_dragdrop. DATA handle_tree TYPE i. *---------------------------------------------------------------------* * CLASS lcl_treeobject DEFINITION *---------------------------------------------------------------------* * Definition of Data Container * *---------------------------------------------------------------------* ##CLASS_FINAL CLASS lcl_drag_object DEFINITION. PUBLIC SECTION. DATA text TYPE mtreesnode-text. ENDCLASS. *---------------------------------------------------------------------* * CLASS dragdrop_receiver DEFINITION *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* ##CLASS_FINAL CLASS lcl_dragdrop_receiver DEFINITION. PUBLIC SECTION. METHODS: flavor_select FOR EVENT on_get_flavor OF cl_gui_textedit ##NEEDED IMPORTING index line pos flavors dragdrop_object, left_drag FOR EVENT on_drag OF cl_gui_simple_tree ##NEEDED IMPORTING node_key drag_drop_object, right_drop FOR EVENT ON_DROP OF cl_gui_textedit ##NEEDED IMPORTING index line pos dragdrop_object, drop_complete FOR EVENT on_drop_complete OF cl_gui_simple_tree IMPORTING node_key drag_drop_object. ENDCLASS. ************************************************************************ ************************************************************************ START-OF-SELECTION. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Module START OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE start OUTPUT. SET PF-STATUS 'BASE'. IF container is initial. CREATE OBJECT container EXPORTING container_name = 'CONTAINER'. CREATE OBJECT splitter EXPORTING parent = container orientation = 1. left = splitter->top_left_container. right = splitter->bottom_right_container. CREATE OBJECT editor EXPORTING parent = right. CREATE OBJECT tree EXPORTING parent = left node_selection_mode = tree->node_sel_mode_single. * Definition of drag drop behaviour CREATE OBJECT behaviour_left. CALL METHOD behaviour_left->add EXPORTING flavor = 'Tree_move_to_Edit' dragsrc = 'X' droptarget = ' ' effect = cl_dragdrop=>copy. CALL METHOD behaviour_left->add EXPORTING flavor = 'Tree_copy_to_Edit' dragsrc = 'X' droptarget = ' ' effect = cl_dragdrop=>copy. CALL METHOD behaviour_left->get_handle IMPORTING handle = handle_tree. * Drag Drop behaviour of tree control nodes are defined in the node * structure PERFORM fill_tree. CALL METHOD tree->add_nodes EXPORTING node_table = node_itab table_structure_name = 'NODE_STR'. CREATE OBJECT behaviour_right. CALL METHOD behaviour_right->add EXPORTING flavor = 'Tree_move_to_Edit' dragsrc = ' ' droptarget = 'X' effect = cl_dragdrop=>copy. CALL METHOD behaviour_right->add EXPORTING flavor = 'Tree_copy_to_Edit' dragsrc = ' ' droptarget = 'X' effect = cl_dragdrop=>copy. CALL METHOD editor->set_dragdrop EXPORTING dragdrop = behaviour_right. * registration of drag and drop events ##DECL_MODUL DATA dragdrop TYPE REF TO lcl_dragdrop_receiver. CREATE OBJECT dragdrop. SET HANDLER dragdrop->flavor_select FOR editor. SET HANDLER dragdrop->left_drag FOR tree. SET HANDLER dragdrop->right_drop FOR editor. set handler dragdrop->drop_complete for tree. CALL METHOD tree->expand_node ##NO_TEXT EXPORTING node_key = 'Root'. ENDIF. ENDMODULE. " START OUTPUT *&---------------------------------------------------------------------* *& Module EXIT INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE exit INPUT. LEAVE PROGRAM. ENDMODULE. " EXIT INPUT *&---------------------------------------------------------------------* *& Form fill_tree *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM fill_tree. DATA: node LIKE mtreesnode. * node table of the left tree CLEAR node. ##NO_TEXT node-node_key = 'Root'. node-isfolder = 'X'. ##NO_TEXT node-text = 'Texte'. node-dragdropid = ' '. APPEND node TO node_itab. CLEAR node. ##NO_TEXT node-node_key = 'Child1'. ##NO_TEXT node-relatkey = 'Root'. node-relatship = cl_gui_simple_tree=>relat_last_child. ##NO_TEXT node-text = 'DragDrop Text 1'. node-dragdropid = handle_tree. " handle of behaviour APPEND node TO node_itab. CLEAR node. ##NO_TEXT node-node_key = 'Child2'. ##NO_TEXT node-relatkey = 'Root'. node-relatship = cl_gui_simple_tree=>relat_last_child. ##NO_TEXT node-text = 'DragDrop Text 2'. node-dragdropid = handle_tree. " handle of behaviour APPEND node TO node_itab. ENDFORM. " fill_tree *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. CALL METHOD cl_gui_cfw=>dispatch. ENDMODULE. " USER_COMMAND_0100 INPUT *---------------------------------------------------------------------* * CLASS DRAGDROP_RECEIVER IMPLEMENTATION *---------------------------------------------------------------------* * ........ * *---------------------------------------------------------------------* CLASS lcl_dragdrop_receiver IMPLEMENTATION. METHOD flavor_select. IF line > 5. SEARCH flavors FOR 'Tree_move_to_Edit'. IF sy-subrc = 0. CALL METHOD dragDROP_OBJECT->SET_FLAVOR EXPORTING newflavor = 'Tree_move_to_Edit'. ELSE. CALL METHOD dragdrop_object->abort. ENDIF. ELSE. SEARCH flavors FOR 'Tree_copy_to_Edit'. IF sy-subrc = 0. CALL METHOD dragdrop_object->set_flavor EXPORTING newflavor = 'Tree_copy_to_Edit'. ELSE. CALL METHOD dragdrop_object->abort. ENDIF. ENDIF. ENDMETHOD. METHOD left_drag. DATA drag_object TYPE REF TO lcl_drag_object. READ TABLE node_itab WITH KEY node_key = node_key INTO node. CREATE OBJECT drag_object. drag_object->text = node-text. drag_drop_object->object = drag_object. ENDMETHOD. METHOD right_drop. DATA textline(256). DATA text_table LIKE STANDARD TABLE OF textline. DATA drag_object TYPE REF TO lcl_drag_object. CATCH SYSTEM-EXCEPTIONS move_cast_error = 1. drag_object ?= dragdrop_object->object. ENDCATCH. IF sy-subrc = 1. " data object has unexpected class " => cancel Drag & Drop operation CALL METHOD dragdrop_object->abort. EXIT. ENDIF. CALL METHOD editor->get_text_as_stream IMPORTING text = text_table. * Synchronize Automation Queue after Get Methods CALL METHOD cl_gui_cfw=>flush. textline = drag_object->text. * Insert text in internal table INSERT textline INTO text_table INDEX 1. * Send modified table to frontend CALL METHOD editor->set_text_as_stream EXPORTING text = text_table EXCEPTIONS error_dp = 1 error_dp_create = 2. ENDMETHOD. METHOD drop_complete. IF drag_drop_object->flavor = 'Tree_move_to_Edit'. CALL METHOD tree->delete_node EXPORTING node_key = node_key. delete node_itab where node_key = node_key. ENDIF. ENDMETHOD. ENDCLASS.