abap2UI5

View Settings Dialog - Custom Tabs

You can have custom tabs with your own defined content in the View Settings Dialog, as shown in this example.

Z2UI5_CL_SMPC_APP_297

Controls sap.m UI5 1.132

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_297
Source file
z2ui5_cl_smpc_app_297.clas.abap
Library
sap.m
UI5 entity
sap.m.ViewSettingsDialog
Demo kit sample
sap.m.sample.ViewSettingsDialogCustomTabs
SAP's own sample
running at sdk.openui5.org ↗
Minimum UI5
1.132
In the playground
runs in the browser, with no system and nothing installed

Keywords: viewsettingsdialog, settings, dialog, sap.m, viewsettingsdialogcustomtabs, html, viewsettingsitem, viewsettingsfilteritem, viewsettingscustomtab, panel, label, segmentedbutton

Controls it builds

Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.

Libraries

Run it here

The sample running, in this page — the app on its own, with no editor over it. Switch to Playground with this code

Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.

The ABAP

z2ui5_cl_smpc_app_297.clas.abap — 421 lines Read it on GitHub ↗
" @keywords viewsettingsdialog settings dialog sap.m viewsettingsdialogcustomtabs html viewsettingsitem viewsettingsfilteritem viewsettingscustomtab panel label segmentedbutton
" @summary You can have custom tabs with your own defined content in the View Settings Dialog, as shown in this example.
CLASS z2ui5_cl_smpc_app_297 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA date_value_state TYPE string.
    DATA date_value_state_text TYPE string.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS on_event.
    METHODS model_init.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_297 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_init( ).
      model_init( ).
      view_display( ).
    ELSEIF client->check_on_navigated( ).
      view_display( ).
    ELSEIF client->check_on_event( ).
      on_event( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

    DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).

    view->ele( n = `View` ns = `mvc`
        )->a( n = `xmlns:l`    v = `sap.ui.layout`
        )->a( n = `xmlns:mvc`  v = `sap.ui.core.mvc`
        )->a( n = `xmlns:core` v = `sap.ui.core`
        )->a( n = `xmlns`      v = `sap.m`

        " the sample's own style.css - the view carries vsdSetting and vsd-dp
        " and the rules behind them have to come with it (apps 122/124/133).
        " \{ \} escaped: the XMLView parser reads an unescaped brace as a binding
        )->tag( n = `HTML` ns = `core`
            )->a( n = `content` v = `<style>.sapMSegB.vsdSetting\{margin-bottom:1rem\}` &&
                                    `.vsd-dp\{margin-inline-start:2rem;margin-block-start:2rem\}</style>`

        " the three controller-loaded fragments, declared in the view's dependents aggregation
        )->ele( n = `dependents` ns = `mvc`

            )->ele( `ViewSettingsDialog`
                )->a( n = `id`      v = `settingsDialog`
                )->a( n = `confirm` v = client->_event( val = `CONFIRM` arg = `${$parameters>/filterString}` )

                )->ele( `sortItems`
                    )->tag( `ViewSettingsItem`
                        )->a( n = `text`     v = `Field 1`
                        )->a( n = `key`      v = `1`
                        )->a( n = `selected` v = `true`
                    )->tag( `ViewSettingsItem`
                        )->a( n = `text` v = `Field 2`
                        )->a( n = `key`  v = `2`
                    )->tag( `ViewSettingsItem`
                        )->a( n = `text` v = `Field 3`
                        )->a( n = `key`  v = `3`

                )->end(
                )->ele( `groupItems`
                    )->tag( `ViewSettingsItem`
                        )->a( n = `text`     v = `Field 1`
                        )->a( n = `key`      v = `1`
                        )->a( n = `selected` v = `true`
                    )->tag( `ViewSettingsItem`
                        )->a( n = `text` v = `Field 2`
                        )->a( n = `key`  v = `2`
                    )->tag( `ViewSettingsItem`
                        )->a( n = `text` v = `Field 3`
                        )->a( n = `key`  v = `3`

                )->end(
                )->ele( `filterItems`
                    )->ele( `ViewSettingsFilterItem`
                        )->a( n = `text` v = `Field1`
                        )->a( n = `key`  v = `1`

                        )->ele( `items`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value A`
                                )->a( n = `key`  v = `1a`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value B`
                                )->a( n = `key`  v = `1b`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value C`
                                )->a( n = `key`  v = `1c`

                        )->end(
                    )->end(
                    )->ele( `ViewSettingsFilterItem`
                        )->a( n = `text` v = `Field2`
                        )->a( n = `key`  v = `2`

                        )->ele( `items`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value A`
                                )->a( n = `key`  v = `2a`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value B`
                                )->a( n = `key`  v = `2b`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value C`
                                )->a( n = `key`  v = `2c`

                        )->end(
                    )->end(
                    )->ele( `ViewSettingsFilterItem`
                        )->a( n = `text` v = `Field3`
                        )->a( n = `key`  v = `3`

                        )->ele( `items`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value A`
                                )->a( n = `key`  v = `3a`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value B`
                                )->a( n = `key`  v = `3b`
                            )->tag( `ViewSettingsItem`
                                )->a( n = `text` v = `Value C`
                                )->a( n = `key`  v = `3c`

                        )->end(
                    )->end(
                )->end(
                )->ele( `customTabs`
                    )->ele( `ViewSettingsCustomTab`
                        )->a( n = `id`      v = `app-settings`
                        )->a( n = `icon`    v = `sap-icon://action-settings`
                        )->a( n = `title`   v = `Settings`
                        )->a( n = `tooltip` v = `Application Settings`

                        )->ele( `content`
                            )->ele( `Panel`
                                )->a( n = `height` v = `338px`

                                )->ele( `content`

                                    )->tag( `Label`
                                        )->a( n = `text`   v = `Theme`
                                        )->a( n = `design` v = `Bold`
                                        )->a( n = `id`     v = `VSDThemeLabel`

                                    )->ele( `SegmentedButton`
                                        )->a( n = `class`        v = `vsdSetting`
                                        )->a( n = `selectedItem` v = `VSDsap_quartzlight`
                                        )->a( n = `id`           v = `VSDThemeButtons`
                                        )->a( n = `width`        v = `100%`

                                        )->ele( `items`
                                            )->tag( `SegmentedButtonItem`
                                                )->a( n = `text` v = `High Contrast Black`
                                                )->a( n = `id`   v = `VSDsap_hcb`
                                            )->tag( `SegmentedButtonItem`
                                                )->a( n = `text` v = `Quartz Light`
                                                )->a( n = `id`   v = `VSDsap_quartzlight`

                                        )->end(
                                    )->end(

                                    )->tag( `Label`
                                        )->a( n = `text`   v = `Compact Content Density`
                                        )->a( n = `design` v = `Bold`

                                    )->ele( `SegmentedButton`
                                        )->a( n = `class`        v = `vsdSetting`
                                        )->a( n = `selectedItem` v = `VSDcompactOn`
                                        )->a( n = `id`           v = `VSDCompactModeButtons`
                                        )->a( n = `width`        v = `100%`

                                        )->ele( `items`
                                            )->tag( `SegmentedButtonItem`
                                                )->a( n = `text` v = `On`
                                                )->a( n = `id`   v = `VSDcompactOn`
                                            )->tag( `SegmentedButtonItem`
                                                )->a( n = `text` v = `Off`
                                                )->a( n = `id`   v = `VSDcompactOff`

                                        )->end(
                                    )->end(

                                    )->tag( `Label`
                                        )->a( n = `text`   v = `Right To Left Mode`
                                        )->a( n = `design` v = `Bold`

                                    )->ele( `SegmentedButton`
                                        )->a( n = `selectedItem` v = `VSDRTLOff`
                                        )->a( n = `id`           v = `VSDRTLButtons`
                                        )->a( n = `width`        v = `100%`

                                        )->ele( `items`
                                            )->tag( `SegmentedButtonItem`
                                                )->a( n = `text` v = `On`
                                                )->a( n = `id`   v = `VSDRTLOn`
                                            )->tag( `SegmentedButtonItem`
                                                )->a( n = `text` v = `Off`
                                                )->a( n = `id`   v = `VSDRTLOff`

                                        )->end(
                                    )->end(
                                )->end(
                            )->end(
                        )->end(
                    )->end(
                    )->ele( `ViewSettingsCustomTab`
                        )->a( n = `id`      v = `example-settings`
                        )->a( n = `tooltip` v = `default icon`

                        )->ele( `content`
                            )->tag( `Button`
                                )->a( n = `text` v = `simple button example`

                        )->end(
                    )->end(
                )->end(
            )->end(

            )->ele( `ViewSettingsDialog`
                )->a( n = `id`      v = `settingsDialogCustomTab`
                )->a( n = `confirm` v = client->_event( val = `CONFIRM` arg = `${$parameters>/filterString}` )

                )->ele( `customTabs`
                    )->ele( `ViewSettingsCustomTab`
                        )->a( n = `id`      v = `app-settings-single`
                        )->a( n = `icon`    v = `sap-icon://action-settings`
                        )->a( n = `title`   v = `Settings`
                        )->a( n = `tooltip` v = `Application Settings`

                        )->ele( `content`
                            )->ele( `Panel`
                                )->a( n = `height` v = `386px`

                                )->tag( `Label`
                                    )->a( n = `text`   v = `Theme`
                                    )->a( n = `design` v = `Bold`
                                    )->a( n = `id`     v = `VSDThemeLabelSingle`

                                )->ele( `SegmentedButton`
                                    )->a( n = `class`        v = `vsdSetting`
                                    )->a( n = `selectedItem` v = `VSDsap_quartzlightSingle`
                                    )->a( n = `id`           v = `VSDThemeButtonsSingle`
                                    )->a( n = `width`        v = `100%`

                                    )->ele( `items`
                                        )->tag( `SegmentedButtonItem`
                                            )->a( n = `text` v = `High Contrast Black`
                                            )->a( n = `id`   v = `VSDsap_hcbSingle`
                                        )->tag( `SegmentedButtonItem`
                                            )->a( n = `text` v = `Quartz Light`
                                            )->a( n = `id`   v = `VSDsap_quartzlightSingle`

                                    )->end(
                                )->end(

                                )->tag( `Label`
                                    )->a( n = `text`   v = `Compact Content Density`
                                    )->a( n = `design` v = `Bold`

                                )->ele( `SegmentedButton`
                                    )->a( n = `class`        v = `vsdSetting`
                                    )->a( n = `selectedItem` v = `VSDcompactOnSingle`
                                    )->a( n = `id`           v = `VSDCompactModeButtonsSingle`
                                    )->a( n = `width`        v = `100%`

                                    )->ele( `items`
                                        )->tag( `SegmentedButtonItem`
                                            )->a( n = `text` v = `On`
                                            )->a( n = `id`   v = `VSDcompactOnSingle`
                                        )->tag( `SegmentedButtonItem`
                                            )->a( n = `text` v = `Off`
                                            )->a( n = `id`   v = `VSDcompactOffSingle`

                                    )->end(
                                )->end(

                                )->tag( `Label`
                                    )->a( n = `text`   v = `Right To Left Mode`
                                    )->a( n = `design` v = `Bold`

                                )->ele( `SegmentedButton`
                                    )->a( n = `selectedItem` v = `VSDRTLOffSingle`
                                    )->a( n = `id`           v = `VSDRTLButtonsSingle`
                                    )->a( n = `width`        v = `100%`

                                    )->ele( `items`
                                        )->tag( `SegmentedButtonItem`
                                            )->a( n = `text` v = `On`
                                            )->a( n = `id`   v = `VSDRTLOnSingle`
                                        )->tag( `SegmentedButtonItem`
                                            )->a( n = `text` v = `Off`
                                            )->a( n = `id`   v = `VSDRTLOffSingle`

                                    )->end(
                                )->end(
                            )->end(
                        )->end(
                    )->end(
                )->end(
            )->end(

            )->ele( `ViewSettingsDialog`
                )->a( n = `id`          v = `settingsDialogDatePicker`
                )->a( n = `confirm`     v = client->_event( val = `CONFIRM` arg = `${$parameters>/filterString}` )
                )->a( n = `beforeClose` v = client->_event(
                          val    = `BEFORE_CLOSE`
                          " _bind( ) - NOT path = abap_true: an ABAP template eats the
                          " braces (|${ ... }| yields "$" + the bare path), and $/PATH is
                          " not a token the UI5 event-handler parser knows. The braced
                          " form gives the ${/PATH} the expression needs
                          s_ctrl = VALUE #( prevent_default_expr =
                                              |${ client->_bind( date_value_state ) } === 'Error'| ) )

                )->ele( `customTabs`
                    )->ele( `ViewSettingsCustomTab`
                        )->a( n = `id`      v = `app-settings-datepicker`
                        )->a( n = `icon`    v = `sap-icon://action-settings`
                        )->a( n = `title`   v = `Settings`
                        )->a( n = `tooltip` v = `Application Settings`

                        )->ele( `content`
                            )->tag( `DatePicker`
                                )->a( n = `id`             v = `datePicker`
                                )->a( n = `class`          v = `vsd-dp`
                                )->a( n = `width`          v = `80%`
                                )->a( n = `valueState`     v = client->_bind( date_value_state )
                                )->a( n = `valueStateText` v = client->_bind( date_value_state_text )
                                )->a( n = `change`         v = client->_event( val = `DATE_CHANGE` arg = `${$parameters>/valid}` )

                        )->end(
                    )->end(
                )->end(
            )->end(
        )->end(

        )->ele( n = `VerticalLayout` ns = `l`
            )->a( n = `class` v = `sapUiContentPadding`
            )->a( n = `width` v = `100%`

            )->tag( `Button`
                )->a( n = `text`  v = `Open View Settings Dialog with several tabs`
                )->a( n = `press` v = client->_event( `OPEN_DIALOG` )
            )->tag( `Button`
                )->a( n = `text`  v = `Open View Settings Dialog with single custom tab`
                )->a( n = `press` v = client->_event( `OPEN_SINGLE_TAB` )
            )->tag( `Button`
                )->a( n = `text`  v = `Open View Settings Dialog with single custom tab with DatePicker`
                )->a( n = `press` v = client->_event( `OPEN_DATE_PICKER` ) ).

    client->view_display( view->stringify( ) ).

  ENDMETHOD.


  METHOD on_event.

    CASE client->get_event( ).

      WHEN `OPEN_DIALOG`.
        client->follow_up_action( val   = client->cs_event-control_by_id
                                  t_arg = VALUE #( ( `settingsDialog` ) ( `open` ) ) ).

      WHEN `OPEN_SINGLE_TAB`.
        client->follow_up_action( val   = client->cs_event-control_by_id
                                  t_arg = VALUE #( ( `settingsDialogCustomTab` ) ( `open` ) ) ).

      WHEN `OPEN_DATE_PICKER`.
        client->follow_up_action( val   = client->cs_event-control_by_id
                                  t_arg = VALUE #( ( `settingsDialogDatePicker` ) ( `open` ) ) ).

      WHEN `DATE_CHANGE`.
        " the original validateDate: an unparsable date marks the field
        IF client->get_event_arg( ) = abap_true.
          date_value_state      = `None`.
          date_value_state_text = ``.

        ELSE.
          date_value_state      = `Error`.
          date_value_state_text = `Invalid date. Please enter a date in the correct format.`.
        ENDIF.

      WHEN `BEFORE_CLOSE`.
        " the client already vetoed the close when the state is Error (see the
        " prevent_default_expr on the wire); the backend only adds the message
        IF date_value_state = `Error`.
          client->message_toast_display( `The entered date is invalid. Please correct it before closing the dialog.` ).
        ENDIF.

      WHEN `CONFIRM`.
        DATA(filter_string) = client->get_event_arg( ).
        IF filter_string IS NOT INITIAL.
          client->message_toast_display( filter_string ).
        ENDIF.

    ENDCASE.

  ENDMETHOD.


  METHOD model_init.

    date_value_state = `None`.

  ENDMETHOD.

ENDCLASS.

More in sap.m

Search every abap2UI5 sample · the full list on one page

On this page