REPORT Zexplore MESSAGE-ID tree_control_msg. *---------------------------------------------------------------------* * REPORT Zexplore * *---------------------------------------------------------------------* * Display a tree containing directories and files of a server * * Can be used as a base for popup selecting files * *---------------------------------------------------------------------* * Created : 17/05/2001 * * Author : François Henrotte (http://www.eponasolutions.com) * *---------------------------------------------------------------------* ************************************************************************ * Displays a tree containing directories included in a specified path * * or server. Needs a dynpro 100 with one control of type Custom Contr * * which name is TREE_CONTAINER. Lenght and height of the control will * * depend of the dynpro (full screen or popup) but the leght should be * * at least 50. * ************************************************************************ CLASS lcl_application DEFINITION DEFERRED. CLASS cl_gui_cfw DEFINITION LOAD. TYPES: node_table_type LIKE STANDARD TABLE OF mtreesnode WITH DEFAULT KEY. DATA: g_application TYPE REF TO lcl_application, g_custom_container_1 TYPE REF TO cl_gui_custom_container, g_tree TYPE REF TO cl_gui_simple_tree, g_ok_code TYPE sy-ucomm. TYPES: BEGIN OF gs_chem, nodekey TYPE tv_nodekey, chemin(255) TYPE c, dir(1) TYPE c, END OF gs_chem. DATA: gt_outtab TYPE STANDARD TABLE OF salfldir, gt_ch TYPE STANDARD TABLE OF gs_chem, gs_ch TYPE gs_chem. DATA: g_node_key TYPE tv_nodekey, node_nb TYPE i, w_host(80) TYPE c, w_delim(1) TYPE c. *---------------------------------------------------------------------* * 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, handle_expand_no_children FOR EVENT expand_no_children OF cl_gui_simple_tree IMPORTING node_key. ENDCLASS. *---------------------------------------------------------------------* * CLASS LCL_APPLICATION IMPLEMENTATION *---------------------------------------------------------------------* CLASS lcl_application IMPLEMENTATION. METHOD handle_node_double_click. DATA: edit_tab TYPE STANDARD TABLE OF spflist. g_node_key = node_key. LOOP AT gt_ch INTO gs_ch WHERE nodekey = node_key. IF gs_ch-dir = 'X'. ELSE. CALL FUNCTION 'RZL_READ_FILE' EXPORTING name = gs_ch-chemin nrlines = 500 TABLES line_tbl = edit_tab EXCEPTIONS argument_error = 1 not_found = 2 send_error = 3 OTHERS = 4. IF sy-subrc = 0. EDITOR-CALL FOR edit_tab. ENDIF. ENDIF. ENDLOOP. ENDMETHOD. METHOD handle_expand_no_children. DATA: g_node_table TYPE node_table_type, node TYPE mtreesnode, node_chemin(255) TYPE c. g_node_key = node_key. DATA: it_dir TYPE salfldir. LOOP AT gt_ch INTO gs_ch WHERE nodekey = node_key. node_chemin = gs_ch-chemin. ENDLOOP. IF sy-subrc NE 0. EXIT. ENDIF. CALL FUNCTION 'RZL_READ_DIR' EXPORTING name = node_chemin nrlines = 500 TABLES file_tbl = gt_outtab EXCEPTIONS argument_error = 1 not_found = 2 send_error = 3 OTHERS = 4. LOOP AT gt_outtab INTO it_dir. CLEAR gs_ch. gs_ch-nodekey = node_nb. CONCATENATE node_chemin it_dir-name INTO gs_ch-chemin SEPARATED BY w_delim. CLEAR node. node-node_key = node_nb. node-relatkey = node_key. node-relatship = cl_gui_simple_tree=>relat_last_child. node-text = it_dir-name. IF it_dir-size IS INITIAL. node-isfolder = 'X'. node-expander = 'X'. gs_ch-dir = 'X'. ENDIF. IF it_dir-name NE '.' AND it_dir-name NE '..'. APPEND gs_ch TO gt_ch. APPEND node TO g_node_table. node_nb = node_nb + 1. ENDIF. ENDLOOP. IF sy-subrc EQ 0. CALL METHOD g_tree->add_nodes EXPORTING table_structure_name = 'MTREESNODE' node_table = g_node_table EXCEPTIONS failed = 1 error_in_node_table = 2 dp_error = 3 table_structure_name_not_found = 4 OTHERS = 5. ENDIF. ENDMETHOD. ENDCLASS. ************************************************************************ INITIALIZATION. PARAMETERS: p_host(80) TYPE c LOWER CASE. ************************************************************************ AT SELECTION-SCREEN. w_host = p_host. CASE sy-opsys. WHEN 'Windows NT'. IF w_host(2) NE '\\'. CONCATENATE '\\' w_host '\sapmnt' INTO w_host. ENDIF. w_delim = '\'. WHEN OTHERS. IF p_host(1) NE '/'. CONCATENATE '/' w_host INTO w_host. ENDIF. w_delim = '/'. ENDCASE. CALL FUNCTION 'RZL_READ_DIR' EXPORTING name = w_host nrlines = 500 TABLES file_tbl = gt_outtab EXCEPTIONS argument_error = 1 not_found = 2 send_error = 3 OTHERS = 4. IF sy-subrc NE 0. IF p_host(1) = '/' OR p_host = '\'. MESSAGE e666(s1) WITH p_host. ELSE. MESSAGE e057(0t) WITH p_host. ENDIF. ENDIF. ************************************************************************ START-OF-SELECTION. CREATE OBJECT g_application. SET SCREEN 100. *---------------------------------------------------------------------* * MODULE PBO_100 OUTPUT * *---------------------------------------------------------------------* MODULE pbo_100 OUTPUT. SET PF-STATUS 'MAIN'. IF p_host(1) = '/' OR p_host(1) = '\'. SET TITLEBAR '001' WITH 'files'. ELSE. SET TITLEBAR '001' WITH p_host. ENDIF. IF g_tree IS INITIAL. PERFORM create_and_init_tree. ENDIF. ENDMODULE. " PBO_0100 OUTPUT *---------------------------------------------------------------------* * MODULE PAI_100 INPUT * *---------------------------------------------------------------------* MODULE pai_100 INPUT. CALL METHOD cl_gui_cfw=>dispatch. CASE g_ok_code. WHEN 'BACK'. IF NOT g_custom_container_1 IS INITIAL. CALL METHOD g_custom_container_1->free EXCEPTIONS cntl_system_error = 1 cntl_error = 2. IF sy-subrc <> 0. MESSAGE a000. ENDIF. ENDIF. CLEAR g_custom_container_1. CLEAR g_tree. LEAVE PROGRAM. ENDCASE. CLEAR g_ok_code. ENDMODULE. " PAI_0100 INPUT *----------------------------------------------------------------------* FORM create_and_init_tree. DATA: events TYPE cntl_simple_events, event TYPE cntl_simple_event, repid TYPE sy-repid, dynnr TYPE sy-dynnr. CREATE OBJECT g_custom_container_1 EXPORTING container_name = 'TREE_CONTAINER' EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5. IF sy-subrc <> 0. MESSAGE a000. ENDIF. CREATE OBJECT g_tree EXPORTING parent = g_custom_container_1 node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single EXCEPTIONS lifetime_error = 1 cntl_system_error = 2 create_error = 3 failed = 4 illegal_node_selection_mode = 5. IF sy-subrc <> 0. MESSAGE a000. ENDIF. event-eventid = cl_gui_simple_tree=>eventid_node_double_click. event-appl_event = 'X'. " process PAI if event occurs APPEND event TO events. event-eventid = cl_gui_simple_tree=>eventid_expand_no_children. event-appl_event = 'X'. APPEND event TO events. CALL METHOD g_tree->set_registered_events EXPORTING events = events EXCEPTIONS cntl_error = 1 cntl_system_error = 2 illegal_event_combination = 3. IF sy-subrc <> 0. MESSAGE a000. ENDIF. SET HANDLER g_application->handle_node_double_click FOR g_tree. SET HANDLER g_application->handle_expand_no_children FOR g_tree. PERFORM build_node_table. ENDFORM. " CREATE_AND_INIT_TREE *----------------------------------------------------------------------* FORM build_node_table. DATA: g_node_table TYPE node_table_type, it_dir TYPE salfldir, node TYPE mtreesnode. CLEAR: node, node_nb. node-node_key = '0'. node-isfolder = 'X'. IF p_host(1) = '/' OR p_host(1) = '\'. node-text = 'DIR'. ELSE. node-text = p_host. ENDIF. APPEND node TO g_node_table. node_nb = node_nb + 1. LOOP AT gt_outtab INTO it_dir. CLEAR gs_ch. gs_ch-nodekey = node_nb. CONCATENATE w_host it_dir-name INTO gs_ch-chemin SEPARATED BY w_delim. CLEAR node. node-node_key = node_nb. node-relatkey = '0'. node-relatship = cl_gui_simple_tree=>relat_last_child. node-text = it_dir-name. IF it_dir-size IS INITIAL. node-isfolder = 'X'. node-expander = 'X'. gs_ch-dir = 'X'. ENDIF. IF it_dir-name NE '.' AND it_dir-name NE '..'. APPEND gs_ch TO gt_ch. APPEND node TO g_node_table. node_nb = node_nb + 1. ENDIF. ENDLOOP. IF sy-subrc EQ 0. CALL METHOD g_tree->add_nodes EXPORTING table_structure_name = 'MTREESNODE' node_table = g_node_table EXCEPTIONS failed = 1 error_in_node_table = 2 dp_error = 3 table_structure_name_not_found = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE a000. ENDIF. ENDIF. ENDFORM. " build_node_table