Web Dynpro for ABAP ( 三 ) Window popup

谷梁驰
2023-12-01

WDA程式在编写的过程中经常会有弹出框的需求,一般我常会用到的一般有三种:

1)、Message的弹出框用于confirm;

2)、需要自己画控件的window;

3)、弹出一个完整的application。

下面介绍具体的方法和步骤:

1)、Message的弹出框用于confirm;

这种最简单,

        APPEND '請確認是否取消!' TO lt_text.

        wd_this->window_cancel = wd_comp_controller->window_manager->create_popup_to_confirm(
            text                 = lt_text
            button_kind          = if_wd_window=>co_buttons_yesno
            message_type         = if_wd_window=>co_msg_type_information
            close_button         = abap_false
            window_title         = 'Confirming'
            default_button       = if_wd_window=>co_button_yes ).
        wd_this->window_cancel->set_remove_on_close( abap_true ).

        wd_this->window_cancel->subscribe_to_button_event(
          button            = if_wd_window=>co_button_yes
          action_name       = 'CANCEL_YES'
          action_view       = wd_this->wd_get_api( )
          button_text       = 'Yes'
          is_default_button = abap_true ).

        wd_this->window_cancel->subscribe_to_button_event(
          button            = if_wd_window=>co_button_no
          action_name       = 'CANCEL_NO'
          action_view       = wd_this->wd_get_api( )
          button_text       = 'No'
          is_default_button = abap_false ).

        wd_this->window_cancel->open( ).

2)、需要自己画控件的window;

将需要展示的控件在view上画出,然后分配一个window,(本个WDA程式内的window)

调用窗口代码:

  IF wd_comp_controller->v_ele_detail_create = 'X'.
    lt_buttons = wd_comp_controller->window_manager->get_buttons_yesno( default_button = if_wd_window=>co_button_yes ).
  ELSE.
    lt_buttons = wd_comp_controller->window_manager->get_buttons_close( ).
  ENDIF.
  ls_canc_action-action_name = '*'.

  lo_window = wd_comp_controller->window_manager->create_and_open_popup(
      window_name          = 'W_ELE'
      title                = 'Modify'
      message_type         = if_wd_window=>co_msg_type_none
      message_display_mode = if_wd_window=>co_msg_display_mode_selected
      is_resizable         = abap_true
      buttons              = lt_buttons
      cancel_action        =  ls_canc_action ).

  lo_window->set_remove_on_close( remove_on_close = abap_true ).
  lo_window->open( ).

被调用窗口:

  DATA: lo_api TYPE REF TO if_wd_view_controller,
        lo_window_ctrl TYPE REF TO if_wd_window_controller,
        lo_window TYPE REF TO if_wd_window.

  lo_api = wd_this->wd_get_api( ).
  lo_window_ctrl = lo_api->get_embedding_window_ctlr( ).
  IF lo_window_ctrl IS BOUND.
    wd_this->vo_window = lo_window_ctrl->get_window( ).
    IF wd_this->vo_window IS BOUND AND wd_comp_controller->v_ele_detail_create = 'X'.
      wd_this->vo_window->subscribe_to_button_event(
        EXPORTING
          button            = if_wd_window=>co_button_yes
          action_name       = 'YES'
          action_view       = lo_api  ).

      wd_this->vo_window->subscribe_to_button_event(
        EXPORTING
          button            = if_wd_window=>co_button_no
          action_name       = 'NO'
          action_view       = lo_api  ).
    ENDIF.

  ENDIF.

如果是调用另一本WDA程式的话:

首先创建一个view,view上面有控件 ViewContainerUIElement,一般我们需要在被调用WDA的componentcontroller中注册一个返回的event,这样方便我们从被调用WDA返回。

首先在调用WDA View触发调用动作,然后call method do_dynamic_navigation,同时需要call 被调用WDA的interface method去初始化界面( 这里也可以去先更新interface node的数据对象,然后在init事件中初始化界面 )。


      lv_tgt_cname = 'YSHWSSS252'.
      IF wd_this->wd_cpuse_yshwsss252( )->has_active_component( ) IS INITIAL.
        wd_this->wd_cpuse_yshwsss252( )->create_component( ).
      ENDIF.
  TRY.
      wd_this->wd_get_api( )->do_dynamic_navigation(
          source_window_name        = 'W_MAIN'
          source_vusage_name        = 'V_2ND_USAGE_1'  " view use
          source_plug_name          = 'OP_TO_2ND'
          target_component_name     = lv_tgt_cname
          target_view_name          = 'W_MAIN'
          target_plug_name          = 'DEFAULT'
          target_embedding_position = 'V_2ND/VCU_MAIN' ).

    CATCH cx_wd_runtime_repository .
      wd_comp_controller->message_manager->report_error_message(
        message_text = '訂單詳情畫面錯誤,請聯繫資訊!' ).
      rv_error = abap_true.
  ENDTRY.
  DATA: LO_WDA252 TYPE REF TO YIWCI_SHWSSS252.
  LO_WDA252 =    WD_THIS->WD_CPIFC_YSHWSSS252( ).
  WD_COMP_CONTROLLER->GS_INTFS-EFORMTYPE = '2'.  "退貨訂單
  LO_WDA252->SET_EFORM_MODE( LS_INTFS = WD_COMP_CONTROLLER->GS_INTFS ).

3)、弹出一个完整的application。

弹出整个application这里其实跟WDA程式已经没有什么关系了,这就是相应URL的超链接。

  CALL METHOD lo_window_manager->create_external_window
    EXPORTING
      url            = lw_url
      modal          = abap_false
      has_menubar    = abap_true
      is_resizable   = abap_true
      has_scrollbars = abap_true
      has_statusbar  = abap_true
      has_toolbar    = abap_true
      has_location   = abap_true
    RECEIVING
      window         = lo_window.

  lo_window->open( ).

 

 类似资料: