abap2UI5

Code Editor with IconTabHeader

Example how to use CodeEditor with IconTabHeader to create a tab-based experience.

Z2UI5_CL_SMPC_APP_150

Controls sap.ui.codeeditor UI5 1.71

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_150
Source file
z2ui5_cl_smpc_app_150.clas.abap
Library
sap.ui.codeeditor
UI5 entity
sap.ui.codeeditor.CodeEditor
Demo kit sample
sap.ui.codeeditor.sample.CodeEditorIconTabHeader
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: codeeditor, code, editor, sap.ui.codeeditor, icontabheader, icontabfilter

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_150.clas.abap — 90 lines Read it on GitHub ↗
" @keywords codeeditor code editor sap.ui.codeeditor icontabheader icontabfilter
" @summary Example how to use CodeEditor with IconTabHeader to create a tab-based experience.
CLASS z2ui5_cl_smpc_app_150 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA selected_key TYPE string.
    DATA code_init    TYPE string.
    DATA code_a       TYPE string.
    DATA code_b       TYPE string.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.
    METHODS model_init.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smpc_app_150 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( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

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

    " the original's onSelectTab swaps the CodeEditor value per selected key in
    " JS (A -> example2, B -> example1, anything else empty) and onInit seeds the
    " hint text. Rebuilt on the client: selectedKey is two-way bound and the
    " editor value is the same switch as an expression binding - no round-trip
    view->ele( n = `View` ns = `mvc`
        )->a( n = `xmlns`     v = `sap.m`
        )->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
        )->a( n = `xmlns:ce`  v = `sap.ui.codeeditor`
        )->a( n = `height`    v = `100%`

        )->ele( `IconTabHeader`
            )->a( n = `id`          v = `iconTabHeader`
            )->a( n = `selectedKey` v = client->_bind( selected_key )
            )->ele( `items`
                )->tag( `IconTabFilter`
                    )->a( n = `text` v = `A`
                    )->a( n = `key`  v = `A`
                )->tag( `IconTabFilter`
                    )->a( n = `text` v = `B`
                    )->a( n = `key`  v = `B`

            )->end(
        )->end(

        )->tag( n = `CodeEditor` ns = `ce`
            )->a( n = `id`     v = `aCodeEditor`
            )->a( n = `height` v = `300px`
            )->a( n = `type`   v = `javascript`
            )->a( n = `value`  v = |\{= ${ client->_bind( selected_key ) } === 'A' ? ${ client->_bind( code_a ) }| &&
                                    | : (${ client->_bind( selected_key ) } === 'B' ? ${ client->_bind( code_b ) }| &&
                                    | : ${ client->_bind( code_init ) }) \}| ).

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

  ENDMETHOD.


  METHOD model_init.

    " the original's onInit hint plus its two example strings, verbatim - note
    " the original's own swap: tab A shows example2, tab B shows example1
    selected_key = `invalidKey`.
    code_init    = `// select tabs to see value of CodeEditor changing`.
    code_a       = |function myFunction(p1, p2) \{\n\treturn 'foo';\n\}|.
    code_b       = |function loadDoc() \{\n\treturn 'bar';\n\}|.

  ENDMETHOD.

ENDCLASS.

More in sap.ui.codeeditor

Search every abap2UI5 sample · the full list on one page

On this page