WDA学习(21):WDA Popup,Message,Focus
作者:互联网
1.14 WDA Popup,Message,Focus
WDA测试Popup,Message,光标Focus功能。
1.创建Component;
COMPONENTCONTROLLER页签
Context页签:创建Context Node:MESSAGE;
创建Attribute:MSG,类型CHAR1;
创建Attribute:MSG_TYPE,类型String;
Attributes页签:创建Attribute,名称POPUP,类型IF_WD_WINDOW;
Methods页签:创建Method,名称SHOW_MSG;
设置Parameter,名称MSG,类型STRING;
设置Parameter,名称MSG_TYPE,类型CHAR1;
代码实例:
"显示信息 DATA: lo_current_controller TYPE REF TO if_wd_controller, lo_message_manager TYPE REF TO if_wd_message_manager. "获取message manager lo_current_controller ?= wd_this->wd_get_api( ). CALL METHOD lo_current_controller->get_message_manager RECEIVING message_manager = lo_message_manager. "report message IF msg_type = 'S'. CALL METHOD lo_message_manager->report_success EXPORTING message_text = msg. ELSEIF msg_type = 'E'. CALL METHOD lo_message_manager->report_error_message EXPORTING message_text = msg. ELSEIF msg_type = 'I'. CALL METHOD lo_message_manager->report_message EXPORTING message_text = msg. ENDIF.
2.创建Main View,设置Layout;
1.Pop弹窗功能:使用Popup打开Window
使用if_wd_window_manager的create_window创建窗口,window_name这个参数设置自定义的Window;
这种方式需要创建VIEW:V_POP1,Layout只显示一个Message,也可以自定义页面;
然后创建Window Name:W_POP,包含VIEW:V_POP1;
创建LinkToAction组件,名称pop to window,绑定Action:POP_TO_WINDOW;
代码实例:
data:lo_window_manager type ref to if_wd_window_manager. data:lo_api_component type ref to if_wd_component. data:lo_api type ref to if_wd_view_controller. if wd_comp_controller->popup is initial. * create window lo_api_component = wd_comp_controller->wd_get_api( ). lo_window_manager = lo_api_component->get_window_manager( ). wd_comp_controller->popup = lo_window_manager->create_window( window_name = 'W_POP' title = '弹窗1' message_display_mode = if_wd_window=>CO_MSG_DISPLAY_MODE_NONE close_button = abap_true button_kind = if_wd_window=>CO_BUTTONS_YESNO "use constants if_wd_window=>CO_BUTTONS_* message_type = if_wd_window=>CO_MSG_TYPE_QUESTION "use constants if_wd_window=>CO_MSG_TYPE_* default_button = if_wd_window=>CO_BUTTON_YES "use constants if_wd_window=>CO_BUTTON_* close_in_any_case = abap_false ). lo_api = wd_this->wd_get_api( ). * subscribe to YES-Button wd_comp_controller->popup->subscribe_to_button_event( button = if_wd_window=>co_button_yes action_name = 'YES' action_view = lo_api ). * subscribe to NO-Button wd_comp_controller->popup->subscribe_to_button_event( button = if_wd_window=>co_button_no action_name = 'NO' action_view = lo_api ). ENDIF. * open popup wd_comp_controller->popup->open( ).
POP_TO_WINDOW这里注册了YES,NO两个Action,需要在Main View创建Action:YES,NO。设置MSG点击了yes or no;
实例代码ONACTIONYES:
DATA lo_nd_message TYPE REF TO if_wd_context_node. DATA lo_el_message TYPE REF TO if_wd_context_element. DATA ls_message TYPE wd_this->Element_message. DATA lv_msg TYPE wd_this->Element_message-msg. * navigate from <CONTEXT> to <MESSAGE> via lead selection lo_nd_message = wd_context->get_child_node( name = wd_this->wdctx_message ). * get element via lead selection lo_el_message = lo_nd_message->get_element( ). lv_msg = '点击yes'. * set single attribute lo_el_message->set_attribute( name = 'MSG' value = lv_msg ). "关闭弹窗 wd_comp_controller->popup->close( ).
2.Message Manager显示信息功能
创建Button组件,绑定Action: SHOW_MSG;
创建DropDownByKey组件,选择message类型;
代码实例:获取Message类型,调用component controller的show_msg方法;
DATA:lo_nd_message TYPE REF TO if_wd_context_node. DATA:lo_el_message TYPE REF TO if_wd_context_element. DATA:lv_msg_type TYPE wd_this->element_message-msg_type. DATA:lv_msg TYPE string VALUE '显示信息'. "获取信息类型 lo_nd_message = wd_context->get_child_node( name = 'MESSAGE' ). lo_el_message = lo_nd_message->get_element( ). lo_el_message->get_attribute( EXPORTING name = 'MSG_TYPE' IMPORTING value = lv_msg_type ). * report message IF lv_msg_type = 'S'. wd_comp_controller->show_msg( msg = lv_msg msg_type = 'S' ). ELSEIF lv_msg_type = 'E'. wd_comp_controller->show_msg( msg = lv_msg msg_type = 'E' ). ELSEIF lv_msg_type = 'I'. wd_comp_controller->show_msg( msg = lv_msg msg_type = 'I' ). ELSEIF lv_msg_type = 'W'. wd_comp_controller->show_msg( msg = lv_msg msg_type = 'W' ). ENDIF.
创建INIT_DROPDOWN方法;
初始化方法WDDOINIT中调用INIT_DROPDOWN方法;
"设置dropdown 信息类型 DATA:wd_node_info TYPE REF TO if_wd_context_node_info. DATA:wd_node TYPE REF TO if_wd_context_node. DATA value_set TYPE wdr_context_attr_value_list. DATA entry TYPE wdr_context_attr_value. wd_node = wd_context->get_child_node( name = 'MESSAGE' ). *初始化 entry-text = 'S'. entry-value = 'S'. APPEND entry TO value_set. entry-text = 'E'. entry-value = 'E'. APPEND entry TO value_set. entry-text = 'W'. entry-value = 'W'. APPEND entry TO value_set. wd_node_info = wd_node->get_node_info( ). wd_node_info->set_attribute_value_set( name = 'MSG_TYPE' value_set = value_set ).
3.External Window功能
通过URL打开其他WDA Application;
创建LinkToAction组件,open url,绑定Action: OPEN_URL;
创建LinkToAction组件,Open Application Url,绑定Action:OPEN_APPL_URL;
代码实例:ONACTIONOPEN_URL
通过if_wd_window_managet->create_external_window方法,打开新页签URL;
DATA:lo_window_manager TYPE REF TO if_wd_window_manager. DATA:lo_api_component TYPE REF TO if_wd_component. DATA:lo_view_control TYPE REF TO if_wd_view_controller. DATA:lo_window TYPE REF TO if_wd_window. "获取view controller lo_view_control = wd_this->wd_get_api( ). "获取view component lo_api_component = lo_view_control->if_wd_controller~get_component( ). "获取window manager lo_window_manager = lo_api_component->get_window_manager( ). lo_window_manager->create_external_window( EXPORTING url = 'https://www.baidu.com' title = 'open external window' modal = abap_false has_menubar = abap_true "false,弹出新窗口打开网页; is_resizable = abap_false "是否可重设大小 has_scrollbars = abap_false has_statusbar = abap_false has_toolbar = abap_false "false,没有标签,收藏等工具栏 has_location = abap_true "false,没有上一页,下一页,搜寻工具栏 RECEIVING window = lo_window ). "打开window lo_window->open( ).
代码实例:ONACTIONOPEN_APPL_URL
通过cl_wd_utilities=>construct_wd_url,根据component获取对应url;
DATA:lo_window_manager TYPE REF TO if_wd_window_manager. DATA:lo_api_component TYPE REF TO if_wd_component. DATA:lo_window TYPE REF TO if_wd_window. DATA:lv_url TYPE string. "获取application url cl_wd_utilities=>construct_wd_url( EXPORTING application_name = 'Z_TEST_WDA96' IMPORTING out_absolute_url = lv_url ). * "添加parameter * cl_http_server=>if_http_server~append_field_url( * EXPORTING * name = 'param1' * value = 'value1' * CHANGING * url = lv_url * ). "获取 component controller lo_api_component = wd_comp_controller->wd_get_api( ). "获取window manager lo_window_manager = lo_api_component->get_window_manager( ). lo_window_manager->create_external_window( EXPORTING url = lv_url title = 'open external window' modal = abap_false has_menubar = abap_true "false,弹出新窗口打开网页; is_resizable = abap_false "是否可重设大小 has_scrollbars = abap_false has_statusbar = abap_false has_toolbar = abap_false "false,没有标签,收藏等工具栏 has_location = abap_true "false,没有上一页,下一页,搜寻工具栏 RECEIVING window = lo_window ). "打开window lo_window->open( ).
4.Pop弹出功能:使用Popup创建弹窗
点击按钮打开弹窗;
创建LinkToAction组件,绑定Action:POP_TO_CONFIRM;
代码实例:ONACTIONPOP_TO_CONFIRM
使用if_wd_window_manager->create_popup_to_confirm方法创建一个confirm弹窗;
DATA:lo_window_manager TYPE REF TO if_wd_window_manager. DATA:lo_api_component TYPE REF TO if_wd_component. DATA:lo_view_controller TYPE REF TO if_wd_view_controller. DATA:lo_window TYPE REF TO if_wd_window. DATA:lv_string TYPE string. DATA:lt_string TYPE TABLE OF string. "获取当前视图controller lo_view_controller = wd_this->wd_get_api( ). lo_api_component = lo_view_controller->if_wd_controller~get_component( ). lo_window_manager = lo_api_component->get_window_manager( ). lv_string = 'This is Pop up to Confirm'. APPEND lv_string TO lt_string. lv_string = 'This is Pop up to Confirm'. APPEND lv_string TO lt_string. lo_window_manager->create_popup_to_confirm( EXPORTING text = lt_string button_kind = if_wd_window=>co_buttons_yesno message_type = if_wd_window=>co_msg_type_information close_button = abap_true "关闭按钮 window_title = 'Pop up confirm' window_left_position = 100 window_top_position = 200 window_position = if_wd_window=>co_center window_width = '200px' window_height = '400px' default_button = if_wd_window=>co_button_yes RECEIVING result = lo_window ). lo_window->subscribe_to_button_event( EXPORTING tooltip = 'yes' button_text = 'button yes' button = if_wd_window=>co_button_yes action_name = 'HDL_YES' action_view = lo_view_controller ). lo_window->subscribe_to_button_event( EXPORTING tooltip = 'no' button_text = 'button no' button = if_wd_window=>co_button_no action_name = 'HDL_NO' action_view = lo_view_controller ). "设置任何action发生后关闭 lo_window->set_close_in_any_case( abap_true ). "打开pop lo_window->open( ). "直接调用关闭 "lo_window->close( ).
代码实例:ONACTIONHDL_YES,处理YES点击事件;
wd_comp_controller->show_msg( msg = 'yes' msg_type = 'S' ).
代码实例:ONACTIONHDL_NO,处理NO点击事件;
wd_comp_controller->show_msg( msg = 'no' msg_type = 'S' ).
5.UI Element Focus功能
设置UI Element鼠标Focus;
MAIN View的初始化方法WDDOINIT方法调用INIT_INPFOCUS方法;
创建INIT_INPFOCUS方法;
代码实例:
通过if_wd_view_controller->request_focus方法,设置focus;
DATA:lo_node TYPE REF TO if_wd_context_node. DATA:lo_element TYPE REF TO if_wd_context_element. DATA:ls_inp TYPE wd_this->element_node_inp. DATA:lo_view_controll TYPE REF TO if_wd_view_controller. lo_view_controll = wd_this->wd_get_api( ). lo_node = wd_context->get_child_node( wd_this->wdctx_node_inp ). lo_element = lo_node->get_element( ). ls_inp-inp1 = 'hello'. ls_inp-inp2 = 'world'. "设置值 lo_element->set_static_attributes( EXPORTING static_attributes = ls_inp ). "设置Focus lo_view_controll->request_focus( EXPORTING context_element = lo_element attribute = 'INP2' ).
标签:WDA,Popup,21,lo,window,wd,msg,message,TYPE 来源: https://www.cnblogs.com/tangToms/p/16581981.html