TREE CONTROL

来源:互联网 发布:卓智网络 保荐 编辑:程序博客网 时间:2024/06/05 17:46

*&---------------------------------------------------------------------*
*& Report  YTREE                                                       *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

report  ytree                                   .


*功能码返回值
data: ok_code type sy-ucomm,
      save_ok type sy-ucomm.
*定制对象

data: wa_container type scrfname value 'TREE',
*客户对象
      wa_custom_container type ref to cl_gui_custom_container,
      wa_tree type ref to cl_gui_simple_tree.
*NODE 节点表
data: node_table like table of mtreesnode,
*节点


      node1 type mtreesnode.
*定义内表,变量需要传递,不加HEADER LINE
data wa_spfli type table of spfli.
*当双击时取得节点KEY值与节点文本值变量


data: nodekey(200) value 'NODE',nodetext(200) value 'NONE'.

*定义对象,定义对象的双击方法,用于将该对象双击方法分配到树双击事件
class lcl_application definition deferred.

*---------------------------------------------------------------------*
*       CLASS lcl_application DEFINITION
*---------------------------------------------------------------------*
*  对象定义
*---------------------------------------------------------------------*
class lcl_application definition.
  public section.
*自定义双击方法,参数为节点关键字
    methods handle_node_double_click
        for event node_double_click
        of cl_gui_simple_tree
        importing node_key.
endclass.                    "

*---------------------------------------------------------------------*
*       CLASS lcl_application IMPLEMENTATION
*---------------------------------------------------------------------*
*  对象方法实现
*---------------------------------------------------------------------*
class lcl_application implementation.
  method handle_node_double_click.
* 当双击时弹出信息窗口,调试用
* MESSAGE I208(00) WITH 'double'.
*取得KEY值,在窗口显示
    nodekey = node_key.
*从节点内表中按关键字读取单个节点
    read table node_table with key node_key = node_key into node1.
*将节点文本在窗口中显示
    nodetext = node1-text.
  endmethod.                    "HANDLE_NODE_DOUBLE_CLICK
endclass.                    "lcl_application IMPLEMENTATION

*自定义定义对象实例
data: g_application type ref to lcl_application.

start-of-selection.

  create object g_application.
* 直接调用窗口,在窗口PBO分配双击对象
  call screen 100.

 

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
*  SET PF-STATUS 'STATUS1'.
  if wa_custom_container is initial.
    perform create_tree.
  endif.

endmodule.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
* 用户交互
*----------------------------------------------------------------------*
module user_command_0100 input.
  ok_code = sy-ucomm .
  save_ok = ok_code.
  clear ok_code.
  case save_ok.
    when 'EXIT'.
      leave program.
  endcase.
endmodule.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  CREATE_TREE
*&---------------------------------------------------------------------*
*    创建树及子节点
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_tree .
*事件内表及单个事件对象
  data: events type cntl_simple_events,
        event1 type cntl_simple_event.
*建立定制控制对象


  create object wa_custom_container
    exporting
    container_name = wa_container.
*建立树对象
  create object wa_tree
    exporting
*    LIFETIME            =


    parent               = wa_custom_container
*    SHELLSYLE           =
    node_selection_mode  = cl_gui_simple_tree=>node_sel_mode_single
*    HIDE_SELECTION      =
*    NAME                =
*    EXCEPTIONS
*    LIFETIME_ERROR              = 1
*    CNTL_SYSTEM_ERROR           = 2
*    CREATE_ERROR                = 3
*    FAILED                      = 4
*    ILLEGAL_NOCE_SELECTION_MODE = 5
*    OTHERS  = 6
    .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*开始建立以国家-> 城市->城区 三层 的树
  clear node1.
*节点关键字
  node1-node_key = '国家'.
*第一层
  clear node1-relatkey.
  clear node1-relatship.
*是文件夹
  node1-hidden = ''.
  node1-disabled = ''.
  node1-isfolder = 'X'.
*不带ICON
  clear node1-n_image.
  clear node1-exp_image.
  clear node1-expander.

  node1-text = '中国'.
  append node1 to node_table.
*二层节点
  clear node1.
  node1-node_key = '城市北京'.
*上层关系
  node1-relatkey = '国家'.


  node1-relatship = cl_gui_simple_tree=>relat_last_child.
  node1-hidden = ''.
  node1-disabled = ''.
  node1-isfolder = 'X'.
  clear node1-n_image.
  clear node1-exp_image.
  clear node1-expander.
  node1-text = '北京'.
  append node1 to node_table.

  clear node1.

  node1-node_key = '城市上海'.
  node1-relatkey = '国家'.
  node1-relatship = cl_gui_simple_tree=>relat_last_child.
  node1-hidden = ''.
  node1-disabled = ''.
  node1-isfolder = 'X'.
  clear node1-n_image.
  clear node1-exp_image.
  clear node1-expander.
  node1-text = '上海'.
  append node1 to node_table.

  clear node1.
  node1-node_key = 'KEY 崇文区'.
  node1-relatkey = '城市北京'.
  node1-relatship = cl_gui_simple_tree=>relat_last_child.
  node1-hidden = ''.
  node1-disabled = ''.
  node1-isfolder = ''.
*图标,可运行SHOWICON查阅
  node1-n_image = '@9Y@'.
  node1-exp_image = '@9Y@'.
  clear node1-expander.
  node1-text = '崇文区'.
  append node1 to node_table.

  clear node1.
  node1-node_key = 'KEY 西城区'.

  node1-relatkey = '城市北京'.


  node1-relatship = cl_gui_simple_tree=>relat_last_child.
  node1-hidden = ''.
  node1-disabled = ''.
  node1-isfolder = ''.
  node1-n_image = '@DF@'.
  node1-exp_image = '@DF@'.
  clear node1-expander.
  node1-text = '西城区'.
  append node1 to node_table.

  clear node1.
  node1-node_key = 'KEY 闵行区'.
  node1-relatkey = '城市上海'.
  node1-relatship = cl_gui_simple_tree=>relat_last_child.
  node1-hidden = ''.
  node1-disabled = ''.
  node1-isfolder = ''.
  node1-n_image = '@NL@'.
  node1-exp_image = '@NL@'.
  clear node1-expander.
  node1-text = '闵行区'.
  append node1 to node_table.
*按照节点内容添加节点
  call method wa_tree->add_nodes
    exporting
      table_structure_name      = 'MTREESNODE'
      node_table                = node_table
*    EXCEPTIONS
*      ERROR_IN_NODE_TABLE             = 1
*      FAILED                          = 2
*      DP_ERROF                        = 3
*      TABLE_STRUCTURE_NAME_NOT_FOUND  = 4
*      OTHERS                          = 5
      .
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*定义双击事件
  event1-eventid = cl_gui_simple_tree=>eventid_node_double_click.
  event1-appl_event = 'X'.
  append event1 to events.
*添加事件内表


  call method wa_tree->set_registered_events
      exporting
        events  = events
*    EXCEPTIONS
*      CNTL_ERROR                = 1
*      CNTL_SYSTEM_ERROR         = 2
*      ILLEGAL_EVENT_COMBINATION = 3
*      OTHERS                    = 4
      .
  if sy-subrc <> 0.


* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
*将已定义的双击事件分配至树对象
  set handler g_application->handle_node_double_click for wa_tree.
endform.                    " CREATE_TREE

原创粉丝点击