abap2UI5

Color Picker - displayMode: Default

Basic example of Color Picker. Note that you have to set the Color Picker mode to HSL to take advantage of the responsiveness of the control on a mobile device.

Z2UI5_CL_SMPC_APP_309

Controls sap.ui.unified UI5 1.71

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_309
Source file
z2ui5_cl_smpc_app_309.clas.abap
Library
sap.ui.unified
UI5 entity
sap.ui.unified.ColorPicker
Demo kit sample
sap.ui.unified.sample.ColorPicker
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: colorpicker, color, picker, sap.ui.unified, vbox, button, responsivepopover

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_309.clas.abap — 114 lines Read it on GitHub ↗
" @keywords colorpicker color picker sap.ui.unified vbox button responsivepopover
" @summary Basic example of Color Picker. Note that you have to set the Color Picker mode to HSL to take advantage of the responsiveness of the control on a mobile device.
CLASS z2ui5_cl_smpc_app_309 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS on_event.
    METHODS popover_colorpicker_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_309 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    me->client = client.
    IF 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 = `height`    v = `100%`
        )->a( n = `xmlns`     v = `sap.ui.unified`
        )->a( n = `xmlns:m`   v = `sap.m`
        )->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`

        )->ele( n = `Page` ns = `m`
            )->a( n = `showHeader`    v = `false`
            )->a( n = `class`         v = `sapUiContentPadding`
            )->a( n = `showNavButton` v = `false`

            )->ele( n = `VBox` ns = `m`
                )->a( n = `class` v = `sapUiSmallMargin`

                )->tag( `ColorPicker`
                    )->a( n = `id`   v = `cp`
                    )->a( n = `mode` v = `HSL`

                )->tag( n = `Button` ns = `m`
                    )->a( n = `text`  v = `Open ColorPicker in a ResponsivePopover`
                    )->a( n = `press` v = client->_event( val = `OPEN_POPOVER` arg = `$event.oSource.sId` ) ).

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

  ENDMETHOD.


  METHOD on_event.

    IF client->get_event( ) = `OPEN_POPOVER`.
      popover_colorpicker_display( ).
    ENDIF.

  ENDMETHOD.


  METHOD popover_colorpicker_display.

    " openPopover builds the ResponsivePopover imperatively (new ResponsivePopover({...}).openBy(button));
    " expressed as a core:FragmentDefinition shown anchored via popover_display( xml by_id )
    DATA(popover) = z2ui5_cl_ui5_view_builder=>factory( ).

    popover->ele( n = `FragmentDefinition` ns = `core`
        )->a( n = `xmlns`      v = `sap.m`
        )->a( n = `xmlns:core` v = `sap.ui.core`
        )->a( n = `xmlns:u`    v = `sap.ui.unified`

        )->ele( `ResponsivePopover`
            )->a( n = `title`           v = `Color Picker`
            )->a( n = `showCloseButton` v = `false`
            " the phone branch stays a branch: the device> model is served on every
            " view slot, so showHeader and the two buttons follow the real device
            )->a( n = `showHeader`      v = `{= ${device>/system/phone}}`

            )->ele( `content`
                )->tag( n = `ColorPicker` ns = `u`
                    )->a( n = `mode` v = `HSL`

            )->end(
            )->ele( `beginButton`
                )->tag( `Button`
                    )->a( n = `text`    v = `Submit`
                    )->a( n = `visible` v = `{= ${device>/system/phone}}`
                    )->a( n = `press`   v = client->follow_up_action( client->cs_event-popover_close )

            )->end(
            )->ele( `endButton`
                )->tag( `Button`
                    )->a( n = `text`    v = `Cancel`
                    )->a( n = `visible` v = `{= ${device>/system/phone}}`
                    )->a( n = `press`   v = client->follow_up_action( client->cs_event-popover_close ) ).

    client->popover_display( xml   = popover->stringify( )
                             by_id = client->get_event_arg( ) ).

  ENDMETHOD.

ENDCLASS.

More in sap.ui.unified

Search every abap2UI5 sample · the full list on one page

On this page