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 -> Editor



 
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:09 pm    Post subject: Demo: Drag and Drop: Tree -> Editor 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 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 editor TYPE REF TO cl_gui_textedit.
DATA tree 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 TYPE i.

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


*---------------------------------------------------------------------*
*       CLASS dragdrop_receiver DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_dragdrop_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
       flavor_select FOR EVENT on_get_flavor OF cl_gui_textedit
                      IMPORTING index line pos flavors dragdrop_object,
       left_drag FOR EVENT on_drag OF cl_gui_simple_tree
                      IMPORTING node_key drag_drop_object,
       right_drop FOR EVENT ON_DROP OF cl_gui_textedit
                      IMPORTING index line pos dragdrop_object,
       drop_complete FOR EVENT on_drop_complete OF cl_gui_simple_tree
                      IMPORTING node_key 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 editor
        EXPORTING parent = right.
    CREATE OBJECT tree
        EXPORTING parent = left
                  node_selection_mode = tree->node_sel_mode_single.

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

    CALL METHOD behaviour_left->get_handle
         IMPORTING handle = handle_tree.

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

    CREATE OBJECT behaviour_right.
 CALL METHOD behaviour_right->add
        EXPORTING
              flavor = 'Tree_move_to_Edit'
              dragsrc = ' '
              droptarget = 'X'
              effect = cl_dragdrop=>copy.
 CALL METHOD behaviour_right->add
        EXPORTING
              flavor = 'Tree_copy_to_Edit'
              dragsrc = ' '
              droptarget = 'X'
              effect = cl_dragdrop=>copy.
    CALL METHOD editor->set_dragdrop
         EXPORTING dragdrop = behaviour_right.

* registration of drag and drop events
    DATA dragdrop TYPE REF TO lcl_dragdrop_receiver.
    CREATE OBJECT dragdrop.
    SET HANDLER dragdrop->flavor_select FOR editor.
    SET HANDLER dragdrop->left_drag FOR tree.
    SET HANDLER dragdrop->right_drop FOR editor.
    set handler dragdrop->drop_complete for tree.


    CALL METHOD tree->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-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 line > 5.
      SEARCH flavors FOR 'Tree_move_to_Edit'.
      IF sy-subrc = 0.
        CALL METHOD dragDROP_OBJECT->SET_FLAVOR
             EXPORTING newflavor = 'Tree_move_to_Edit'.
      ELSE.
        CALL METHOD dragdrop_object->abort.
      ENDIF.
    ELSE.
      SEARCH flavors FOR 'Tree_copy_to_Edit'.
      IF sy-subrc = 0.
        CALL METHOD dragdrop_object->set_flavor
             EXPORTING newflavor = 'Tree_copy_to_Edit'.
      ELSE.
        CALL METHOD dragdrop_object->abort.
      ENDIF.
    ENDIF.

  ENDMETHOD.
  METHOD left_drag.
    DATA drag_object TYPE REF TO lcl_drag_object.

    READ TABLE node_itab WITH KEY node_key = node_key
                         INTO node.

    CREATE OBJECT drag_object.
    drag_object->text = node-text.
    drag_drop_object->object = drag_object.
ENDMETHOD.

  METHOD right_drop.
    DATA textline(256).
    DATA text_table LIKE STANDARD TABLE OF textline.
    DATA drag_object TYPE REF TO lcl_drag_object.
    CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
      drag_object ?= dragdrop_object->object.
    ENDCATCH.
    IF sy-subrc = 1.
      " data object has unexpected class
                                       " => cancel Drag & Drop operation
      CALL METHOD dragdrop_object->abort.
      EXIT.
    ENDIF.
    CALL METHOD editor->get_text_as_stream
         IMPORTING text        = text_table.
* Synchronize Automation Queue after Get Methods
    CALL METHOD cl_gui_cfw=>flush.
    textline = drag_object->text.
* Insert text in internal table
    INSERT textline INTO text_table INDEX 1.
* Send modified table to frontend
    CALL METHOD editor->set_text_as_stream
         EXPORTING  text = text_table
         EXCEPTIONS error_dp        = 1
                    error_dp_create = 2.
  ENDMETHOD.
  METHOD drop_complete.
    IF drag_drop_object->flavor = 'Tree_move_to_Edit'.
      CALL METHOD tree->delete_node
           EXPORTING node_key = node_key.
      delete node_itab where node_key = node_key.
    ENDIF.
    ENDMETHOD.
ENDCLASS.


****************************************************************
* This file was generated by Direct Download Enterprise. *
* Please do not change it manually. *
****************************************************************
%_DYNPRO
RSDEMO_DRAG_DROP_EDIT_TREE
0100
620
40
%_HEADER
RSDEMO_DRAG_DROP_EDIT_TREE 0100 0100 21 83192 35 0 0 21 83 0G D 20001113153749
%_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.