ABAP顾问
分类:
2007-11-29 22:05:05
REPORT z_barry_tree .
DATA: mycontainer TYPE REF TO cl_gui_custom_container.
DATA: node_itab LIKE node_str OCCURS 0 ,
node LIKE node_str.
DATA: g_tree TYPE REF TO cl_gui_simple_tree.
TYPES: node_table_type LIKE STANDARD
TABLE OF mtreesnode WITH DEFAULT KEY .
DATA: node_table TYPE node_table_type,
events TYPE cntl_simple_events,
event TYPE cntl_simple_event.
DATA ok_code TYPE sy-ucomm.
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS: node_double_click
FOR EVENT node_double_click
OF cl_gui_simple_tree
IMPORTING node_key.
ENDCLASS. "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD node_double_click.
PERFORM dclik USING node_key .
ENDMETHOD.
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
DATA: event_receiver TYPE REF TO lcl_event_receiver.
START-OF-SELECTION.
PERFORM getdata .
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Form fill_tree
*&---------------------------------------------------------------------*
FORM getdata .
PERFORM fill_node USING 'Root1' '' 'X' '' 'Root1' ''.
PERFORM fill_node USING 'Lay1' 'Root1' 'X' '6' 'Lay1' '' .
PERFORM fill_node USING 'Item' 'Lay1' '' '6' 'Item' .
PERFORM fill_node USING 'Lay2' 'Root1' '' '6' 'Item2' .
PERFORM fill_node USING 'Root2' '' 'X' '' 'Root2' '' .
ENDFORM. " fill_tree
*---------------------------------------------------------------------*
* FORM fill_node *
*---------------------------------------------------------------------*
FORM fill_node USING node_key
relatkey
isfolder
relatship
text
n_image .
DATA: node LIKE mtreesnode.
CLEAR node.
node-node_key = node_key.
node-relatkey = relatkey.
node-isfolder = isfolder.
node-relatship = relatship.
node-text = text.
node-n_image = n_image.
APPEND node TO node_table.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
IF mycontainer IS INITIAL.
CREATE OBJECT mycontainer
EXPORTING container_name = 'TREE1'.
CREATE OBJECT g_tree
EXPORTING parent = mycontainer
node_selection_mode = g_tree->node_sel_mode_single.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->node_double_click FOR g_tree.
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = ' '. "system event, does not trigger PAI
APPEND event TO events.
CALL METHOD g_tree->set_registered_events
EXPORTING events = events.
CALL METHOD g_tree->add_nodes
EXPORTING
node_table = node_table
table_structure_name = 'MTREESNODE'
EXCEPTIONS
failed = 1
error_in_node_table = 2
dp_error = 3
table_structure_name_not_found = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE e000(z900) WITH 'error'.
ENDIF.
CALL METHOD g_tree->expand_root_nodes
EXPORTING
expand_subtree = 'X'
EXCEPTIONS
failed = 1
illegal_level_count = 2
cntl_system_error = 3
OTHERS = 4.
ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form dclik
*&---------------------------------------------------------------------*
FORM dclik USING p_node_key.
MESSAGE s000(z900) WITH p_node_key.
ENDFORM. " dclik