Ниже представлены различные варианты реализации древовидного представления данных.
Заметка построена по следующему принципу: перед каждым примером показан скриншот результата, далее ABAP-код отчета, затем скриншот повторяется. Примеры взяты с сайта codezentrale.de. Оригинальный код и комментарии, на момент копирования, сохранены.
Пример использования CL_COLUMN_TREE_MODEL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
* Demoprogramm: SAPCOLUMN_TREE_CONTROL_DEMO * http://saphelp.ucc.ovgu.de/NW750/EN/4d/88f020981740abe10000000a15822b/frameset.htm * Eventhandler-Klasse CLASS lcl_events DEFINITION. PUBLIC SECTION. TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY. CLASS-METHODS: on_button_click FOR EVENT button_click OF cl_column_tree_model IMPORTING node_key item_name sender. CLASS-METHODS: on_link_click FOR EVENT link_click OF cl_column_tree_model IMPORTING node_key item_name sender. CLASS-METHODS: on_checkbox_change FOR EVENT checkbox_change OF cl_column_tree_model IMPORTING node_key item_name checked sender. CLASS-METHODS: on_header_click FOR EVENT header_click OF cl_column_tree_model IMPORTING header_name sender. ENDCLASS. CLASS lcl_events IMPLEMENTATION. METHOD on_button_click. MESSAGE node_key && '_' && item_name TYPE 'S'. ENDMETHOD. METHOD on_link_click. MESSAGE node_key && '_' && item_name TYPE 'S'. ENDMETHOD. METHOD on_checkbox_change. MESSAGE node_key && '_' && item_name && '_' && checked TYPE 'S'. ENDMETHOD. METHOD on_header_click. MESSAGE header_name TYPE 'S'. ENDMETHOD. ENDCLASS. START-OF-SELECTION. * Tree-Control erzeugen * item_selection = abap_true wegen der CheckBoxen DATA(o_tree) = NEW cl_column_tree_model( node_selection_mode = cl_column_tree_model=>node_sel_mode_single hierarchy_column_name = 'FOLDER' hierarchy_header = VALUE #( t_image = icon_folder heading = 'Beispiel' tooltip = 'Tooltip' width = 30 ) item_selection = abap_true ). * Spalten hinzufügen o_tree->add_column( EXPORTING name = 'COL1' width = 30 header_text = 'Column1' ). o_tree->add_column( EXPORTING name = 'COL2' width = 30 header_text = 'Column2' ). * in default_screen einbetten o_tree->create_tree_control( parent = cl_gui_container=>default_screen ). * Beispielhaft Nodes und Subnodes erzeugen o_tree->add_node( EXPORTING isfolder = abap_true node_key = 'NODE1' relative_node_key = '' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_folder ) image = CONV tv_image( icon_folder ) item_table = VALUE #( ( class = cl_column_tree_model=>item_class_checkbox item_name = 'FOLDER' text = 'Obj1' editable = abap_true ) ) ). o_tree->add_node( EXPORTING isfolder = abap_true node_key = 'NODE1_1' relative_node_key = 'NODE1' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_oo_object ) image = CONV tv_image( icon_oo_object ) item_table = VALUE #( ( class = cl_column_tree_model=>item_class_link item_name = 'FOLDER' text = 'Obj4' ) ( class = cl_column_tree_model=>item_class_text item_name = 'COL1' text = 'Wert1' style = cl_column_tree_model=>style_intensified font = cl_column_tree_model=>item_font_prop ) ( class = cl_column_tree_model=>item_class_text item_name = 'COL2' text = 'Wert2' ) ) ). o_tree->add_node( EXPORTING isfolder = abap_true node_key = 'NODE2' relative_node_key = '' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_folder ) image = CONV tv_image( icon_folder ) item_table = VALUE #( ( class = cl_column_tree_model=>item_class_checkbox item_name = 'FOLDER' text = 'Obj2' editable = abap_true ) ) ). o_tree->add_node( EXPORTING isfolder = abap_true node_key = 'NODE2_1' relative_node_key = 'NODE2' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_oo_object ) image = CONV tv_image( icon_oo_object ) item_table = VALUE #( ( class = cl_column_tree_model=>item_class_button item_name = 'FOLDER' text = 'Obj3' ) ( class = cl_column_tree_model=>item_class_text item_name = 'COL1' text = 'Wert1' style = cl_column_tree_model=>style_inactive font = cl_column_tree_model=>item_font_prop ) ( class = cl_column_tree_model=>item_class_text item_name = 'COL2' text = 'Wert2' ) ) ). * Nodes expandieren o_tree->expand_root_nodes( expand_subtree = abap_true level_count = 10 ). * Events registrieren * ITEM_DOUBLE_CLICK Doppelklick auf Item * BUTTON_CLICK Drucktaste wurde gedrückt * LINK_CLICK Link geklickt * CHECKBOX_CHANGE Zustandsänderung einer Checkbox * ITEM_KEYPRESS Taste wurde gedrückt, Item war selektiert * HEADER_CLICK Header geklickt * ITEM_CONTEXT_MENU_REQUEST Anforderung eines Kontext-Menüs für ein Item * ITEM_CONTEXT_MENU_SELECT Kontext-Menü Eintrag wurde ausgewählt * HEADER_CONTEXT_MENU_REQUEST Anforderung eines Kontext-Menüs für einen Header * HEADER_CONTEXT_MENU_SELECT Kontext-Menü Eintrag wurde ausgewählt * DRAG Ereignis zum Füllen des Drag Drop Daten - Objekts * DRAG_MULTIPLE Ereignis zum Füllen des Drag Drop Daten - Objekts * DROP_COMPLETE Ereignis nach erfolgreichem Drop * DROP_COMPLETE_MULTIPLE Ereignis nach erfolgreichem Drop SET HANDLER lcl_events=>on_button_click FOR o_tree. SET HANDLER lcl_events=>on_checkbox_change FOR o_tree. SET HANDLER lcl_events=>on_header_click FOR o_tree. SET HANDLER lcl_events=>on_link_click FOR o_tree. * Eventtypten müssen gesondert registriert werden DATA(it_events) = VALUE lcl_events=>ty_it_events( ( eventid = cl_column_tree_model=>eventid_button_click appl_event = abap_true ) ( eventid = cl_column_tree_model=>eventid_checkbox_change appl_event = abap_true ) ( eventid = cl_column_tree_model=>eventid_header_click appl_event = abap_true ) ( eventid = cl_column_tree_model=>eventid_link_click appl_event = abap_true ) ). o_tree->set_registered_events( events = it_events ). * Erzeugung von cl_gui_container=>default_screen erzwingen WRITE: space. |
Пример использования CL_LIST_TREE_MODEL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
* Demoprogramm: SAP_LIST_TREE_MODEL_DEMO * http://saphelp.ucc.ovgu.de/NW750/EN/4d/88f020981740abe10000000a15822b/frameset.htm * Eventhandler-Klasse CLASS lcl_events DEFINITION. PUBLIC SECTION. TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY. CLASS-METHODS: on_button_click FOR EVENT button_click OF cl_list_tree_model IMPORTING node_key item_name sender. CLASS-METHODS: on_link_click FOR EVENT link_click OF cl_list_tree_model IMPORTING node_key item_name sender. CLASS-METHODS: on_checkbox_change FOR EVENT checkbox_change OF cl_list_tree_model IMPORTING node_key item_name checked sender. CLASS-METHODS: on_header_click FOR EVENT header_click OF cl_list_tree_model IMPORTING header_name sender. ENDCLASS. CLASS lcl_events IMPLEMENTATION. METHOD on_button_click. MESSAGE node_key && '_' && item_name TYPE 'S'. ENDMETHOD. METHOD on_link_click. MESSAGE node_key && '_' && item_name TYPE 'S'. ENDMETHOD. METHOD on_checkbox_change. MESSAGE node_key && '_' && item_name && '_' && checked TYPE 'S'. ENDMETHOD. METHOD on_header_click. MESSAGE header_name TYPE 'S'. ENDMETHOD. ENDCLASS. START-OF-SELECTION. * Tree-Control erzeugen * item_selection = abap_true wegen der CheckBoxen DATA(o_tree) = NEW cl_list_tree_model( node_selection_mode = cl_list_tree_model=>node_sel_mode_single item_selection = abap_true with_headers = abap_true hierarchy_header = VALUE #( t_image = icon_folder heading = 'Beispiel' tooltip = 'Tooltip' width = 80 ) ). * in default_screen einbetten o_tree->create_tree_control( parent = cl_gui_container=>default_screen ). * Beispielhaft Nodes und Subnodes erzeugen o_tree->add_node( EXPORTING isfolder = abap_true node_key = 'NODE1' relative_node_key = '' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_folder ) image = CONV tv_image( icon_folder ) item_table = VALUE #( ( class = cl_list_tree_model=>item_class_checkbox item_name = '1' text = 'Obj1' editable = abap_true length = 10 ) ) ). o_tree->add_node( EXPORTING isfolder = abap_false node_key = 'NODE1_1' relative_node_key = 'NODE1' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_oo_object ) image = CONV tv_image( icon_oo_object ) item_table = VALUE #( ( class = cl_list_tree_model=>item_class_link item_name = '1' text = 'Obj4' length = 10 ) ( class = cl_list_tree_model=>item_class_text item_name = '2' text = 'Wert1' length = 10 ) ( class = cl_list_tree_model=>item_class_text item_name = '3' text = 'Wert2' length = 10 alignment = cl_list_tree_model=>align_auto font = cl_list_tree_model=>item_font_prop ) ) ). o_tree->add_node( EXPORTING isfolder = abap_true node_key = 'NODE2' relative_node_key = '' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_folder ) image = CONV tv_image( icon_folder ) item_table = VALUE #( ( class = cl_list_tree_model=>item_class_checkbox item_name = '1' text = 'Obj2' editable = abap_true length = 10 ) ) ). o_tree->add_node( EXPORTING isfolder = abap_false node_key = 'NODE2_1' relative_node_key = 'NODE2' relationship = cl_tree_model=>relat_last_child expanded_image = CONV tv_image( icon_oo_object ) image = CONV tv_image( icon_oo_object ) item_table = VALUE #( ( class = cl_list_tree_model=>item_class_button item_name = '1' text = 'Obj3' length = 10 ) ( class = cl_list_tree_model=>item_class_text item_name = '2' text = 'Wert1' length = 10 ) ( class = cl_list_tree_model=>item_class_text item_name = '3' text = 'Wert2' length = 10 alignment = cl_list_tree_model=>align_auto font = cl_list_tree_model=>item_font_prop ) ) ). * Nodes expandieren o_tree->expand_root_nodes( expand_subtree = abap_true level_count = 10 ). * Events registrieren * ITEM_DOUBLE_CLICK Doppelklick auf Item * BUTTON_CLICK Drucktaste wurde gedrückt * LINK_CLICK Link geklickt * CHECKBOX_CHANGE Zustandsänderung einer Checkbox * ITEM_KEYPRESS Taste wurde gedrückt, Item war selektiert * HEADER_CLICK Header geklickt * ITEM_CONTEXT_MENU_REQUEST Anforderung eines Kontext-Menüs für ein Item * ITEM_CONTEXT_MENU_SELECT Kontext-Menü Eintrag wurde ausgewählt * HEADER_CONTEXT_MENU_REQUEST Anforderung eines Kontext-Menüs für einen Header * HEADER_CONTEXT_MENU_SELECT Kontext-Menü Eintrag wurde ausgewählt * DRAG Ereignis zum Füllen des Drag Drop Daten - Objekts * DRAG_MULTIPLE Ereignis zum Füllen des Drag Drop Daten - Objekts * DROP_COMPLETE Ereignis nach erfolgreichem Drop * DROP_COMPLETE_MULTIPLE Ereignis nach erfolgreichem Drop SET HANDLER lcl_events=>on_button_click FOR o_tree. SET HANDLER lcl_events=>on_checkbox_change FOR o_tree. SET HANDLER lcl_events=>on_header_click FOR o_tree. SET HANDLER lcl_events=>on_link_click FOR o_tree. * Eventtypten müssen gesondert registriert werden DATA(it_events) = VALUE lcl_events=>ty_it_events( ( eventid = cl_list_tree_model=>eventid_button_click appl_event = abap_true ) ( eventid = cl_list_tree_model=>eventid_checkbox_change appl_event = abap_true ) ( eventid = cl_list_tree_model=>eventid_header_click appl_event = abap_true ) ( eventid = cl_list_tree_model=>eventid_link_click appl_event = abap_true ) ). o_tree->set_registered_events( events = it_events ). * Erzeugung von cl_gui_container=>default_screen erzwingen WRITE: space. |
Отображение дерева в виде списка и обработка событий
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
* obsolete Darstellung über die FuBas RS_TREE_CONSTRUCT und RS_TREE_LIST_DISPLAY * besser ist die Nutzung der Klassen cl_salv_tree, cl_gui_simple_tree, cl_gui_column_tree, cl_gui_list_tree SELECT kunnr, land1, name1, ort01 INTO TABLE @DATA(it_kna1) FROM kna1 UP TO 25 ROWS. SELECT vbeln, erdat, erzet, netwr, waerk, kunnr INTO TABLE @DATA(it_vbak) FROM vbak FOR ALL ENTRIES IN @it_kna1 WHERE kunnr = @it_kna1-kunnr. SELECT vbeln, posnr, matnr, netwr, waerk INTO TABLE @DATA(it_vbap) FROM vbap FOR ALL ENTRIES IN @it_vbak WHERE vbeln = @it_vbak-vbeln. * Rootnode (Node-Level 1) DATA(it_nodes) = VALUE snodetab( ( tlevel = 1 name = 'Kundenstamm' nlength = 27 color = col_key text = 'Verkaufs-Report' tlength = 50 ) ). LOOP AT it_kna1 ASSIGNING FIELD-SYMBOL(<k>). * Node-Level 2 DATA(lv_node_2) = VALUE snodetext( tlevel = 2 name = <k>-kunnr nlength = 19 color = col_key text = <k>-land1 tlength = 5 tcolor = col_normal text1 = <k>-name1 tlength1 = 40 tcolor1 = col_normal text2 = <k>-ort01 tlength2 = 25 tcolor2 = col_normal ). APPEND lv_node_2 TO it_nodes. LOOP AT it_vbak ASSIGNING FIELD-SYMBOL(<v>) WHERE kunnr = <k>-kunnr. * Node-Level 3 DATA(lv_node_3) = VALUE snodetext( tlevel = 3 name = <v>-vbeln nlength = 15 color = col_positive text = <v>-erdat tlength = 12 tcolor = col_normal text1 = <v>-erzet tlength1 = 10 tcolor1 = col_normal text2 = <v>-netwr tlength2 = 15 tcolor2 = col_total text3 = <v>-waerk tlength3 = 5 tcolor3 = col_total ). APPEND lv_node_3 TO it_nodes. LOOP AT it_vbap ASSIGNING FIELD-SYMBOL(<p>) WHERE vbeln = <v>-vbeln. * Node-Level 4 DATA(lv_node_4) = VALUE snodetext( tlevel = 4 name = <p>-posnr nlength = 11 color = col_group text = <p>-matnr tlength = 23 tcolor = col_normal text1 = <p>-netwr tlength1 = 15 tcolor1 = col_total text2 = <p>-waerk tlength2 = 5 tcolor2 = col_total ). APPEND lv_node_4 TO it_nodes. ENDLOOP. ENDLOOP. ENDLOOP. * Tree-Objekte in Funktionsgruppe SEUT * Neue Hierarchie aufbauen bzw. Teilbaum einfügen CALL FUNCTION 'RS_TREE_CONSTRUCT' TABLES nodetab = it_nodes EXCEPTIONS tree_failure = 1 id_not_found = 2 wrong_relationship = 3 OTHERS = 4. IF sy-subrc = 0. * Konstanten sind in Typgruppe STREE definiert * Hierarchie anzeigen CALL FUNCTION 'RS_TREE_LIST_DISPLAY' EXPORTING callback_program = sy-repid callback_user_command = 'ON_USER_COMMAND' " Formroutine für Callback-Funktion für Buttons und Mausklicks status = 'STANDARD' " GUI-Status des Trees (wird für Callback benötigt, kann sonst weggelassen werden use_control = stree_use_list. " stree_use_list (Liste), stree_use_list_print (Druckausgabe), stree_use_control (Fullscreen-Control), stree_use_in_dynpro (Dynpro) ELSE. WRITE: / 'Fehler:', sy-subrc. ENDIF. * Form ON_USER_COMMAND * Callback-Funktion für Buttons und Mausklicks FORM on_user_command TABLES node STRUCTURE seucomm USING command CHANGING exit list_refresh. * Messagetext ausgeben, um geklicktes Element zu identifizieren MESSAGE |{ node-name }, { command }| TYPE 'S'. ENDFORM. |
Пример использования CL_SALV_TREE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
* Demoprogramme * * SALV_DEMO_TREE_DATA_UPDATE * SALV_DEMO_TREE_EVENTS * SALV_DEMO_TREE_FUNCTIONS * SALV_DEMO_TREE_METADATA * SALV_DEMO_TREE_SELECTIONS * SALV_DEMO_TREE_SETTINGS * SALV_DEMO_TREE_SIMPLE TYPES: ty_it_spfli TYPE STANDARD TABLE OF spfli WITH DEFAULT KEY. DATA: o_tree TYPE REF TO cl_salv_tree. DATA: it_spfli TYPE ty_it_spfli. DATA: it_spfli_empty TYPE ty_it_spfli. * Eventhandlerklasse CLASS lcl_events DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_button_click FOR EVENT link_click OF cl_salv_events_tree IMPORTING columnname node_key sender. CLASS-METHODS: on_user_command FOR EVENT added_function OF cl_salv_events IMPORTING e_salv_function sender. ENDCLASS. CLASS lcl_events IMPLEMENTATION. METHOD on_button_click. TRY. IF o_tree IS BOUND. * Unternode (Child) zur akt. geklickten Node holen DATA(o_child_node) = o_tree->get_nodes( )->get_node( node_key )->get_first_child( ). * alle Unternodes durchlaufen und Checkbox der Spalte Carrier setzen WHILE o_child_node IS BOUND. DATA(o_item) = o_child_node->get_item( 'CARRID' ). IF o_item->is_checked( ) = abap_true. o_item->set_checked( abap_false ). ELSE. o_item->set_checked( abap_true ). ENDIF. o_child_node = o_child_node->get_next_sibling( ). ENDWHILE. ENDIF. CATCH cx_salv_msg. ENDTRY. ENDMETHOD. METHOD on_user_command. MESSAGE e_salv_function TYPE 'I'. ENDMETHOD. ENDCLASS. START-OF-SELECTION. * Daten holen SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE it_spfli. SORT: it_spfli BY carrid. TRY. * Tree-Objekt mit leerer Tabelle (Dummy) erzeugen cl_salv_tree=>factory( IMPORTING r_salv_tree = o_tree CHANGING t_table = it_spfli_empty ). * Header setzen o_tree->get_tree_settings( )->set_header( CONV #( sy-title ) ). o_tree->get_tree_settings( )->set_hierarchy_header( 'Carrier' ). o_tree->get_tree_settings( )->set_hierarchy_tooltip( 'Carrier' ). o_tree->get_tree_settings( )->set_hierarchy_size( 40 ). o_tree->get_tree_settings( )->set_hierarchy_icon( CONV #( icon_tree ) ). * Treenodes einfügen LOOP AT it_spfli ASSIGNING FIELD-SYMBOL(<c>) GROUP BY <c>-carrid. DATA(it_cp) = VALUE ty_it_spfli( FOR <cp> IN GROUP <c> ( <cp> ) ). DATA(o_parent) = o_tree->get_nodes( )->add_node( related_node = '' relationship = cl_gui_column_tree=>relat_last_child collapsed_icon = CONV #( icon_closed_folder ) expanded_icon = CONV #( icon_open_folder ) row_style = if_salv_c_tree_style=>intensified text = CONV #( <c>-carrid ) ). IF lines( it_cp ) > 1. o_parent->get_item( 'CARRID' )->set_type( if_salv_c_item_type=>button ). o_parent->get_item( 'CARRID' )->set_value( 'all' ). ENDIF. LOOP AT GROUP <c> ASSIGNING FIELD-SYMBOL(<f>). DATA(o_carrid) = o_tree->get_nodes( )->add_node( related_node = o_parent->get_key( ) relationship = cl_gui_column_tree=>relat_last_child data_row = <f> row_style = if_salv_c_tree_style=>intensified text = CONV #( <f>-connid ) ). o_carrid->get_item( 'CARRID' )->set_type( if_salv_c_item_type=>checkbox ). o_carrid->get_item( 'CARRID' )->set_editable( abap_true ). ENDLOOP. ENDLOOP. * Mandant ausblenden o_tree->get_columns( )->get_column( 'MANDT' )->set_technical( abap_true ). * Carrid zentriert o_tree->get_columns( )->get_column( 'CARRID' )->set_alignment( if_salv_c_alignment=>right ). * Spaltenbreiten optimieren o_tree->get_columns( )->set_optimize( abap_true ). * Flugzeiten Aggregieren o_tree->get_aggregations( )->add_aggregation( columnname = 'FLTIME' aggregation = if_salv_c_aggregation=>total ). * Alle Funktionsbuttons einschalten o_tree->get_functions( )->set_all( abap_true ). * eigenen Button hinzufügen * das Hinzufügen des Buttons funktioniert nur, wenn die SALV-Table innerhalb eines Containers (z.B. cl_gui_container=>default_screen) eingebettet ist * o_tree->get_functions( )->add_function( name = 'BTN_USR' * icon = CONV #( icon_abap ) * text = 'Testbutton' * tooltip = 'Testbutton' * position = if_salv_c_function_position=>right_of_salv_functions ). * Handler für Button-Click setzen SET HANDLER lcl_events=>on_button_click FOR o_tree->get_event( ). * SET HANDLER lcl_events=>on_user_command FOR o_tree->get_event( ). o_tree->display( ). CATCH cx_root INTO DATA(e_txt). WRITE: / e_txt->get_text( ). ENDTRY. |
Дерево с таблицей на экране выбора и обработка событий
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
********************************************************************** * * Datentypen, Variablen, Konstanten * ********************************************************************** TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY. TYPES: ty_it_nodes TYPE STANDARD TABLE OF mtreesnode WITH DEFAULT KEY. DATA: o_splitter_main TYPE REF TO cl_gui_splitter_container. DATA: o_container_l TYPE REF TO cl_gui_container. DATA: o_container_r TYPE REF TO cl_gui_container. DATA: o_tree TYPE REF TO cl_gui_simple_tree. DATA: o_salv TYPE REF TO cl_salv_table. DATA: it_tree_spfli TYPE STANDARD TABLE OF spfli. DATA: it_salv_spfli TYPE STANDARD TABLE OF spfli. DATA: it_nodes TYPE ty_it_nodes. ********************************************************************** * * Eventhandler * ********************************************************************** CLASS lcl_events DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_selection_changed FOR EVENT selection_changed OF cl_gui_simple_tree IMPORTING node_key sender. ENDCLASS. CLASS lcl_events IMPLEMENTATION. * Klick auf ein aktives Baumelement METHOD on_selection_changed. IF o_salv IS BOUND. * Element in der Nodes-Tabelle lesen ASSIGN it_nodes[ node_key = node_key ] TO FIELD-SYMBOL(<fs_node>). * iTab für SALV-Table neu aufbauen, abhängig vom gewählten Baumelement it_salv_spfli = VALUE #( FOR l IN it_tree_spfli WHERE ( carrid = <fs_node>-text ) ( mandt = l-mandt carrid = l-carrid connid = l-connid countryfr = l-countryfr cityfrom = l-cityfrom airpfrom = l-airpfrom countryto = l-countryto cityto = l-cityto airpto = l-airpto fltime = l-fltime deptime = l-deptime arrtime = l-arrtime distance = l-distance distid = l-distid fltype = l-fltype period = l-period ) ). * SALV-Table neu anzeigen o_salv->refresh( ). ENDIF. ENDMETHOD. ENDCLASS. ********************************************************************** * * SELECTION-SCREEN * ********************************************************************** * leeres Selektionsbild als Dummy für die Container-Objekte (o_splitter_main ...) SELECTION-SCREEN BEGIN OF SCREEN 2000. SELECTION-SCREEN END OF SCREEN 2000. ********************************************************************** * * INITIALIZATION * ********************************************************************** INITIALIZATION. SELECT * INTO TABLE it_tree_spfli FROM spfli. ********************************************************************** * * START-OF-SELECTION * ********************************************************************** START-OF-SELECTION. * leeres Selektionbild 2000 anzeigen CALL SELECTION-SCREEN 2000. ********************************************************************** * * AT SELECTION-SCREEN OUTPUT * ********************************************************************** AT SELECTION-SCREEN OUTPUT. * Doppelte Objekterzeugung unterbinden IF NOT o_splitter_main IS BOUND. * Splitter auf default_screen (SELECTION-SCREEN 2000) erzeugen o_splitter_main = NEW #( parent = cl_gui_container=>default_screen rows = 1 columns = 2 ). * Breite in % (linke Spalte für den Tree) o_splitter_main->set_column_width( id = 1 width = 15 ). * linken und rechten Splitcontainer holen o_container_l = o_splitter_main->get_container( row = 1 column = 1 ). o_container_r = o_splitter_main->get_container( row = 1 column = 2 ). * Tree-Objekt erzeugen o_tree = NEW #( parent = o_container_l node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single ). * Eventtypten müssen gesondert registriert werden DATA(it_events) = VALUE ty_it_events( ( eventid = cl_gui_simple_tree=>eventid_selection_changed appl_event = abap_true ) ). o_tree->set_registered_events( events = it_events ). SET HANDLER lcl_events=>on_selection_changed FOR o_tree. * Root-Node einfügen it_nodes = VALUE #( ( node_key = 'ROOT' " Node-Bezeichner relatship = cl_gui_simple_tree=>relat_last_child disabled = abap_true isfolder = abap_true " Typ Ordner für Root-Element n_image = icon_folder " Icon Ordner exp_image = icon_open_folder " Icon geöffneter Ordner style = cl_gui_simple_tree=>style_default text = 'Airlines' ) ). * Childs an Root-Node anhängen LOOP AT it_tree_spfli ASSIGNING FIELD-SYMBOL(<fs_line>). * bei Änderung der carrid neue carrid als Child anhängen AT NEW carrid. APPEND VALUE #( node_key = |NODE{ sy-tabix }| " Node-Bezeichner relatship = cl_gui_simple_tree=>relat_last_child relatkey = 'ROOT' " an ROOT-Element anhängen style = cl_gui_simple_tree=>style_intensified text = |{ <fs_line>-carrid }| ) TO it_nodes. ENDAT. ENDLOOP. * Nodes im Baum einfügen o_tree->add_nodes( table_structure_name = 'MTREESNODE' " Typ muss gleich mit Zeilentyp von ty_it_nodes sein node_table = it_nodes ). * Root-Nodes des Trees expandieren o_tree->expand_root_nodes( ). * leeres SALV-Grid erzeugen cl_salv_table=>factory( EXPORTING r_container = o_container_r IMPORTING r_salv_table = o_salv CHANGING t_table = it_salv_spfli ). o_salv->get_display_settings( )->set_striped_pattern( abap_true ). o_salv->get_columns( )->set_optimize( abap_true ). o_salv->get_functions( )->set_all( ). o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ). o_salv->display( ). ENDIF. ********************************************************************** * * AT SELECTION-SCREEN * ********************************************************************** AT SELECTION-SCREEN. * wenn "Ausführen" (F8) geklickt wurde IF sy-ucomm = 'CRET'. * Selektionbild 2000 wieder anzeigen CALL SELECTION-SCREEN 2000. ENDIF. |
Отображение древовидной структуры с CL_GUI_LIST_TREE, перехват событий
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY. DATA: it_nodes TYPE treev_ntab. DATA: it_items TYPE STANDARD TABLE OF mtreeitm WITH DEFAULT KEY. CLASS lcl_event DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_node_double_click FOR EVENT node_double_click OF cl_gui_list_tree IMPORTING node_key. CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_list_tree IMPORTING node_key. CLASS-METHODS: on_item_double_click FOR EVENT item_double_click OF cl_gui_list_tree IMPORTING node_key item_name. CLASS-METHODS: on_button_click FOR EVENT button_click OF cl_gui_list_tree IMPORTING node_key item_name. CLASS-METHODS: on_link_click FOR EVENT link_click OF cl_gui_list_tree IMPORTING node_key item_name. CLASS-METHODS: on_checkbox_change FOR EVENT checkbox_change OF cl_gui_list_tree IMPORTING node_key item_name checked. ENDCLASS. CLASS lcl_event IMPLEMENTATION. METHOD on_node_double_click. WRITE: / |Node double click on node: { node_key }|. ENDMETHOD. METHOD on_item_double_click. WRITE: / |Item double click on node: { node_key }, item: { item_name }|. ENDMETHOD. METHOD on_link_click. WRITE: / |Link click on node: { node_key }, item: { item_name }|. ENDMETHOD. METHOD on_button_click. WRITE: / |Button click on node: { node_key }, item: { item_name }|. ENDMETHOD. METHOD on_checkbox_change. WRITE: / |Checkbox change on node: { node_key }, item: { item_name }|. ENDMETHOD. METHOD on_expand_no_children. WRITE: / |Expand no children on node: { node_key }|. ENDMETHOD. ENDCLASS. START-OF-SELECTION. * Container-Objekt erzeugen DATA(o_dock) = NEW cl_gui_docking_container( no_autodef_progid_dynnr = abap_true side = cl_gui_docking_container=>dock_at_left ratio = 20 caption = 'Datenausgabe' ). * Tree-Objekt erzeugen DATA(o_tree) = NEW cl_gui_list_tree( parent = o_dock node_selection_mode = cl_gui_list_tree=>node_sel_mode_single item_selection = abap_true with_headers = abap_false ). * Eventtypten müssen gesondert registriert werden DATA(it_events) = VALUE ty_it_events( ( eventid = cl_gui_list_tree=>eventid_node_double_click appl_event = abap_true ) ( eventid = cl_gui_list_tree=>eventid_item_double_click appl_event = abap_true ) ( eventid = cl_gui_list_tree=>eventid_expand_no_children appl_event = abap_true ) ( eventid = cl_gui_list_tree=>eventid_link_click appl_event = abap_true ) ( eventid = cl_gui_list_tree=>eventid_button_click appl_event = abap_true ) ( eventid = cl_gui_list_tree=>eventid_checkbox_change appl_event = abap_true ) ). o_tree->set_registered_events( events = it_events ). SET HANDLER lcl_event=>on_node_double_click FOR o_tree. SET HANDLER lcl_event=>on_item_double_click FOR o_tree. SET HANDLER lcl_event=>on_expand_no_children FOR o_tree. SET HANDLER lcl_event=>on_link_click FOR o_tree. SET HANDLER lcl_event=>on_button_click FOR o_tree. SET HANDLER lcl_event=>on_checkbox_change FOR o_tree. * Tree-Nodes einfügen -> die Bezeichner müssen eindeutig sein it_nodes = VALUE #( ( node_key = 'ROOT' hidden = abap_false disabled = abap_false isfolder = abap_true ) ( node_key = 'NODE1' relatkey = 'ROOT' relatship = cl_gui_list_tree=>relat_last_child hidden = abap_false disabled = abap_false isfolder = abap_true ) ( node_key = 'NODE1_1' relatkey = 'NODE1' relatship = cl_gui_list_tree=>relat_last_child hidden = abap_false disabled = abap_false isfolder = abap_false ) ( node_key = 'NODE1_2' relatkey = 'NODE1' relatship = cl_gui_list_tree=>relat_last_child hidden = abap_false disabled = abap_false isfolder = abap_false ) ( node_key = 'NODE1_3' relatkey = 'NODE1' relatship = cl_gui_list_tree=>relat_last_child hidden = abap_false disabled = abap_false isfolder = abap_false ) ( node_key = 'NODE2' relatkey = 'ROOT' relatship = cl_gui_list_tree=>relat_last_child hidden = abap_false disabled = abap_false isfolder = abap_false ) ( node_key = 'NODE3' relatkey = 'ROOT' relatship = cl_gui_list_tree=>relat_last_child hidden = abap_false disabled = abap_false isfolder = abap_false ) ). * Items für die Nodes definieren it_items = VALUE #( ( node_key = 'ROOT' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = 'Root' t_image = icon_led_green ) * Ordner ( node_key = 'NODE1' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = 'Node 1' t_image = icon_led_yellow ) * Item Button ( node_key = 'NODE1_1' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_button alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = 'Node 1_1' t_image = icon_led_green ) * Item Checkbox ( node_key = 'NODE1_2' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_checkbox alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = 'Node 1_2' t_image = icon_led_green editable = abap_true ) * Item Link ( node_key = 'NODE1_3' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_link alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = 'Node 1_3' t_image = icon_led_green ) * Item mit 4 Spalten ( node_key = 'NODE2' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = '' t_image = icon_led_green usebgcolor = abap_true ) ( node_key = 'NODE2' item_name = '2' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_left font = cl_gui_list_tree=>item_font_fixed length = 4 text = '1000' usebgcolor = abap_true ) ( node_key = 'NODE2' item_name = '3' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_left font = cl_gui_list_tree=>item_font_fixed length = 10 text = 'Liter' usebgcolor = abap_true ) ( node_key = 'NODE2' item_name = '4' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_prop text = 'Testeintrag 1' ) * Item mit 4 Spalten ( node_key = 'NODE3' item_name = '1' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_fixed text = '' t_image = icon_led_green usebgcolor = abap_true ) ( node_key = 'NODE3' item_name = '2' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_left font = cl_gui_list_tree=>item_font_fixed length = 4 text = '0100' usebgcolor = abap_true ) ( node_key = 'NODE3' item_name = '3' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_left font = cl_gui_list_tree=>item_font_fixed length = 10 text = 'mm' usebgcolor = abap_true ) ( node_key = 'NODE3' item_name = '4' style = cl_gui_list_tree=>style_default class = cl_gui_list_tree=>item_class_text alignment = cl_gui_list_tree=>align_auto font = cl_gui_list_tree=>item_font_prop text = 'Testeintrag 2' ) ). o_tree->add_nodes_and_items( node_table = it_nodes item_table = it_items item_table_structure_name = 'MTREEITM' ). " Typ muss gleich mit Zeilentyp von it_items sein * Root-Nodes des Trees expandieren o_tree->expand_root_nodes( ). * leere Toolbar ausblenden cl_abap_list_layout=>suppress_toolbar( ). WRITE space. " wichtig für Erzwingung der Listenausgabe und Anzeige des Trees |
Отображения дерева и таблицы без экрана, обработка событий
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY. TYPES: ty_it_nodes TYPE STANDARD TABLE OF mtreesnode WITH DEFAULT KEY. DATA: o_salv TYPE REF TO cl_salv_table. DATA: it_tree_spfli TYPE STANDARD TABLE OF spfli. DATA: it_salv_spfli TYPE STANDARD TABLE OF spfli. DATA: it_nodes TYPE ty_it_nodes. CLASS lcl_events DEFINITION. PUBLIC SECTION. * GUI Simple Tree CLASS-METHODS: on_keypress FOR EVENT node_keypress OF cl_gui_simple_tree IMPORTING node_key key sender. CLASS-METHODS: on_selection_changed FOR EVENT selection_changed OF cl_gui_simple_tree IMPORTING node_key sender. CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key sender. * ALV-Events für das SALV-Grid CLASS-METHODS: on_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object sender. CLASS-METHODS: on_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm sender. ENDCLASS. CLASS lcl_events IMPLEMENTATION. * Tastendruck METHOD on_keypress. MESSAGE |Node: { node_key } Taste: { key }| TYPE 'S'. ENDMETHOD. * Klick auf ein aktives Baumelement METHOD on_selection_changed. * Element in der Nodes-Tabelle lesen ASSIGN it_nodes[ node_key = node_key ] TO FIELD-SYMBOL(<fs_node>). * iTab für SALV-Table neu aufbauen CLEAR: it_salv_spfli. LOOP AT it_tree_spfli ASSIGNING FIELD-SYMBOL(<fs_line>) WHERE carrid = <fs_node>-text. APPEND <fs_line> TO it_salv_spfli. ENDLOOP. * SALV-Table neu anzeigen o_salv->refresh( ). ENDMETHOD. * bei Expandierung eines Baumelements ohne Unterelemente METHOD on_expand_no_children. MESSAGE |Node: { node_key }| TYPE 'S'. ENDMETHOD. * Toolbar-Buttons hinzufügen: * butn_type Bezeichung * 0 Button (normal) * 1 Menü + Defaultbutton * 2 Menü * 3 Separator * 4 Radiobutton * 5 Auswahlknopf (Checkbox) * 6 Menüeintrag METHOD on_toolbar. * Separator hinzufügen APPEND VALUE #( butn_type = 3 ) TO e_object->mt_toolbar. * Edit-Button hinzufügen APPEND VALUE #( butn_type = 5 text = 'Daten anzeigen' icon = icon_icon_list function = 'SHOW_DATA' quickinfo = 'Daten anzeigen' disabled = ' ' ) TO e_object->mt_toolbar. ENDMETHOD. * Benutzerkommando (Button-Klick) METHOD on_user_command. CASE e_ucomm. WHEN 'SHOW_DATA'. DATA: lv_row TYPE i. " Zeile auf Grid DATA: lv_value TYPE char255. " Wert DATA: lv_col TYPE i. " Spalte auf Grid DATA: lv_row_id TYPE lvc_s_row. " Zeilen-Id DATA: lv_col_id TYPE lvc_s_col. " Spalten-Id DATA: lv_row_no TYPE lvc_s_roid. " Numerische Zeilen ID sender->get_current_cell( IMPORTING e_row = lv_row e_value = lv_value e_col = lv_col es_row_id = lv_row_id es_col_id = lv_col_id es_row_no = lv_row_no ). MESSAGE |Zeile: { lv_row }, Spalte: { lv_col }, Wert: { lv_value }, Spaltenname: { lv_col_id-fieldname }| TYPE 'S'. ENDCASE. ENDMETHOD. ENDCLASS. START-OF-SELECTION. SELECT * INTO TABLE it_tree_spfli FROM spfli. * Splitter auf screen0 erzeugen DATA(o_split) = NEW cl_gui_splitter_container( parent = cl_gui_container=>screen0 no_autodef_progid_dynnr = abap_true rows = 1 columns = 2 ). * Breite in % (linke Spalte für den Tree) o_split->set_column_width( id = 1 width = 15 ). * linken und rechten Splitcontainer holen DATA(o_spl_left) = o_split->get_container( row = 1 column = 1 ). DATA(o_spl_right) = o_split->get_container( row = 1 column = 2 ). TRY. * Tree-Objekt erzeugen DATA(o_tree) = NEW cl_gui_simple_tree( parent = o_spl_left node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single ). * Eventtypten müssen gesondert registriert werden DATA(it_events) = VALUE ty_it_events( ( eventid = cl_gui_simple_tree=>eventid_node_keypress appl_event = abap_true ) ( eventid = cl_gui_simple_tree=>eventid_selection_changed appl_event = abap_true ) ( eventid = cl_gui_simple_tree=>eventid_expand_no_children appl_event = abap_true ) ). o_tree->set_registered_events( events = it_events ). o_tree->add_key_stroke( cl_gui_simple_tree=>key_enter ). * Events registrieren SET HANDLER lcl_events=>on_keypress FOR o_tree. SET HANDLER lcl_events=>on_selection_changed FOR o_tree. SET HANDLER lcl_events=>on_expand_no_children FOR o_tree. * Root-Node einfügen it_nodes = VALUE #( ( node_key = 'ROOT' " Node-Bezeichner relatship = cl_gui_simple_tree=>relat_last_child disabled = abap_true isfolder = abap_true " Typ Ordner für Root-Element n_image = icon_folder " Icon Ordner exp_image = icon_open_folder " Icon geöffneter Ordner style = cl_gui_simple_tree=>style_default text = 'Airlines' ) ). * Childs an Root-Node anhängen LOOP AT it_tree_spfli ASSIGNING FIELD-SYMBOL(<fs_line>). * bei Änderung der carrid neue carrid als Child anhängen AT NEW carrid. APPEND VALUE #( node_key = |NODE{ sy-tabix }| " eindeutiger Node-Bezeichner relatship = cl_gui_simple_tree=>relat_last_child relatkey = 'ROOT' " an ROOT-Element anhängen style = cl_gui_simple_tree=>style_intensified text = |{ <fs_line>-carrid }| ) TO it_nodes. ENDAT. ENDLOOP. * Nodes im Baum einfügen o_tree->add_nodes( table_structure_name = 'MTREESNODE' " Typ muss gleich mit Zeilentyp von ty_it_nodes sein node_table = it_nodes ). * Root-Nodes des Trees expandieren o_tree->expand_root_nodes( ). * leeres SALV-Grid erzeugen cl_salv_table=>factory( EXPORTING r_container = o_spl_right IMPORTING r_salv_table = o_salv CHANGING t_table = it_salv_spfli ). o_salv->get_display_settings( )->set_striped_pattern( abap_true ). o_salv->get_columns( )->set_optimize( abap_true ). o_salv->get_functions( )->set_all( ). o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ). o_salv->display( ). * Trick: Aus dem Split-Container rechts das Grid-Objekt holen und nach cl_gui_alv_grid casten READ TABLE o_spl_right->children INDEX 1 ASSIGNING FIELD-SYMBOL(<child>). IF <child> IS ASSIGNED. DATA(o_alv_grid) = CAST cl_gui_alv_grid( <child> ). * Eventhandler registrieren SET HANDLER lcl_events=>on_toolbar FOR o_alv_grid. SET HANDLER lcl_events=>on_user_command FOR o_alv_grid. ENDIF. CATCH cx_root INTO DATA(e_text). WRITE: / e_text->get_text( ). ENDTRY. * leere Toolbar ausblenden cl_abap_list_layout=>suppress_toolbar( ). * cl_gui_container=>screen0 erzwingen WRITE space. |
Отображения дерева CL_GUI_SIMPLE_TREE и обработка событий
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
* Demoprogramme * RSDEMO_DRAG_DROP_EDIT_TREE * RSDEMO_DRAG_DROP_TREE_MULTI * SAPSIMPLE_TREE_CONTROL_DEMO TYPES: ty_it_events TYPE STANDARD TABLE OF cntl_simple_event WITH DEFAULT KEY. TYPES: ty_it_nodes TYPE STANDARD TABLE OF mtreesnode WITH DEFAULT KEY. DATA: it_nodes TYPE ty_it_nodes. CLASS lcl_event DEFINITION. PUBLIC SECTION. CLASS-METHODS: on_keypress FOR EVENT node_keypress OF cl_gui_simple_tree IMPORTING node_key key sender. CLASS-METHODS: on_double_click FOR EVENT node_double_click OF cl_gui_simple_tree IMPORTING node_key sender. CLASS-METHODS: on_selection_changed FOR EVENT selection_changed OF cl_gui_simple_tree IMPORTING node_key sender. CLASS-METHODS: on_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key sender. ENDCLASS. CLASS lcl_event IMPLEMENTATION. * Tastendruck, die Tasten müssen mit add_key_stroke( ) registriert worden sein METHOD on_keypress. WRITE: / |Node: { node_key } Taste: { key }|. ENDMETHOD. * Doppelklick auf ein aktives Baumelement METHOD on_double_click. * Text in der Nodes-Tabelle anpassen ASSIGN it_nodes[ node_key = node_key ] TO FIELD-SYMBOL(<fs_node>). <fs_node>-text = 'Schonmal geklickt.'. * Text in der Node anpassen sender->node_set_text( node_key = node_key text = <fs_node>-text ). WRITE: / |Node: { node_key }, Text: { <fs_node>-text }|. ENDMETHOD. * Klick auf ein aktives Baumelement METHOD on_selection_changed. WRITE: / |Node: { node_key }|. ENDMETHOD. * bei Expandierung eines Baumelements ohne Unterelemente METHOD on_expand_no_children. WRITE: / |Node: { node_key }|. ENDMETHOD. ENDCLASS. START-OF-SELECTION. * Container-Objekt erzeugen DATA(o_dock) = NEW cl_gui_docking_container( no_autodef_progid_dynnr = abap_true side = cl_gui_docking_container=>dock_at_left ratio = 15 caption = 'Datenausgabe' ). * Tree-Objekt erzeugen DATA(o_tree) = NEW cl_gui_simple_tree( parent = o_dock node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single ). * Eventtypten müssen gesondert registriert werden DATA(it_events) = VALUE ty_it_events( ( eventid = cl_gui_simple_tree=>eventid_node_keypress ) * ( eventid = cl_gui_simple_tree=>eventid_node_double_click ) ( eventid = cl_gui_simple_tree=>eventid_selection_changed ) ( eventid = cl_gui_simple_tree=>eventid_expand_no_children appl_event = abap_true ) ). o_tree->set_registered_events( events = it_events ). * benötigte Tasten registrieren *cl_gui_simple_tree=>key_f1: F1 *cl_gui_simple_tree=>key_f4: F4 *cl_gui_simple_tree=>key_insert: Einfügen *cl_gui_simple_tree=>key_delete: Entfernen *cl_gui_simple_tree=>key_enter: Enter *cl_gui_simple_tree=>key_cut: Strg+X *cl_gui_simple_tree=>key_copy: Strg+C *cl_gui_simple_tree=>key_paste: Strg+V o_tree->add_key_stroke( cl_gui_simple_tree=>key_enter ). o_tree->add_key_stroke( cl_gui_simple_tree=>key_f1 ). o_tree->add_key_stroke( cl_gui_simple_tree=>key_delete ). * Events registrieren, on_double_click und on_selection_changed * dürfen nicht gleichzeitig registriert sein, sonst Exception SET HANDLER lcl_event=>on_keypress FOR o_tree. * SET HANDLER lcl_event=>on_double_click FOR o_tree. SET HANDLER lcl_event=>on_selection_changed FOR o_tree. SET HANDLER lcl_event=>on_expand_no_children FOR o_tree. * Tree-Nodes einfügen -> die Bezeichner müssen eindeutig sein it_nodes = VALUE #( ( node_key = 'FLDR1' relatship = cl_gui_simple_tree=>relat_last_child disabled = abap_true isfolder = abap_true n_image = icon_folder exp_image = icon_open_folder style = cl_gui_simple_tree=>style_default text = 'Ordner' ) ( node_key = 'NODE1' relatship = cl_gui_simple_tree=>relat_last_child disabled = abap_true isfolder = abap_true relatkey = 'FLDR1' n_image = icon_folder exp_image = icon_open_folder style = cl_gui_simple_tree=>style_intensified text = 'Datensatz 1' ) ( node_key = 'NODE1_1' relatship = cl_gui_simple_tree=>relat_last_child isfolder = abap_false relatkey = 'NODE1' n_image = icon_led_yellow style = cl_gui_simple_tree=>style_intensified text = 'Datensatz 1_1' ) ( node_key = 'NODE2' relatship = cl_gui_simple_tree=>relat_last_child isfolder = abap_false relatkey = 'FLDR1' n_image = icon_led_green style = cl_gui_simple_tree=>style_default text = 'Datensatz 2' ) ( node_key = 'NODE3' relatship = cl_gui_simple_tree=>relat_last_child isfolder = abap_false relatkey = 'FLDR1' disabled = abap_true n_image = icon_led_inactive style = cl_gui_simple_tree=>style_inactive text = 'Datensatz 3 (inaktiv)' ) ( node_key = 'NODE4' relatship = cl_gui_simple_tree=>relat_last_child isfolder = abap_false relatkey = 'FLDR1' disabled = abap_false n_image = icon_led_red style = cl_gui_simple_tree=>style_intensifd_critical text = 'Datensatz 4' ) ). o_tree->add_nodes( table_structure_name = 'MTREESNODE' " Typ muss gleich mit Zeilentyp von ty_it_nodes sein node_table = it_nodes ). * Root-Nodes des Trees expandieren o_tree->expand_root_nodes( ). * leere Toolbar ausblenden cl_abap_list_layout=>suppress_toolbar( ). WRITE space. " wichtig für Erzwingung der Listenausgabe und Anzeige des Trees |
Супер!