zoukankan      html  css  js  c++  java
  • ABAP Control Framework(9): Tree

    9.Tree

    Simple Tree:使用cl_gui_simple_tree类创建只有单个节点Tree;

     

     List Tree:使用cl_gui_list_tree类创建每个节点有多个entry,从左到右;

     

     Column Tree:cl_gui_column_tree类自定义拥有多列的节点;

     

               示例:SAPSIMPLE_TREE_CONTROL_DEMO;

              示例:SAPTLIST_TREE_CONTROL_DEMO;

              示例:SAPCOLUMN_TREE_CONTROL_DEMO;

              示例:SAPSIMPLE_TREE_DRAG_DROP_DEMO;

           示例:RSDEMO_DRAG_DROP_TREE_MULTI;

    示例1:cl_gui_simple_tree

    CLASS c8_event_handler DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA:gv_string TYPE string.
        CLASS-METHODS:m_node_double_click FOR EVENT node_double_click OF cl_gui_simple_tree
          IMPORTING node_key.
        CLASS-METHODS:m_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree
          IMPORTING node_key sender.
    ENDCLASS.
    CLASS c8_event_handler IMPLEMENTATION.
      METHOD:m_node_double_click.
        gv_string = 'node double click node key:' && node_key.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_expand_no_children.
        DATA:lt_node TYPE TABLE OF mtreesnode.
        DATA:ls_node LIKE LINE OF lt_node.
        IF node_key = 'Item1'.
          "添加节点
          CLEAR ls_node.
          ls_node-node_key = 'New1'.
          ls_node-relatkey = 'Item1'.
          ls_node-relatship = cl_gui_column_tree=>relat_last_child.
          ls_node-n_image = '@FO@'.
          ls_node-exp_image = '@W5@'.
          ls_node-text = 'Node New1'.
          APPEND ls_node TO lt_node.
          CLEAR ls_node.
          ls_node-node_key = 'New2'.
          ls_node-relatkey = 'Item1'.
          ls_node-relatship = cl_gui_column_tree=>relat_last_child.
          ls_node-n_image = '@FO@'.
          ls_node-exp_image = '@W5@'.
          ls_node-text = 'Node New2'.
          APPEND ls_node TO lt_node.
    
          sender->add_nodes(
            EXPORTING
              node_table = lt_node
              table_structure_name = 'MTREESNODE'
          ).
        ENDIF.
        gv_string = 'expand no children node key:' && node_key.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
    ENDCLASS.
    
    CLASS c8_simple_tree DEFINITION.
      PUBLIC SECTION.
        DATA:lo_simple_tree TYPE REF TO cl_gui_simple_tree.
        METHODS:m_init_tree.
        "创建节点
        METHODS:m_creat_node.
        "注册事件
        METHODS:m_regist_event.
    ENDCLASS.
    CLASS c8_simple_tree IMPLEMENTATION.
      METHOD:m_init_tree.
        "创建tree
        CREATE OBJECT lo_simple_tree
          EXPORTING
            parent = cl_gui_container=>default_screen
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single.
        "创建node
        me->m_creat_node( ).
        "注册事件
        me->m_regist_event( ).
      ENDMETHOD.
      METHOD m_creat_node.
        DATA:lt_node TYPE TABLE OF mtreesnode.
        DATA:ls_node LIKE LINE OF lt_node.
        "添加节点
        ls_node-node_key = 'Root'.
        ls_node-isfolder = 'X'.
        ls_node-n_image = '@FO@'.
        ls_node-exp_image = '@W5@'.
        ls_node-hidden = ''.
        ls_node-disabled = ''.
        ls_node-text = 'Root Node'.
        APPEND ls_node TO lt_node.
        CLEAR ls_node.
        ls_node-node_key = 'Item1'.
        ls_node-relatkey = 'Root'.
        ls_node-relatship = cl_gui_column_tree=>relat_last_child.
        ls_node-isfolder = 'X'.
        ls_node-expander = 'X'.
        ls_node-n_image = '@FO@'.
        ls_node-exp_image = '@W5@'.
        ls_node-text = 'Item1 Node'.
        APPEND ls_node TO lt_node.
    
        lo_simple_tree->add_nodes(
          EXPORTING
            node_table = lt_node
            table_structure_name = 'MTREESNODE'
        ).
      ENDMETHOD.
      METHOD m_regist_event.
        DATA:lt_events TYPE cntl_simple_events.
        DATA:ls_events TYPE cntl_simple_event.
        ls_events-eventid = cl_gui_column_tree=>eventid_node_double_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_expand_no_children.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        "设置事件
        lo_simple_tree->set_registered_events(
          events = lt_events
        ).
        SET HANDLER c8_event_handler=>m_node_double_click FOR lo_simple_tree.
        SET HANDLER c8_event_handler=>m_expand_no_children FOR lo_simple_tree.
      ENDMETHOD.
    ENDCLASS.

    示例2:cl_gui_list_tree

    CLASS c8_event_handler DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA:gv_string TYPE string.
        CLASS-METHODS:m_node_double_click FOR EVENT node_double_click OF cl_gui_list_tree
          IMPORTING node_key.
        CLASS-METHODS:m_header_click FOR EVENT header_click OF cl_gui_list_tree
          IMPORTING header_name.
        CLASS-METHODS:m_expand_no_children FOR EVENT expand_no_children OF cl_gui_list_tree
          IMPORTING node_key sender.
        CLASS-METHODS:m_item_double_click FOR EVENT item_double_click OF cl_gui_list_tree
          IMPORTING node_key item_name.
        CLASS-METHODS:m_button_click FOR EVENT button_click OF cl_gui_list_tree
          IMPORTING node_key item_name.
        CLASS-METHODS:m_link_click FOR EVENT link_click OF cl_gui_list_tree
          IMPORTING node_key item_name.
        CLASS-METHODS:m_checkbox_change FOR EVENT checkbox_change OF cl_gui_list_tree
          IMPORTING node_key item_name checked.
    ENDCLASS.
    CLASS c8_event_handler IMPLEMENTATION.
      METHOD:m_node_double_click.
        gv_string = 'node double click node key:' && node_key.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_header_click.
        gv_string = 'header name:' && header_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_expand_no_children.
        DATA:lt_node TYPE treev_ntab.
        DATA:ls_node TYPE treev_node.
        DATA:lt_item TYPE TABLE OF mtreeitm.
        DATA:ls_item TYPE mtreeitm.
        IF node_key = 'Item2'.
          DO 2 TIMES.
            "Item2添加New21,New22子节点
            CLEAR ls_node.
            ls_node-node_key = 'New2' && sy-index.
            ls_node-relatkey = 'Item2'.
            ls_node-relatship = cl_gui_list_tree=>relat_last_child.
            APPEND ls_node TO lt_node.
    
            "设置new2的text
            CLEAR ls_item.
            ls_item-node_key = 'New2' && sy-index.
            ls_item-item_name = sy-index.
            "item种类
            ls_item-class = cl_gui_list_tree=>item_class_text.
            "字体ITEM_FONT_DEFAULT,ITEM_FONT_FIXED,ITEM_FONT_PROP
            ls_item-font = cl_gui_list_tree=>item_font_prop.
            "align_xxx,left,auto,right,center
            ls_item-alignment = cl_gui_list_tree=>align_left.
            ls_item-t_image = '@B1@'."图标
            ls_item-length = 5. "长度
            ls_item-usebgcolor = 'X'."是否使用bgcolor
            ls_item-text = 'text' && sy-index.
            APPEND ls_item TO lt_item.
    
            "设置new2的text
            CLEAR ls_item.
            ls_item-node_key = 'New2' && sy-index.
            ls_item-item_name = sy-index + 1.
            "item种类
            ls_item-class = cl_gui_list_tree=>item_class_text.
            "align_xxx,left,auto,right,center
            ls_item-alignment = cl_gui_list_tree=>align_left.
            ls_item-t_image = '@B1@'."图标
            ls_item-length = 5. "长度
            ls_item-usebgcolor = 'X'."是否使用bgcolor
            ls_item-text = 'text' && sy-index.
            APPEND ls_item TO lt_item.
          ENDDO.
          sender->add_nodes_and_items(
          EXPORTING
            node_table = lt_node
            item_table = lt_item
            item_table_structure_name = 'MTREEITM'
        ).
        ENDIF.
        gv_string = 'expand no children node key:' && node_key.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_item_double_click.
        gv_string = 'item double click node key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_button_click.
        gv_string = 'butto click key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_link_click.
        gv_string = 'link click node key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_checkbox_change.
        gv_string = 'checkbox change node key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
    ENDCLASS.
    
    CLASS c8_list_tree DEFINITION.
      PUBLIC SECTION.
        DATA:lo_list_tree TYPE REF TO cl_gui_list_tree.
        METHODS:m_init_tree.
        METHODS:m_creat_node.
        METHODS:m_regist_event.
    ENDCLASS.
    CLASS c8_list_tree IMPLEMENTATION.
      METHOD:m_init_tree.
        "创建tree
        CREATE OBJECT lo_list_tree
          EXPORTING
            parent = cl_gui_container=>default_screen
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection = 'X'
            with_headers = ''.
        "创建node
        me->m_creat_node( ).
        "注册事件
        me->m_regist_event( ).
      ENDMETHOD.
      METHOD m_creat_node.
        DATA:lt_node TYPE treev_ntab.
        DATA:ls_node TYPE treev_node.
        DATA:lt_item TYPE TABLE OF mtreeitm.
        DATA:ls_item TYPE mtreeitm.
        "添加根节点
        ls_node-node_key = 'Root'.
        ls_node-isfolder = 'X'.
        ls_node-n_image = '@FO@'.
        ls_node-exp_image = '@W5@'.
        ls_node-hidden = ''.
        ls_node-disabled = ''.
        APPEND ls_node TO lt_node.
        DO 2 TIMES.
          "Root添加Item1,2子节点
          CLEAR ls_node.
          ls_node-node_key = 'Item' && sy-index.
          ls_node-relatkey = 'Root'.
          ls_node-relatship = cl_gui_list_tree=>relat_last_child.
          ls_node-isfolder = 'X'.
          ls_node-expander = 'X'.
          ls_node-n_image = '@FO@'.
          ls_node-exp_image = '@W5@'.
          APPEND ls_node TO lt_node.
    
          "Item1添加New1,New2子节点
          CLEAR ls_node.
          ls_node-node_key = 'New' && sy-index.
          ls_node-relatkey = 'Item1'.
          ls_node-relatship = cl_gui_list_tree=>relat_last_child.
          APPEND ls_node TO lt_node.
        ENDDO.
    
        "设置root text
        ls_item-node_key = 'Root'.
        ls_item-item_name = '1'.
        ls_item-class = cl_gui_list_tree=>item_class_text.
        ls_item-length = 10. "长度
        ls_item-text = 'Root text'.
        APPEND ls_item TO lt_item.
        DO 2 TIMES.
          "设置Item1,2的text
          CLEAR ls_item.
          ls_item-node_key = 'Item' && sy-index.
          ls_item-item_name = '1'.
          ls_item-class = cl_gui_list_tree=>item_class_text.
          ls_item-length = 10. "长度
          ls_item-text = ls_item-node_key && ' text'.
          APPEND ls_item TO lt_item.
        ENDDO.
        DO 2 TIMES.
          "设置new1的text
          CLEAR ls_item.
          ls_item-node_key = 'New' && sy-index.
          ls_item-item_name = '1'.
          "item种类
          ls_item-class = cl_gui_list_tree=>item_class_text.
          "字体ITEM_FONT_DEFAULT,ITEM_FONT_FIXED,ITEM_FONT_PROP
          ls_item-font = cl_gui_list_tree=>item_font_prop.
          ls_item-disabled = ''."是否可用
          ls_item-editable = ''."是否可编辑
          ls_item-hidden = ''. "是否隐藏
          "align_xxx,left,auto,right,center
          ls_item-alignment = cl_gui_list_tree=>align_left.
          ls_item-t_image = '@B1@'."图标
          ls_item-chosen = ''."是否可选
          ls_item-togg_right = ''. "是否toggle
          ls_item-style = cl_gui_list_tree=>style_emphasized.
          ls_item-length = 5. "长度
          ls_item-length_pix = ''."是否使用pix
          ls_item-ignoreimag = ''. "是否忽略imag
          ls_item-usebgcolor = ''."是否使用bgcolor
          ls_item-txtisqinfo = ''. "是否text为qinfo
          ls_item-text = 'text' && sy-index.
          APPEND ls_item TO lt_item.
          "设置new1的button
          CLEAR ls_item.
          ls_item-node_key = 'New' && sy-index.
          ls_item-item_name = '2'.
          "item种类
          ls_item-class = cl_gui_list_tree=>item_class_button.
          ls_item-length = 10. "长度
          ls_item-text = 'button' && sy-index.
          APPEND ls_item TO lt_item.
          "设置new1的link
          CLEAR ls_item.
          ls_item-node_key = 'New' && sy-index.
          ls_item-item_name = '3'.
          "item种类
          ls_item-class = cl_gui_list_tree=>item_class_link.
          ls_item-length = 10. "长度
          ls_item-text = 'link' && sy-index.
          APPEND ls_item TO lt_item.
          "设置new1的link
          CLEAR ls_item.
          ls_item-node_key = 'New' && sy-index.
          ls_item-item_name = '4'.
          "item种类
          ls_item-class = cl_gui_list_tree=>item_class_checkbox.
          ls_item-length = 1. "长度
          ls_item-txtisqinfo = 'X'. "qinfo
          ls_item-editable = 'X'."是否可编辑
          ls_item-text = 'checkbox' && sy-index.
          APPEND ls_item TO lt_item.
        ENDDO.
    
        lo_list_tree->add_nodes_and_items(
          EXPORTING
            node_table = lt_node
            item_table = lt_item
            item_table_structure_name = 'MTREEITM'
        ).
    
      ENDMETHOD.
      METHOD m_regist_event.
        DATA:lt_events TYPE cntl_simple_events.
        DATA:ls_events TYPE cntl_simple_event.
        ls_events-eventid = cl_gui_column_tree=>eventid_node_double_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_header_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_expand_no_children.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_item_double_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_button_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_link_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_checkbox_change.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        "设置事件
        lo_list_tree->set_registered_events(
          events = lt_events
        ).
        SET HANDLER c8_event_handler=>m_node_double_click FOR lo_list_tree.
        SET HANDLER c8_event_handler=>m_header_click FOR lo_list_tree.
        SET HANDLER c8_event_handler=>m_expand_no_children FOR lo_list_tree.
        SET HANDLER c8_event_handler=>m_item_double_click FOR lo_list_tree.
        SET HANDLER c8_event_handler=>m_button_click FOR lo_list_tree.
        SET HANDLER c8_event_handler=>m_link_click FOR lo_list_tree.
        SET HANDLER c8_event_handler=>m_checkbox_change FOR lo_list_tree.
      ENDMETHOD.
    ENDCLASS.

    示例3:cl_gui_column_tree

    CLASS c8_event_handler DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA:gv_string TYPE string.
        CLASS-METHODS:m_node_double_click FOR EVENT node_double_click OF cl_gui_column_tree
          IMPORTING node_key.
        CLASS-METHODS:m_header_click FOR EVENT header_click OF cl_gui_column_tree
          IMPORTING header_name.
        CLASS-METHODS:m_expand_no_children FOR EVENT expand_no_children OF cl_gui_column_tree
          IMPORTING node_key sender.
        CLASS-METHODS:m_item_double_click FOR EVENT item_double_click OF cl_gui_column_tree
          IMPORTING node_key item_name.
        CLASS-METHODS:m_button_click FOR EVENT button_click OF cl_gui_column_tree
          IMPORTING node_key item_name.
        CLASS-METHODS:m_link_click FOR EVENT link_click OF cl_gui_column_tree
          IMPORTING node_key item_name.
        CLASS-METHODS:m_checkbox_change FOR EVENT checkbox_change OF cl_gui_column_tree
          IMPORTING node_key item_name checked.
    ENDCLASS.
    CLASS c8_event_handler IMPLEMENTATION.
      METHOD:m_node_double_click.
        gv_string = 'node double click node key:' && node_key.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_header_click.
        gv_string = 'header name:' && header_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_expand_no_children.
        DATA:lt_node TYPE treev_ntab.
        DATA:ls_node TYPE treev_node.
        DATA:lt_item TYPE TABLE OF mtreeitm.
        DATA:ls_item TYPE mtreeitm.
        IF node_key = 'Item1'.
          "添加节点
          CLEAR ls_node.
          ls_node-node_key = 'New1'.
          ls_node-relatkey = 'Item1'.
          ls_node-relatship = cl_gui_column_tree=>relat_last_child.
          ls_node-n_image = '@FO@'.
          ls_node-exp_image = '@W5@'.
          APPEND ls_node TO lt_node.
          CLEAR ls_node.
          ls_node-node_key = 'New2'.
          ls_node-relatkey = 'Item1'.
          ls_node-relatship = cl_gui_column_tree=>relat_last_child.
          ls_node-n_image = '@FO@'.
          ls_node-exp_image = '@W5@'.
          APPEND ls_node TO lt_node.
    
          "设置column item
          ls_item-node_key = 'New1'.
          ls_item-item_name = 'Col1'.
          ls_item-class = cl_gui_column_tree=>item_class_text.
          ls_item-text = 'New1->col1'.
          APPEND ls_item TO lt_item.
          ls_item-node_key = 'New1'.
          ls_item-item_name = 'Col2'.
          ls_item-class = cl_gui_column_tree=>item_class_text.
          ls_item-text = 'New1->col2'.
          APPEND ls_item TO lt_item.
          ls_item-node_key = 'New1'.
          ls_item-item_name = 'Col3'.
          ls_item-class = cl_gui_column_tree=>item_class_text.
          ls_item-text = 'New1->col3'.
          APPEND ls_item TO lt_item.
    
          sender->add_nodes_and_items(
            EXPORTING
              node_table = lt_node
              item_table = lt_item
              item_table_structure_name = 'MTREEITM'
          ).
        ENDIF.
        gv_string = 'expand no children node key:' && node_key.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_item_double_click.
        gv_string = 'item double click node key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_button_click.
        gv_string = 'butto click key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_link_click.
        gv_string = 'link click node key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
      METHOD:m_checkbox_change.
        gv_string = 'checkbox change node key:'
          && node_key && 'item name:' && item_name.
        MESSAGE gv_string TYPE 'I'.
      ENDMETHOD.
    ENDCLASS.
    
    CLASS c8_column_tree DEFINITION.
      PUBLIC SECTION.
        DATA:lo_col_tree TYPE REF TO cl_gui_column_tree.
        DATA:ls_header TYPE treev_hhdr.
        METHODS:m_init_tree.
        METHODS:m_creat_col.
        METHODS:m_creat_node.
        METHODS:m_regist_event.
    ENDCLASS.
    CLASS c8_column_tree IMPLEMENTATION.
      METHOD:m_init_tree.
        ls_header-heading = 'heading'.
        ls_header-width = 30.
        ls_header-tooltip = 'this header'.
        ls_header-t_image = '@B1@'.
        "创建tree
        CREATE OBJECT lo_col_tree
          EXPORTING
            parent = cl_gui_container=>default_screen
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection = 'X'
            hierarchy_column_name = 'Col1'
            hierarchy_header = ls_header.
        "创建column
        me->m_creat_col( ).
        "创建node
        me->m_creat_node( ).
        "注册事件
        me->m_regist_event( ).
      ENDMETHOD.
      METHOD:m_creat_col.
        "添加列
        lo_col_tree->add_column(
          EXPORTING
            name = 'Col2'
            alignment = cl_gui_column_tree=>align_right
            width = 20
            header_image = '@B1@'
            header_text = 'Column2'
            header_tooltip = 'this column2'
         ).
        "插入列
        lo_col_tree->insert_column(
          EXPORTING
            name = 'Col3'
            predecessor_column = 'Col2'
            width = 20
            header_image = '@B2@'
            header_text = 'Column3'
            header_tooltip = 'this column3'
         ).
        "删除列
        "delete_column
        "更新列
        "update_column
      ENDMETHOD.
      METHOD m_creat_node.
        DATA:lt_node TYPE treev_ntab.
        DATA:ls_node TYPE treev_node.
        DATA:lt_item TYPE TABLE OF mtreeitm.
        DATA:ls_item TYPE mtreeitm.
        "添加节点
        ls_node-node_key = 'Root'.
        ls_node-isfolder = 'X'.
        ls_node-n_image = '@FO@'.
        ls_node-exp_image = '@W5@'.
        ls_node-hidden = ''.
        ls_node-disabled = ''.
        APPEND ls_node TO lt_node.
        CLEAR ls_node.
        ls_node-node_key = 'Item1'.
        ls_node-relatkey = 'Root'.
        ls_node-relatship = cl_gui_column_tree=>relat_last_child.
        ls_node-isfolder = 'X'.
        ls_node-expander = 'X'.
        ls_node-n_image = '@FO@'.
        ls_node-exp_image = '@W5@'.
        APPEND ls_node TO lt_node.
    
        "设置column item
        ls_item-node_key = 'Root'.
        ls_item-item_name = 'Col1'.
        ls_item-class = cl_gui_column_tree=>item_class_text.
        ls_item-text = 'Root->col1'.
        APPEND ls_item TO lt_item.
        ls_item-node_key = 'Root'.
        ls_item-item_name = 'Col2'.
        ls_item-class = cl_gui_column_tree=>item_class_button.
        ls_item-text = 'Root->col2'.
        APPEND ls_item TO lt_item.
        ls_item-node_key = 'Root'.
        ls_item-item_name = 'Col3'.
        ls_item-class = cl_gui_column_tree=>item_class_link.
        ls_item-text = 'Root->col3'.
        APPEND ls_item TO lt_item.
    
        ls_item-node_key = 'Item1'.
        ls_item-item_name = 'Col1'.
        ls_item-class = cl_gui_column_tree=>item_class_text.
        ls_item-text = 'Item1->col1'.
        APPEND ls_item TO lt_item.
        ls_item-node_key = 'Item1'.
        ls_item-item_name = 'Col2'.
        ls_item-class = cl_gui_column_tree=>item_class_button.
        ls_item-text = 'Item1->col2'.
        APPEND ls_item TO lt_item.
        ls_item-node_key = 'Item1'.
        ls_item-item_name = 'Col3'.
        ls_item-editable = 'X'.
        ls_item-class = cl_gui_column_tree=>item_class_checkbox.
        ls_item-text = 'Item1->col3'.
        APPEND ls_item TO lt_item.
    
        lo_col_tree->add_nodes_and_items(
          EXPORTING
            node_table = lt_node
            item_table = lt_item
            item_table_structure_name = 'MTREEITM'
        ).
    
      ENDMETHOD.
      METHOD m_regist_event.
        DATA:lt_events TYPE cntl_simple_events.
        DATA:ls_events TYPE cntl_simple_event.
        ls_events-eventid = cl_gui_column_tree=>eventid_node_double_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_header_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_expand_no_children.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_item_double_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_button_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_link_click.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        ls_events-eventid = cl_gui_column_tree=>eventid_checkbox_change.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        "设置事件
        lo_col_tree->set_registered_events(
          events = lt_events
        ).
        SET HANDLER c8_event_handler=>m_node_double_click FOR lo_col_tree.
        SET HANDLER c8_event_handler=>m_header_click FOR lo_col_tree.
        SET HANDLER c8_event_handler=>m_expand_no_children FOR lo_col_tree.
        SET HANDLER c8_event_handler=>m_item_double_click FOR lo_col_tree.
        SET HANDLER c8_event_handler=>m_button_click FOR lo_col_tree.
        SET HANDLER c8_event_handler=>m_link_click FOR lo_col_tree.
        SET HANDLER c8_event_handler=>m_checkbox_change FOR lo_col_tree.
      ENDMETHOD.
    ENDCLASS

    示例:节点上右键菜单

    1.创建对应事件响应方法

        CLASS-METHODS:m_node_context_menu_request FOR EVENT node_context_menu_request OF cl_gui_simple_tree
          IMPORTING node_key menu.
        CLASS-METHODS:m_node_context_menu_select FOR EVENT node_context_menu_select OF cl_gui_simple_tree
          IMPORTING node_key fcode.

    2.方法实现

     "创建menu
      METHOD m_node_context_menu_request.
        DATA:lo_menu TYPE REF TO cl_ctmenu.
        CREATE OBJECT lo_menu.
        lo_menu->add_function(
          EXPORTING
            fcode = 'FUNC1'
            text = 'function 1'
            icon = '@B1@'
        ).
        lo_menu->add_function(
          EXPORTING
            fcode = 'FUNC2'
            text = 'function 2'
            icon = '@B1@'
        ).
        menu->add_function(
          EXPORTING
            fcode = 'FUNC'
            text = 'function'
            icon = '@B3@'
        ).
        menu->add_submenu(
          EXPORTING
            menu = lo_menu
            text = 'menu1'
            icon = '@B2@'
         ).
      ENDMETHOD.
      METHOD m_node_context_menu_select.
        DATA:lv_str TYPE string.
        lv_str = 'node_key:' && node_key
          && 'function:' && fcode.
        MESSAGE lv_str TYPE 'I'.
      ENDMETHOD

    3.注册事件,以及设置handler

        ls_events-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
        ls_events-appl_event = ''.
        APPEND ls_events TO lt_events.
        "设置事件
        lo_simple_tree->set_registered_events(
          events = lt_events
        ). 

    设置事件Handler

        SET HANDLER c8_event_handler=>m_node_context_menu_request FOR lo_simple_tree.
        SET HANDLER c8_event_handler=>m_node_context_menu_select FOR lo_simple_tree.
  • 相关阅读:
    个人作业-Alpha项目测试
    第三次作业
    第二次作业
    第一次作业
    JQuery(一)页面加载,写入文本,对象转换,隐藏显示,基本选择器,层级选择器,基本过滤选择器,表单选择器,class操作,属性操作
    JavaScript(二)
    轮辐广告、简单选项卡
    div层随着页面大小变化相对位置不变、按钮隐藏一半鼠标放上去就出来,不放上去就退回去
    markDown语法详解
    Mybatis中动态SQL语句
  • 原文地址:https://www.cnblogs.com/tangToms/p/14772095.html
Copyright © 2011-2022 走看看