[ABAP] Vertikaler Tabstrip-Container für Controls (CL_GUI_CONTAINER_BAR_XT, CL_GUI_CONTAINER_BAR_2, CL_GUI_CONTAINER_BAR)

Variante 1 (CL_GUI_CONTAINER_BAR_XT)

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_clicked FOR EVENT clicked OF cl_gui_container_bar_xt
        IMPORTING
            id
            container
            sender.
    CLASS-METHODS:
      on_empty FOR EVENT empty OF cl_gui_container_bar_xt
        IMPORTING
            sender.
    CLASS-METHODS:
      on_closed FOR EVENT closed OF cl_gui_container_bar_xt
        IMPORTING
            id
            sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
* Eintrag angeklickt
  METHOD on_clicked.
    MESSAGE |Property: { id } { container->get_container_type( ) }| TYPE 'S'.
  ENDMETHOD.
* wenn keine Einträge mehr vorhanden (z.B. alle durch Klick auf die Schließen-Kreuze geschlossen)
  METHOD on_empty.
    BREAK-POINT.
  ENDMETHOD.
* wenn Schließen-Kreuz eines Eintrages geklickt
  METHOD on_closed.
    BREAK-POINT.
  ENDMETHOD.
ENDCLASS.

INITIALIZATION.
  TRY.
* Vertikalen Splitter erzeugen
      DATA(o_splitter) = NEW cl_gui_splitter_container( parent                  = cl_gui_container=>default_screen
                                                        no_autodef_progid_dynnr = abap_true
                                                        rows                    = 1
                                                        columns                 = 2 ).

* 10% / 90% Teilung
      o_splitter->set_column_width( id = 1 width = 10 ).

      DATA(o_container_left) = o_splitter->get_container( row = 1 column = 1 ).
      DATA(o_container_right) = o_splitter->get_container( row = 1 column = 2 ).

