WDA演練二:主界面設計(一)

 

 

前面已經完成了登錄界面的開發,下面就是主頁面的展現了。node

1、新建菜單表:api

這裏說明一下,考慮到簡單點,這裏只用了兩級菜單展現,表裏在配置的時候也指揮有一級,二級。ui

AUGRP對應前面用戶表的GROUPthis

ZLEVEL對應層級,最多2級。spa

INX是層級對應的序號。翻譯

ID爲WDA程序名稱。設計

LANGU爲語言,這裏能夠作多語言翻譯,顯示不一樣語言下的菜單。3d

TEXT爲菜單顯示的名字。code

SUB_LEVEL爲上級菜單對應的序號。component

INTERFACE_WINDOW是調用的顯示主窗口。

 

2、程序設計:

1.將全局節點拖到MAIN視圖中。

2.新建NODE節點,對應菜單樹。

3.NODE下新建LEAF節點,對應樹葉,菜單:

4.新建NODE的屬性:除了EXPAND是WDA_BOOLEAN類型,其餘均爲STRING類型。

5.新建LEAF屬性:

 

 3、主頁菜單設計:

1.按一般顯示來,擡頭是標題或者圖片LOGO,上傳擡頭LOGO

2.接着前面的來,添加擡頭圖片到視圖:

3.新建SPLITTER,將頁面分爲左右兩部分。

4.給SPLITTER添加菜單控制器和右邊的顯示容器:

5.右側添加視圖控制器:

6.左側加TREE:

7.將TREE綁定到前面建的節點NODE上:

8.添加樹節點:

 

9.添加樹葉節點:

10.節點綁定:

 

 3、初始化看看效果:

METHOD init_menu .
**-------------------------------------------------------------------------
**                          初始化菜單項
**
**        一級菜單               二級菜單
**
*
**-------------------------------------------------------------------------
  DATA lo_nd_node TYPE REF TO if_wd_context_node.
  DATA lo_nd_leaf TYPE REF TO if_wd_context_node.
  DATA lo_el_leaf TYPE REF TO if_wd_context_element.
  DATA ls_leaf TYPE wd_this->element_leaf.
  DATA lt_leaf TYPE wd_this->elements_leaf.
  DATA lo_el_node TYPE REF TO if_wd_context_element.
  DATA ls_node TYPE wd_this->element_node.
  DATA lt_node TYPE wd_this->elements_node.
  DATA l_menuid TYPE i.
*  DATA lt_auth  TYPE TABLE OF zauth.
*  DATA ls_auth  TYPE zauth.

  lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).
  lo_nd_node->bind_table( lt_node )."清空節點

  DATA: lt_fir_level TYPE TABLE OF zlymenu,
        ls_fir_level TYPE zlymenu.

  DATA: lt_sec_level TYPE TABLE OF zlymenu,
        ls_sec_level TYPE zlymenu.
  DATA: lv_char TYPE string.

  SELECT * INTO TABLE lt_fir_level FROM zlymenu WHERE augrp = augrp AND zlevel IN (0,1)
    AND langu = sy-langu.

  SORT lt_fir_level BY inx.

  IF lt_fir_level IS NOT INITIAL.
    SELECT * INTO TABLE lt_sec_level FROM zlymenu
      FOR ALL ENTRIES IN lt_fir_level
      WHERE sub_level = lt_fir_level-inx  AND augrp = augrp AND zlevel = 2
      AND langu = sy-langu.
    SORT lt_sec_level BY sub_level inx.
    LOOP AT lt_fir_level INTO ls_fir_level.
      CLEAR:lt_leaf.
      LOOP AT lt_sec_level INTO ls_sec_level WHERE sub_level = ls_fir_level-inx.
        ls_leaf-leafid = ls_sec_level-id.
        ls_leaf-leafname = ls_sec_level-text.
        ls_leaf-interface_window = ls_sec_level-interface_window.
        APPEND ls_leaf TO lt_leaf.
      ENDLOOP.
      "IF lt_leaf IS NOT INITIAL.
      lv_char = ls_fir_level-inx.
      CONCATENATE 'S' lv_char INTO ls_node-nodeid.
      ls_node-nodename = ls_fir_level-text.
      ls_node-expand = 'X'.
      ls_node-icon_source = 'ICON_OBJECT_FOLDER'.
      l_menuid = l_menuid + 1.
      CALL METHOD lo_nd_node->bind_element
        EXPORTING
          new_item             = ls_node
          set_initial_elements = abap_false
          index                = l_menuid
        RECEIVING
          element              = lo_el_node.
      lo_nd_leaf = lo_el_node->get_child_node( wd_this->wdctx_leaf ).
      lo_nd_leaf->bind_table( lt_leaf ).
      REFRESH lt_leaf.
      "ENDIF.
    ENDLOOP.
  ENDIF.


