SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Demo: Drag and Drop: Tree -> Tree



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Nov 05, 2007 12:05 pm    Post subject: Demo: Drag and Drop: Tree -> Tree Reply with quote

Code:
*&---------------------------------------------------------------------*
*& Report  RSDEMO_DRAG_DROP_EDIT_TREE                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  rsdemo_drag_drop_edit_tree    .
DATA ok_code TYPE sy-ucomm.
DATA node_itab_left LIKE node_str OCCURS 0.
DATA node_itab_right LIKE node_str OCCURS 0.
DATA node LIKE node_str.

DATA container TYPE REF TO cl_gui_custom_container.
DATA splitter TYPE REF TO cl_gui_easy_splitter_container.
DATA right TYPE REF TO cl_gui_container.
DATA left  TYPE REF TO cl_gui_container.

DATA tree_right TYPE REF TO cl_gui_simple_tree.
DATA tree_left TYPE REF TO cl_gui_simple_tree.

DATA behaviour_left TYPE REF TO cl_dragdrop.
DATA behaviour_right TYPE REF TO cl_dragdrop.

DATA handle_tree_left TYPE i.
DATA handle_tree_right TYPE i.

*---------------------------------------------------------------------*
*       CLASS lcl_treeobject DEFINITION
*---------------------------------------------------------------------*
*       Definition of Data Container                                  *
*---------------------------------------------------------------------*
CLASS lcl_drag_object DEFINITION.
  PUBLIC SECTION.
    DATA text TYPE STANDARD TABLE OF mtreesnode-text.
ENDCLASS.


*---------------------------------------------------------------------*
*       CLASS dragdrop_receiver DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_dragdrop_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
       flavor_select FOR EVENT on_drop_get_flavor OF cl_gui_simple_tree
                      IMPORTING node_key flavors drag_drop_object,
       left_drag FOR EVENT on_drag_multiple OF cl_gui_simple_tree
                      IMPORTING node_key_table drag_drop_object,
       right_drop FOR EVENT on_drop OF cl_gui_simple_tree
                      IMPORTING node_key drag_drop_object,
       drop_complete FOR EVENT on_drop_complete_multiple OF
                      cl_gui_simple_tree
                      IMPORTING node_key_table drag_drop_object.

ENDCLASS.

************************************************************************


************************************************************************

START-OF-SELECTION.
  CALL SCREEN 100.
*&---------------------------------------------------------------------*
*&      Module  START  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE start OUTPUT.
  SET PF-STATUS 'BASE'.
  IF container is initial.
    CREATE OBJECT container
        EXPORTING container_name = 'CONTAINER'.
    CREATE OBJECT splitter
        EXPORTING parent = container
                  orientation = 1.
    left = splitter->top_left_container.
    right = splitter->bottom_right_container.
    CREATE OBJECT tree_right
     EXPORTING parent = right
               node_selection_mode = tree_right->node_sel_mode_multiple.
    CREATE OBJECT tree_left
      EXPORTING parent = left
                node_selection_mode = tree_left->node_sel_mode_multiple.

* Definition of drag drop behaviour
    CREATE OBJECT behaviour_left.
    CALL METHOD behaviour_left->add
        EXPORTING
              flavor = 'Tree_move'
              dragsrc = 'X'
              droptarget = ' '
              effect = cl_dragdrop=>copy.
    CALL METHOD behaviour_left->add
         EXPORTING
               flavor = 'Tree_copy'
               dragsrc = 'X'
               droptarget = ' '
               effect = cl_dragdrop=>copy.

    CALL METHOD behaviour_left->get_handle
         IMPORTING handle = handle_tree_left.

* Drag Drop behaviour of tree control nodes are defined in the node
* structure
    PERFORM fill_tree CHANGING handle_tree_left node_itab_left.
    CALL METHOD tree_left->add_nodes
         EXPORTING node_table = node_itab_left
                   table_structure_name = 'NODE_STR'.

    CREATE OBJECT behaviour_right.

    CALL METHOD behaviour_right->add
           EXPORTING
                 flavor = 'Tree_copy'
                 dragsrc = ' '
                 droptarget = 'X'
                 effect = cl_dragdrop=>copy.
    CALL METHOD behaviour_right->add
           EXPORTING
                 flavor = 'Tree_move'
                 dragsrc = ' '
                 droptarget = 'X'
                 effect = cl_dragdrop=>copy.
    CALL METHOD behaviour_right->get_handle
         IMPORTING handle = handle_tree_right.

    PERFORM fill_tree CHANGING handle_tree_right node_itab_right.
    CALL METHOD tree_right->add_nodes
         EXPORTING node_table = node_itab_right
                   table_structure_name = 'NODE_STR'.

* registration of drag and drop events
    DATA dragdrop TYPE REF TO lcl_dragdrop_receiver.
    CREATE OBJECT dragdrop.
    SET HANDLER dragdrop->flavor_select FOR tree_right.
    SET HANDLER dragdrop->left_drag FOR tree_left.
    SET HANDLER dragdrop->right_drop FOR tree_right.
    SET HANDLER dragdrop->drop_complete FOR tree_left.


    CALL METHOD tree_left->expand_node
         EXPORTING node_key = 'Root'.
    CALL METHOD tree_right->expand_node
         EXPORTING node_key = 'Root'.

  ENDIF.
