[ABAP] Beispiel für die Verwendung von CL_LIST_TREE_MODEL

* 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.

[ABAP] GUI Tree-Typen

CL_GUI_SIMPLE_TREE

  • einfache Baumdarstellung, ohne zus. Spalten

Demos

  • SAPSIMPLE_TREE_CONTEXT_MEN_DEM
  • SAPSIMPLE_TREE_CONTROL_DEMO
  • SAPSIMPLE_TREE_DRAG_DROP_DEMO
  • SAPTREX_NODE_STYLES
  • RSDEMO_DRAG_DROP_EDIT_TREE
  • RSDEMO_DRAG_DROP_TREE_MULTI

Links

CL_SALV_TREE

  • Nodes links (Tree) und Columns rechts getrennt dargestellt
  • Zeilentyp wird für alle Nodes des Trees gleich bei cl_salv_tree=>factory vorgegeben

Demos

  • 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

Links

CL_COLUMN_TREE_MODEL

  • Nodes links (Tree) und Columns rechts getrennt dargestellt, frei definierbar

Demos

  • SAPCOLUMN_TREE_MODEL_DEMO
  • SAPCOLUMN_TREE_CONTROL_DEMO

Links

CL_GUI_COLUMN_TREE

  • Nodes links (Tree) und Columns rechts getrennt dargestellt, frei definierbar

Demos

  • SAPCOLUMN_TREE_CONTROL_DEMO

Links

CL_LIST_TREE_MODEL

  • Nodes mit mehreren Columns zusammen auf der linken Seite definierbar

Demos

  • SAPTLIST_TREE_MODEL_DEMO

Links

CL_GUI_LIST_TREE

  • Nodes mit mehreren Columns zusammen auf der linken Seite definierbar

Demos

  • SAPTLIST_TREE_CONTROL_DEMO
  • SAPTLIST_TREE_CONTROL_DEMO_HDR

Links