* Zwei Einträge im cl_gui_container_bar_xt
      DATA(it_captions) = VALUE sbptcaptns( ( caption      = 'ABAP'
                                              icon         = icon_abap
                                              no_close     = abap_false
                                              name         = 'CAP1'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' )
                                            ( caption      = 'ABC'
                                              icon         = icon_abc
                                              no_close     = abap_false
                                              name         = 'CAP2'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' ) ).

* cl_gui_container_bar_xt im linken Splitter erzeugen
      DATA(o_toolbar_xt) = NEW cl_gui_container_bar_xt( active_id     = 1                                    " Nr. des aktiven Eintrages
                                                        parent        = o_container_left                     " Einbettung in linken Container
                                                        captions      = it_captions                          " Einträge
                                                        style         = cl_gui_container_bar_xt=>c_style_fix " Style: Fix = Feste Anordnung, Outlook = Anordnung klappt
                                                        close_buttons = abap_true ).                         " Schließen Kreuze anzeigen

* einen weiterer Eintrag im cl_gui_container_bar_xt hinzufügen
      DATA(lv_caption) = VALUE sbptcaptn( caption      = 'Activate'
                                          icon         = icon_activate
                                          no_close     = abap_false
                                          name         = 'CAP3'
                                          invisible    = abap_false
                                          pre_inst     = abap_false
                                          reuse_cnt_of = '' ).

* Eintrag einfügen und Id holen
      DATA(lv_id) = 0.
      o_toolbar_xt->add_cell( EXPORTING caption = lv_caption
                              CHANGING  id      = lv_id ).

* Testweise Container zum Eintrag ermitteln
      DATA(o_cont) = o_toolbar_xt->get_container( id = lv_id ).

* letzen Eintrag im cl_gui_container_bar_xt aktiv (ausgewählt) setzen
      o_toolbar_xt->set_active( id = lv_id ).

* Eventhandler registrieren
      SET HANDLER lcl_events=>on_clicked FOR o_toolbar_xt.
      SET HANDLER lcl_events=>on_empty FOR o_toolbar_xt.
      SET HANDLER lcl_events=>on_closed FOR o_toolbar_xt.

* im rechten Splitter Beispieldaten anzeigen
      DATA: it_sflight TYPE STANDARD TABLE OF sflight.

      SELECT * FROM sflight INTO TABLE @it_sflight.

      DATA: o_salv TYPE REF TO cl_salv_table.

      cl_salv_table=>factory( EXPORTING
                                r_container    = o_container_right
                              IMPORTING
                                r_salv_table   = o_salv
                              CHANGING
                                t_table        = it_sflight ).

      o_salv->get_functions( )->set_all( ).
      o_salv->display( ).

* leere Standard-Toolbar ausblenden
      cl_abap_list_layout=>suppress_toolbar( ).

* Ausgabe von cl_gui_container=>default_screen erzwingen
      WRITE: space.
    CATCH cx_root INTO DATA(e_txt).
  ENDTRY.

Variante 2 (CL_GUI_CONTAINER_BAR_2)

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_clicked FOR EVENT clicked OF cl_gui_container_bar_2
        IMPORTING
            id
            container
            sender.
    CLASS-METHODS:
      on_empty FOR EVENT empty OF cl_gui_container_bar_2
        IMPORTING
            sender.
    CLASS-METHODS:
      on_closed FOR EVENT closed OF cl_gui_container_bar_2
        IMPORTING
            id
            sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
* Eintrag angeklickt
  METHOD on_clicked.
    MESSAGE |Property: { id } { container->get_container_type( ) }| TYPE 'S'.
  ENDMETHOD.
* wenn keine Einträge mehr vorhanden (z.B. alle durch Klick auf die Schließen-Kreuze geschlossen)
  METHOD on_empty.
    BREAK-POINT.
  ENDMETHOD.
* wenn Schließen-Kreuz eines Eintrages geklickt
  METHOD on_closed.
    BREAK-POINT.
  ENDMETHOD.
ENDCLASS.

INITIALIZATION.
  TRY.
* Vertikalen Splitter erzeugen
      DATA(o_splitter) = NEW cl_gui_splitter_container( parent                  = cl_gui_container=>default_screen
                                                        no_autodef_progid_dynnr = abap_true
                                                        rows                    = 1
                                                        columns                 = 2 ).

* 10% / 90% Teilung
      o_splitter->set_column_width( id = 1 width = 10 ).

      DATA(o_container_left) = o_splitter->get_container( row = 1 column = 1 ).
      DATA(o_container_right) = o_splitter->get_container( row = 1 column = 2 ).

* Zwei Einträge im cl_gui_container_bar_2
      DATA(it_captions) = VALUE sbptcaptns( ( caption      = 'ABAP'
                                              icon         = icon_abap
                                              no_close     = abap_false
                                              name         = 'CAP1'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' )
                                            ( caption      = 'ABC'
                                              icon         = icon_abc
                                              no_close     = abap_false
                                              name         = 'CAP2'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' ) ).

* cl_gui_container_bar_2 im linken Splitter erzeugen
      DATA(o_toolbar) = NEW cl_gui_container_bar_2( active_id     = 1                                    " Nr. des aktiven Eintrages
                                                    parent        = o_container_left                     " Einbettung in linken Container
                                                    captions      = it_captions                          " Einträge
                                                    style         = cl_gui_container_bar_2=>c_style_tile " Style: Fix = Feste Anordnung, tile = Menü, Outlook = Anordnung klappt
                                                    close_buttons = abap_false ).                        " Schließen Kreuze anzeigen

* einen weiterer Eintrag im cl_gui_container_bar_2 hinzufügen
      DATA(lv_caption) = VALUE sbptcaptn( caption      = 'Activate'
                                          icon         = icon_activate
                                          no_close     = abap_false
                                          name         = 'CAP3'
                                          invisible    = abap_false
                                          pre_inst     = abap_false
                                          reuse_cnt_of = '' ).

* Eintrag einfügen und Id holen
      DATA(lv_id) = 0.
      o_toolbar->add_cell( EXPORTING caption = lv_caption
                           CHANGING  id      = lv_id ).

* Testweise Container zum Eintrag ermitteln
      DATA(o_cont) = o_toolbar->get_container( id = lv_id ).

* letzen Eintrag im cl_gui_container_bar_2 aktiv (ausgewählt) setzen
      o_toolbar->set_active( id = lv_id ).

* Eventhandler registrieren
      SET HANDLER lcl_events=>on_clicked FOR o_toolbar.
      SET HANDLER lcl_events=>on_empty FOR o_toolbar.
      SET HANDLER lcl_events=>on_closed FOR o_toolbar.

* im rechten Splitter Beispieldaten anzeigen
      DATA: it_sflight TYPE STANDARD TABLE OF sflight.

      SELECT * FROM sflight INTO TABLE @it_sflight.

      DATA: o_salv TYPE REF TO cl_salv_table.

      cl_salv_table=>factory( EXPORTING
                                r_container    = o_container_right
                              IMPORTING
                                r_salv_table   = o_salv
                              CHANGING
                                t_table        = it_sflight ).

      o_salv->get_functions( )->set_all( ).
      o_salv->display( ).

* leere Standard-Toolbar ausblenden
      cl_abap_list_layout=>suppress_toolbar( ).

* Ausgabe von cl_gui_container=>default_screen erzwingen
      WRITE: space.
    CATCH cx_root INTO DATA(e_txt).
  ENDTRY.

Variante 3 (CL_GUI_CONTAINER_BAR)

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      on_clicked FOR EVENT clicked OF cl_gui_container_bar
        IMPORTING
            id
            container
            sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.
* Eintrag angeklickt
  METHOD on_clicked.
    MESSAGE |Property: { id } { container->get_container_type( ) }| TYPE 'S'.
  ENDMETHOD.
ENDCLASS.

INITIALIZATION.
  TRY.
* Vertikalen Splitter erzeugen
      DATA(o_splitter) = NEW cl_gui_splitter_container( parent                  = cl_gui_container=>default_screen
                                                        no_autodef_progid_dynnr = abap_true
                                                        rows                    = 1
                                                        columns                 = 2 ).

* 10% / 90% Teilung
      o_splitter->set_column_width( id = 1 width = 10 ).

      DATA(o_container_left) = o_splitter->get_container( row = 1 column = 1 ).
      DATA(o_container_right) = o_splitter->get_container( row = 1 column = 2 ).

* Drei Einträge im cl_gui_container_bar
      DATA(it_captions) = VALUE sbptcaptns( ( caption      = 'ABAP'
                                              icon         = icon_abap
                                              no_close     = abap_false
                                              name         = 'CAP1'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' )
                                            ( caption      = 'ABC'
                                              icon         = icon_abc
                                              no_close     = abap_false
                                              name         = 'CAP2'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' )
                                            ( caption      = 'Activate'
                                              icon         = icon_activate
                                              no_close     = abap_false
                                              name         = 'CAP3'
                                              invisible    = abap_false
                                              pre_inst     = abap_false
                                              reuse_cnt_of = '' ) ).

* cl_gui_container_bar im linken Splitter erzeugen
      DATA(o_toolbar) = NEW cl_gui_container_bar( active_id     = 1                " Nr. des aktiven Eintrages
                                                  parent        = o_container_left " Einbettung in linken Container
                                                  captions      = it_captions ).   " Einträge

* Eventhandler registrieren
      SET HANDLER lcl_events=>on_clicked FOR o_toolbar.

* im rechten Splitter Beispieldaten anzeigen
      DATA: it_sflight TYPE STANDARD TABLE OF sflight.

      SELECT * FROM sflight INTO TABLE @it_sflight.

      DATA: o_salv TYPE REF TO cl_salv_table.

      cl_salv_table=>factory( EXPORTING
                                r_container    = o_container_right
                              IMPORTING
                                r_salv_table   = o_salv
                              CHANGING
                                t_table        = it_sflight ).

      o_salv->get_functions( )->set_all( ).
      o_salv->display( ).

* leere Standard-Toolbar ausblenden
      cl_abap_list_layout=>suppress_toolbar( ).

* Ausgabe von cl_gui_container=>default_screen erzwingen
      WRITE: space.
    CATCH cx_root INTO DATA(e_txt).
  ENDTRY.

Kommentare sind geschlossen.