ENDMETHOD.

將上面的方法在處理LOGON跳轉裏調用:

METHOD handlefromlogon .
  DATA lo_nd_zhis_user TYPE REF TO if_wd_context_node.
  DATA lo_el_zhis_user TYPE REF TO if_wd_context_element.
  DATA ls_zhis_user TYPE wd_this->element_zhis_user.

*   navigate from <CONTEXT> to <ZHIS_USER> via lead selection
  lo_nd_zhis_user = wd_context->get_child_node( name = wd_this->wdctx_zhis_user ).
  lo_el_zhis_user = lo_nd_zhis_user->get_element( ).
*   @TODO handle not set lead selection
  IF lo_el_zhis_user IS INITIAL.
    EXIT.
  ENDIF.

  lo_el_zhis_user->get_static_attributes(
    IMPORTING
      static_attributes = ls_zhis_user ).

  wd_this->init_menu( ls_zhis_user-augrp ).


ENDMETHOD.

添加事件處理邏輯:

METHOD onactionselect_item .
  DATA ls_leaf  TYPE wd_this->element_leaf.
  DATA ls_zlymenu TYPE zlymenu.

  DATA lo_nd_zhis_user TYPE REF TO if_wd_context_node.

  DATA lo_el_zhis_user TYPE REF TO if_wd_context_element.
  DATA ls_zhis_user TYPE wd_this->element_zhis_user.
  DATA lv_augrp TYPE wd_this->element_zhis_user-augrp.

* navigate from <CONTEXT> to <ZHIS_USER> via lead selection
  lo_nd_zhis_user = wd_context->get_child_node( name = wd_this->wdctx_zhis_user ).

* @TODO handle non existant child
* IF lo_nd_zhis_user IS INITIAL.
* ENDIF.

* get element via lead selection
  lo_el_zhis_user = lo_nd_zhis_user->get_element( ).
* @TODO handle not set lead selection
  IF lo_el_zhis_user IS INITIAL.
  ENDIF.

* get single attribute
  lo_el_zhis_user->get_attribute(
    EXPORTING
      name =  `AUGRP`
    IMPORTING
      value = lv_augrp ).


  IF context_element IS INITIAL.

    IF wd_this->iv_context_element IS NOT INITIAL.
      wd_this->iv_context_element->get_static_attributes(
       IMPORTING
         static_attributes = ls_leaf ).
    ENDIF.

    IF ls_leaf IS INITIAL.
      SELECT SINGLE * INTO ls_zlymenu FROM zlymenu
        WHERE augrp = lv_augrp
        AND zlevel = 2
        AND sub_level = 0
        AND langu = sy-langu.
      IF sy-subrc EQ 0.
        ls_leaf-leafid = ls_zlymenu-id.
        ls_leaf-leafname = ls_zlymenu-text.
        ls_leaf-interface_window = ls_zlymenu-interface_window.
      ELSE.
        EXIT.
      ENDIF.

    ENDIF.

  ELSE.

    context_element->get_static_attributes(
      IMPORTING
        static_attributes = ls_leaf ).

  ENDIF.

* 獲得window名稱
  DATA l_current_controller TYPE REF TO if_wd_controller.
  DATA l_message_manager    TYPE REF TO if_wd_message_manager.
  DATA lr_view_controller   TYPE REF TO if_wd_view_controller.
  DATA lr_window_controller TYPE REF TO if_wd_window_controller.
  DATA lv_window_name       TYPE string.
*
  l_current_controller ?= wd_this->wd_get_api( ).
  l_message_manager = l_current_controller->get_message_manager( ).

  lr_view_controller = wd_this->wd_get_api( ).
  lr_window_controller = lr_view_controller->get_embedding_window_ctlr( ).
  lv_window_name = lr_window_controller->if_wd_controller~name.
