捕获扩展节点事件(ABAP)

时间:2014-03-20 07:25:53

标签: tree treeview abap

我使用类* cl_salv_tree *创建了一个alv树视图。一切正常但我想在扩展节点时抓取事件,以填充自动调整树列大小的函数。我的问题是,扩展事件是类* CL_GUI_ALV_TREE *的私有方法* HANDLE_EXPAND_NC *,我实际上不知道如何捕获此事件。我愿意接受任何想法并感谢你的时间。

亲切的问候

塞巴斯蒂安

2 个答案:

答案 0 :(得分:1)

据我所知,只有在展开了尚未包含子项的文件夹时才会通知您(方法/事件名称的_NC部分表示)。这是为了延迟加载树。 SAP菜单中显示的树或IMG就是一个很好的例子 - 当您展开顶级节点时,您实际上可以看到正在加载树的部分。

如果这对您来说已足够,请使用由EXPAND_EMPTY_FOLDER实施的界面IF_SALV_EVENTS_TREE的事件CL_SALV_EVENTS_TREE。虽然似乎没有一个很好的演示程序。

答案 1 :(得分:0)

这是一个最小的可重现示例,它显示了当展开最初没有子节点的节点时触发事件EXPAND_EMPTY_FOLDER,并在该事件期间添加了子节点:

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    METHODS pbo
      RAISING
        cx_salv_error.
  PRIVATE SECTION.
    DATA: salv   TYPE REF TO cl_salv_tree,
          scarrs TYPE STANDARD TABLE OF scarr.
    METHODS on_expand_empty_folder
      FOR EVENT expand_empty_folder
                  OF cl_salv_events_tree
      IMPORTING node_key.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
  METHOD pbo.
    IF salv IS NOT BOUND.
      cl_salv_tree=>factory( EXPORTING r_container = cl_gui_container=>screen0
                             IMPORTING r_salv_tree = salv
                             CHANGING  t_table     = scarrs ).
      DATA(lo_settings) = salv->get_tree_settings( ).
      lo_settings->set_hierarchy_size( 30 ).
      DATA(event) = salv->get_event( ).
      salv->get_functions( )->add_function( name = 'NEW' text = 'NEW' tooltip = '' position = 1 ).
      SET HANDLER on_expand_empty_folder FOR event.
      SELECT * FROM scarr INTO TABLE @DATA(local_scarrs).
      LOOP AT local_scarrs REFERENCE INTO DATA(scarr).
        salv->get_nodes( )->add_node(
          related_node = space " (root node)
          relationship = cl_gui_column_tree=>relat_last_child
          text         = |{ scarr->carrid } - { scarr->carrname }|
          data_row     = scarr->*
          folder       = abap_true
          expander     = abap_true ).
      ENDLOOP.
      salv->display( ).
    ENDIF.
    LOOP AT SCREEN.
      screen-active = '0'.
      MODIFY SCREEN.
    ENDLOOP.
  ENDMETHOD.
  METHOD on_expand_empty_folder.
    TRY.
        DATA(scarr) = CAST scarr( salv->get_nodes( )->get_node( node_key )->get_data_row( ) )->*.
        salv->get_nodes( )->add_node(
          related_node = node_key
          relationship = cl_gui_column_tree=>relat_last_child
          text         = |Node added at time of expand below { scarr-carrid }| ).
      CATCH cx_root INTO DATA(lx).
        MESSAGE lx TYPE 'I' DISPLAY LIKE 'E'.
        LEAVE PROGRAM.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

PARAMETERS dummy.

LOAD-OF-PROGRAM.
  DATA(app) = NEW lcl_app( ).

AT SELECTION-SCREEN OUTPUT.
  TRY.
      app->pbo( ).
    CATCH cx_root INTO DATA(lx).
      MESSAGE lx TYPE 'S' DISPLAY LIKE 'E'.
  ENDTRY.