abap2UI5

PDF Viewer - Two PDF Documents

Two PDF viewer frames displayed side by side. The second frame has the property isTrustedSource set to false which opens the PDF viewer with the displayType set to Link

Z2UI5_CL_SMPC_APP_442

Controls sap.m UI5 1.71

The facts

Repository
abap2UI5/samples-controls
Class
Z2UI5_CL_SMPC_APP_442
Source file
z2ui5_cl_smpc_app_442.clas.abap
Library
sap.m
UI5 entity
sap.m.PDFViewer
Demo kit sample
sap.m.sample.PDFViewerMultiple
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: pdfviewer, sap.m, pdfviewermultiple, scrollcontainer, flexbox, button, flexitemdata

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_442.clas.abap — 136 lines Read it on GitHub ↗
" @keywords pdfviewer sap.m pdfviewermultiple scrollcontainer flexbox button flexitemdata
" @summary Two PDF viewer frames displayed side by side. The second frame has the property isTrustedSource set to false which opens the PDF viewer with the displayType set to Link
CLASS z2ui5_cl_smpc_app_442 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA source TYPE string.
    DATA title1 TYPE string VALUE `My Title 1`.
    DATA title2 TYPE string VALUE `My Title 2`.
    DATA height TYPE string VALUE `600px`.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    " the sample's two documents, served from the demo kit host
    CONSTANTS c_valid_path   TYPE string VALUE `https://sdk.openui5.org/test-resources/sap/m/demokit/sample/PDFViewerMultiple/sample.pdf`.
    CONSTANTS c_invalid_path TYPE string VALUE `https://sdk.openui5.org/test-resources/sap/m/demokit/sample/PDFViewerMultiple/sample_nonexisting.pdf`.

    METHODS view_display.
    METHODS on_event.
    METHODS model_init.

  PRIVATE SECTION.
ENDCLASS.


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

        )->ele( `ScrollContainer`
            )->a( n = `height`     v = `100%`
            )->a( n = `width`      v = `100%`
            )->a( n = `horizontal` v = `true`
            )->a( n = `vertical`   v = `true`

            )->ele( `FlexBox`
                )->a( n = `class`      v = `sapUiSmallMargin`
                )->a( n = `direction`  v = `Column`
                )->a( n = `renderType` v = `Div`

                )->ele( `FlexBox`

                    " onCorrectPathClick / onIncorrectPathClick write /Source, which
                    " both PDFViewers bind - the same model write, done in ABAP
                    )->tag( `Button`
                        )->a( n = `text`  v = `Correctly Displayed`
                        )->a( n = `press` v = client->_event( `CORRECT_PATH` )
                    )->tag( `Button`
                        )->a( n = `text`  v = `Loading Error`
                        )->a( n = `press` v = client->_event( `INCORRECT_PATH` )

                )->end(

                )->ele( `FlexBox`
                    )->a( n = `direction`    v = `Row`
                    )->a( n = `fitContainer` v = `true`
                    )->a( n = `renderType`   v = `Div`

                    )->ele( `PDFViewer`
                        )->a( n = `class`           v = `sapUiSmallMarginEnd`
                        )->a( n = `source`          v = client->_bind( source )
                        )->a( n = `title`           v = client->_bind( title1 )
                        )->a( n = `height`          v = client->_bind( height )
                        )->a( n = `width`           v = `auto`
                        )->a( n = `isTrustedSource` v = `true`

                        )->ele( `layoutData`
                            )->tag( `FlexItemData`
                                )->a( n = `growFactor` v = `1`

                        )->end(
                    )->end(

                    )->ele( `PDFViewer`
                        )->a( n = `class`  v = `sapUiSmallMarginBegin`
                        )->a( n = `source` v = client->_bind( source )
                        )->a( n = `title`  v = client->_bind( title2 )
                        )->a( n = `height` v = client->_bind( height )
                        )->a( n = `width`  v = `auto`

                        )->ele( `layoutData`
                            )->tag( `FlexItemData`
                                )->a( n = `growFactor` v = `1` ).

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

  ENDMETHOD.


  METHOD on_event.

    CASE client->get_event( ).

      WHEN `CORRECT_PATH`.
        source = c_valid_path.

      WHEN `INCORRECT_PATH`.
        source = c_invalid_path.

    ENDCASE.

  ENDMETHOD.


  METHOD model_init.

    " onInit seeds /Source with the valid document
    source = c_valid_path.

  ENDMETHOD.

ENDCLASS.

More in sap.m

Search every abap2UI5 sample · the full list on one page

On this page