abap2UI5

Toolbar vs Bar vs OverflowToolbar

Toolbar handles overflow by shrinking items. OverflowToolbar provides an overflow menu. Bar is able to perfectly center a text if nothing overflows.

Z2UI5_CL_SMPC_APP_189

Controls sap.m UI5 1.71

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_189
Source file
z2ui5_cl_smpc_app_189.clas.abap
Library
sap.m
UI5 entity
sap.m.Bar
Demo kit sample
sap.m.sample.ToolbarVsBar
SAP's own sample
running at sdk.openui5.org ↗
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
runs in the browser, with no system and nothing installed

Keywords: bar, sap.m, toolbarvsbar, button, toolbar, toolbarspacer, title, messagestrip, label, toolbarlayoutdata, overflowtoolbar

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_189.clas.abap — 203 lines Read it on GitHub ↗
" @keywords bar sap.m toolbarvsbar button toolbar toolbarspacer title messagestrip label toolbarlayoutdata overflowtoolbar
" @summary Toolbar handles overflow by shrinking items. OverflowToolbar provides an overflow menu. Bar is able to perfectly center a text if nothing overflows.
CLASS z2ui5_cl_smpc_app_189 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_189 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_navigated( ).
      view_display( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

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

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

        )->ele( `Page`
            )->a( n = `title`         v = `Bar can center a Title.`
            )->a( n = `titleLevel`    v = `H2`
            )->a( n = `class`         v = `sapUiContentPadding`
            )->a( n = `showNavButton` v = `true`

            )->ele( `headerContent`
                )->tag( `Button`
                    )->a( n = `icon` v = `sap-icon://action`

            )->end(
            )->ele( `subHeader`
                )->ele( `Toolbar`
                    )->tag( `Button`
                        )->a( n = `type`    v = `Back`
                        )->a( n = `tooltip` v = `Back`
                    )->tag( `ToolbarSpacer`
                    )->tag( `Title`
                        )->a( n = `text`  v = `Toolbar center`
                        )->a( n = `level` v = `H3`
                    )->tag( `ToolbarSpacer`

                )->end(
            )->end(
            )->ele( `content`
                )->tag( `MessageStrip`
                    )->a( n = `text`  v = `A Toolbar's centering technique will be slightly off the center if there is a button on the left.`
                    )->a( n = `class` v = `sapUiTinyMargin`

                )->ele( `Toolbar`
                    )->ele( `Label`
                        )->a( n = `text` v = `Toolbar can shrink content in case of overflow.`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `false`

                        )->end(
                    )->end(
                    )->ele( `Button`
                        )->a( n = `text` v = `Accept`
                        )->a( n = `type` v = `Accept`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `true`

                        )->end(
                    )->end(
                    )->ele( `Label`
                        )->a( n = `text` v = `This is a long non-shrinkable label.`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `false`

                        )->end(
                    )->end(
                    )->ele( `Button`
                        )->a( n = `text` v = `Reject`
                        )->a( n = `type` v = `Reject`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `true`

                        )->end(
                    )->end(
                    )->ele( `Button`
                        )->a( n = `text` v = `Big Big Big Big Big Big Big Big Button`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `true`

                        )->end(
                    )->end(
                )->end(
                )->tag( `Label`

                )->ele( `Bar`
                    )->ele( `contentLeft`
                        )->tag( `Label`
                            )->a( n = `text` v = `Bar cannot really handle overflow it just cuts the content.`

                    )->end(
                    )->ele( `contentMiddle`
                        )->tag( `Button`
                            )->a( n = `text` v = `Accept`
                            )->a( n = `type` v = `Accept`
                        )->tag( `Label`
                            )->a( n = `text` v = `This is a long non-shrinkable label.`
                        )->tag( `Button`
                            )->a( n = `text` v = `Reject`
                            )->a( n = `type` v = `Reject`
                        )->tag( `Button`
                            )->a( n = `text` v = `Edit`
                        )->tag( `Button`
                            )->a( n = `text` v = `Big Big Big Big Big Big Big Big Button`

                    )->end(
                )->end(
                )->tag( `Label`

                )->ele( `OverflowToolbar`
                    )->ele( `Label`
                        )->a( n = `text` v = `OverflowToolbar provides a See more (...) button for overflow.`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `false`

                        )->end(
                    )->end(
                    )->ele( `Button`
                        )->a( n = `text` v = `Accept`
                        )->a( n = `type` v = `Accept`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `true`

                        )->end(
                    )->end(
                    )->ele( `Label`
                        )->a( n = `text` v = `This is a long non-shrinkable label`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `false`

                        )->end(
                    )->end(
                    )->ele( `Button`
                        )->a( n = `text` v = `Reject`
                        )->a( n = `type` v = `Reject`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `true`

                        )->end(
                    )->end(
                    )->ele( `Button`
                        )->a( n = `text` v = `Big Big Big Big Big Big Big Big Button`

                        )->ele( `layoutData`
                            )->tag( `ToolbarLayoutData`
                                )->a( n = `shrinkable` v = `true`

                        )->end(
                    )->end(
                )->end(
            )->end(
            )->ele( `footer`
                )->ele( `Toolbar`

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

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

  ENDMETHOD.

ENDCLASS.

More in sap.m

Search every abap2UI5 sample · the full list on one page

On this page