gpt4 book ai didi

event-handling - ABAP:CL_SIMPLE_TREE_MODEL 的事件 CONTEXT_MENU_SELECT - 无法触发它

转载 作者:行者123 更新时间:2023-12-04 04:29:14 25 4
gpt4 key购买 nike

我有一个 CL_SIMPLE_TREE_MODEL 实例,我设法触发并处理了 CONTEXT_MENU_REQUEST 事件,然后构建了我的上下文菜单。

我按照我想要的方式添加了我的函数。

问题是,当我从上下文菜单中选择一个选项时,没有任何反应。换句话说,程序流不会进入 CONTEXT_MENU_SELECT 的处理程序。

我当然假设当我点击上下文菜单中的功能时会触发此事件。

我找到了官方文档,但仅针对您使用 Shift+F10 访问的“默认上下文菜单”,它需要程序中的某些子例程才能触发。

我做了什么:

  1. 我确实定义并实现了一个方法,该方法是该事件的处理程序。
  2. 我确实在为 CONTEXT_MENU_REQUEST 事件设置处理程序的同一位置设置了事件处理程序
  3. 我没有使用 SET_REGISTERED_EVENTS 注册事件,因为在该事件的类属性中没有定义 ID - 例如 CONTEXT_MENU_REQUEST 事件。

代码:

REPORT.

CLASS lcl_tree_handler DEFINITION.

PUBLIC SECTION.
METHODS:
pbo,
on_ctx_menu_request FOR EVENT node_context_menu_request OF cl_simple_tree_model
IMPORTING node_key menu sender, "TYPE TM_NODEKEY CL_CTMENU
on_ctx_menu_select FOR EVENT node_context_menu_select OF cl_simple_tree_model
IMPORTING node_key fcode. "TYPE TM_NODEKEY SY-UCOMM
DATA:
po_tree_model TYPE REF TO cl_simple_tree_model,
gt_tree TYPE TABLE OF treemsnodt,
control TYPE REF TO cl_gui_control.
ENDCLASS.

CLASS lcl_tree_handler IMPLEMENTATION.

METHOD pbo.
DATA: lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
FIELD-SYMBOLS <gs_tree> TYPE treemsnodt.

CHECK po_tree_model IS NOT BOUND.

CREATE OBJECT po_tree_model
EXPORTING
node_selection_mode = po_tree_model->node_sel_mode_single.

APPEND INITIAL LINE TO gt_tree ASSIGNING <gs_tree>.
<gs_tree>-node_key = 'Node key 1'.
<gs_tree>-text = 'First node'.
<gs_tree>-isfolder = 'X'.
APPEND INITIAL LINE TO gt_tree ASSIGNING <gs_tree>.
<gs_tree>-node_key = 'Node key 2'.
<gs_tree>-relatkey = 'Node key 1'.
<gs_tree>-relatship = cl_tree_model=>relat_last_child.
<gs_tree>-text = 'First child'.
po_tree_model->add_nodes(
node_table = gt_tree ).

ls_event-eventid = cl_simple_tree_model=>eventid_node_context_menu_req.
ls_event-appl_event = 'X'. "tried with space too
APPEND ls_event TO lt_events.

CALL METHOD po_tree_model->set_registered_events
EXPORTING
events = lt_events.

SET HANDLER on_ctx_menu_request FOR po_tree_model.
SET HANDLER on_ctx_menu_select FOR po_tree_model.

po_tree_model->create_tree_control(
EXPORTING
parent = cl_gui_container=>screen0
IMPORTING
control = control ).

ENDMETHOD.

METHOD on_ctx_menu_request. "I initialize the context menu object here.
DATA: lt_chidren_keys TYPE treemnotab,
ls_child_key TYPE tm_nodekey,
lv_text TYPE gui_text.

CALL METHOD sender->node_get_children
EXPORTING
node_key = node_key
IMPORTING
node_key_table = lt_chidren_keys
EXCEPTIONS
OTHERS = 2.

LOOP AT lt_chidren_keys INTO ls_child_key.
lv_text = ls_child_key.
CALL METHOD menu->add_function
EXPORTING
fcode = 'ONE'
text = lv_text
ftype = 'B'.
ENDLOOP.

menu->add_separator( ).
CALL METHOD menu->add_function
EXPORTING
fcode = 'ALL'
text = 'All the work groups'
ftype = 'W'.

ENDMETHOD.

METHOD on_ctx_menu_select.
BREAK-POINT. "tried actual code here too.
ENDMETHOD.

ENDCLASS.


DATA: go_tree_handler TYPE REF TO lcl_tree_handler.

PARAMETERS dummy.

INITIALIZATION.
CREATE OBJECT go_tree_handler.

AT SELECTION-SCREEN OUTPUT.
go_tree_handler->pbo( ).

AT SELECTION-SCREEN ON EXIT-COMMAND.
go_tree_handler->control->free( ).

显示树,右键单击上下文菜单出现。

但是当我选择一个菜单项时没有任何反应。我错过了什么吗?

最佳答案

不支持您指定的函数类型(ftype = 'W''B')(检查底层域 CUA_FUNTYP< 的固定值)。在那种情况下,什么也不会发生。

经典的解决方案是使用ftype = ' '(普通函数):

    LOOP AT lt_chidren_keys INTO ls_child_key.
lv_text = ls_child_key.
CALL METHOD menu->add_function
EXPORTING
fcode = 'ONE'
text = lv_text
ftype = ' '.
ENDLOOP.

menu->add_separator( ).
CALL METHOD menu->add_function
EXPORTING
fcode = 'ALL'
text = 'All the work groups'
ftype = ' '.

可能的 ftype 值是(来源:域 CUA_FUNTYP):

  • ' ' : 正常功能
  • 'H':帮助功能(处理帮助请求)
  • 'S':系统函数(由 DYNP 直接处理)
  • 'T':交易调用(LEAVE TO TRANSACTION)
  • “E”:访问“AT EXIT COMMAND”模块 ->/E 作为前缀
  • 'I':包括菜单(在运行时替换 - 不支持)
  • 'N' : 'AT EXIT COMMAND' 功能,> DYNP >/N 作为前缀

备注:第一版题中的代码缺少第二个事件处理器的注册SET HANDLER go_tree_handler->on_ctx_menu_select FOR po_tree_model.(现在可以了)

关于event-handling - ABAP:CL_SIMPLE_TREE_MODEL 的事件 CONTEXT_MENU_SELECT - 无法触发它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13254719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com