ENDMODULE.                             " START  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE exit INPUT.
  LEAVE PROGRAM.
ENDMODULE.                             " EXIT  INPUT
*&---------------------------------------------------------------------*
*&      Form  fill_tree
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <p2>relat_last_child.
  node-text = 'DragDrop Text 1'.
  node-dragdropid = handle_tree.       " handle of behaviour
  APPEND node TO node_itab.

  CLEAR node.
  node-node_key = 'Child2'.
  node-relatkey = 'Root'.
    node-isfolder = 'X'.
    node-relatship = cl_gui_simple_tree=>relat_last_child.
  node-text = 'DragDrop Text 2'.
  node-dragdropid = handle_tree.       " handle of behaviour
  APPEND node TO node_itab.


ENDFORM.                               " fill_tree
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CALL METHOD cl_gui_cfw=>dispatch.
ENDMODULE.                             " USER_COMMAND_0100  INPUT


*---------------------------------------------------------------------*
*       CLASS DRAGDROP_RECEIVER IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_dragdrop_receiver IMPLEMENTATION.
  METHOD flavor_select.
    IF node_key <> 'Root'.
      SEARCH flavors FOR 'Tree_move'.
      IF sy-subrc = 0.
        CALL METHOD drag_drop_object->set_flavor
             EXPORTING newflavor = 'Tree_move'.
      ELSE.
        CALL METHOD drag_drop_object->abort.
      ENDIF.
    ELSE.
      SEARCH flavors FOR 'Tree_copy'.
      IF sy-subrc = 0.
        CALL METHOD drag_drop_object->set_flavor
             EXPORTING newflavor = 'Tree_copy'.
      ELSE.
        CALL METHOD drag_drop_object->abort.
      ENDIF.
    ENDIF.

  ENDMETHOD.
  METHOD left_drag.
    DATA drag_object TYPE REF TO lcl_drag_object.
    DATA node_key TYPE node_str-node_key.
    CREATE OBJECT drag_object.
    LOOP AT node_key_table INTO node_key.
      READ TABLE node_itab_left WITH KEY node_key = node_key
                           INTO node.

      APPEND node-text TO drag_object->text.
    ENDLOOP.
    drag_drop_object->object = drag_object.
  ENDMETHOD.

  METHOD right_drop.
    DATA drag_object TYPE REF TO lcl_drag_object.
    data new_nodes like node_itab_right.
    data new_node type node_str.
    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
      drag_object ?= drag_drop_object->object.
    ENDCATCH.
    IF sy-subrc = 1.
      " data object has unexpected class
                                       " => cancel Drag & Drop operation
      CALL METHOD drag_drop_object->abort.
      EXIT.
     ENDIF.
   loop at drag_object->text into new_node-text.
     perform add_node changing node_key new_node new_nodes
                               node_itab_left.
    endloop.
     call method tree_right->add_nodes
          exporting node_table           = new_nodes
                    table_structure_name = 'NODE_STR'.
  ENDMETHOD.
  METHOD drop_complete.
    DATA node_key TYPE node_str-node_key.
    IF drag_drop_object->flavor = 'Tree_move_to_Edit'.
      LOOP AT node_key_table INTO node_key.
        CALL METHOD tree_left->delete_node
               EXPORTING node_key = node_key.
        DELETE node_itab_left WHERE node_key = node_key.
      ENDLOOP.
    ENDIF.

  ENDMETHOD.
ENDCLASS.

*&---------------------------------------------------------------------*
*&      Form  ADD_NODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_NEW_NODE  text
*      <--P_NEW_NODES  text
*      <--P_NODE_ITAB_LEFT  text
*----------------------------------------------------------------------*
FORM ADD_NODE CHANGING node_key
                       NEW_NODE type node_str
                       NEW_NODES like node_itab_left
                       NODE_ITAB_LEFT like node_itab_left.
data lines type i.
describe table node_itab_left lines lines.
  new_node-node_key = lines.
  new_node-isfolder = 'X'.
  new_node-dragdropid = handle_tree_right.
  new_node-relatkey = node_key.

  APPEND new_node TO new_nodes.
  append new_node to node_itab_left.

ENDFORM.                    " ADD_NODE


****************************************************************
* This file was generated by Direct Download Enterprise. *
* Please do not change it manually. *
****************************************************************
%_DYNPRO
RSDEMO_DRAG_DROP_TREE_MULTI
0100
620
40
%_HEADER
RSDEMO_DRAG_DROP_TREE_MULTI 0100 0100 21 83192 35 0 0 21 83 0G D 20001113153750
%_DESCRIPTION
Drag & Drop Example
%_FIELDS
CONTAINER 83 00 00 00 30 00 2 2 0 0 0 20 U 1 1 102
OK_CODE CHAR 20 80 10 00 00 00 255 1 O 0 0 0
%_FLOWLOGIC
PROCESS BEFORE OUTPUT.
MODULE STArt.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
module exit at exit-command.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dialog Programming All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.