*
  DATA lv_vusage_name TYPE string.
  lv_vusage_name = 'MAIN_USAGE_0'.

  DATA ls_component_usages TYPE wdapi_component_usage.
  DATA l_view  TYPE string.

  DATA l_view_controller TYPE REF TO if_wd_view_controller.
  DATA l_view_name TYPE string.
  DATA: s_plug_name TYPE string.


*  ls_component_usages-component_usage_name = ls_leaf-leafid."aaaa
  ls_component_usages-embedding_position = 'MAIN/RIGHT'.

  DATA: l_view_controller_api TYPE REF TO if_wd_view_controller.
  l_view_controller_api = wd_this->wd_get_api( ).

  IF wd_this->component_usage IS NOT INITIAL.
    IF wd_this->component_usage-component_usage->has_active_component( ) IS NOT INITIAL.
      wd_this->component_usage-component_usage->delete_component(  ).
      CALL METHOD l_view_controller_api->remove_dynamic_meta_data
        EXPORTING
          source_window_name        = lv_window_name
          source_vusage_name        = lv_vusage_name
*         source_plug_name          = s_plug_name
          source_plug_name          = 'TO_WDA'
          target_component_name     = wd_this->component_usage-used_component
          target_component_usage    = wd_this->component_usage-component_usage_name
          target_view_name          = wd_this->old_view
          target_plug_name          = 'DEFAULT'
          target_embedding_position = wd_this->component_usage-embedding_position.
    ENDIF.
  ENDIF.


  TRY.
      l_view_name = ls_leaf-interface_window.
      lv_window_name = 'ZLY_PORTAL'.
      ls_component_usages-used_component = ls_leaf-leafid.
      ls_component_usages-component_usage_name = ls_leaf-leafid.
      ls_component_usages-component_usage = l_view_controller_api->prepare_dynamic_navigation(
                  source_window_name          = lv_window_name
                  source_vusage_name          = lv_vusage_name
                  source_plug_name            = 'TO_WDA'
                  target_component_name       = ls_component_usages-used_component
                  target_component_usage      = ls_component_usages-component_usage_name
                  target_view_name            = l_view_name
                  target_plug_name            = 'DEFAULT'
                  target_embedding_position   = ls_component_usages-embedding_position ).

    CATCH cx_wd_runtime_repository.
      RAISE EXCEPTION TYPE cx_wdr_rt_exception.
      EXIT.
  ENDTRY.


  DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

  IF ls_component_usages-component_usage->has_active_component( ) IS NOT INITIAL.
    ls_component_usages-component_usage->delete_component(  ).
  ENDIF.
  ls_component_usages-component_usage->create_component( ls_component_usages-used_component ).
  wd_this->component_usage = ls_component_usages.
  wd_this->old_view = l_view_name.

*-------------------------->綁interface結點<----------------------

  DATA l_intf_controller     TYPE REF TO ziwci_crm_interface.
  DATA l_wd_controller       TYPE REF TO if_wd_controller.
  DATA l_wd_context          TYPE REF TO if_wd_context.
  DATA l_wd_context_node     TYPE REF TO if_wd_context_node.


  wd_this->fire_to_WDA_plg( ).

  CLEAR ls_component_usages.




ENDMETHOD.

樹葉節點綁定事件:

METHOD onactionselect_item2 .
  DATA lo_nd_leaf TYPE REF TO if_wd_context_node.
  DATA lo_el_leaf TYPE REF TO if_wd_context_element.
  DATA ls_leaf TYPE wd_this->element_leaf.


  wd_this->iv_context_element = context_element.

  context_element->get_static_attributes(
    IMPORTING
      static_attributes = ls_leaf ).


  DATA zwdevent TYPE REF TO cl_wd_custom_event.

  wd_this->onactionselect_item(
    context_element =  context_element                 " ref to if_wd_context_element
    wdevent = zwdevent                          " ref to cl_wd_custom_event
  ).

ENDMETHOD.

 

效果如圖:

程序裏默認選擇了主頁面。取消效果以下:

到此結束。

相關文章
相關標籤/搜索