Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Drag and Drop question

Former Member
0 Kudos
167

Hi,

I have a program with a tree and two CL_GUI_TEXTEDIT windows. Depending on the drag and drop event, I would like to do some additional follow on functions. For this, I need to know which CL_GUI_TEXTEDIT window the drop was done. Do I have to create different flabors, or can I use a single flavor and find out which window the drop was done.

Thanks.

Albert

6 REPLIES 6

uwe_schieferstein
Active Contributor
0 Kudos
56

Hello Albert

All events have an <i>optional </i>IMPORTING parameter <b>SENDER </b>which corresponds to the control that has raised the event.

Perhaps this could be a simple and quick solution to your problem.

Regards

Uwe

0 Kudos
56

Hi Uwe,

I could not find the SENDER parameter in the methods. I can get the class name, but I want to get the variable name.

Albert

0 Kudos
56

Hi,

If you want tho handle a parameter, you have to implement it in the (handler)method..

Then it is filled implicitly...

Regards,

Gianpietro

0 Kudos
56

Hello Albert,

retrieving the variable name is not possible. You need to maintain some mechanism to retrieve the role from the sender object. E.g. you may develop a service method which returns the role for the controls based on their instance.

Regards

Klaus

uwe_schieferstein
Active Contributor
0 Kudos
56

Hello Albert

Yes, is it very easy to find out at which textedit control the node was dropped. Make a copy of sample report <b>SAPTEXTEDIT_DEMO_DRAGDROP</b> and make the following changes:

<b>1. Resize the custom container on screen '0100' and add second custom container ('CONTAINER2').

2. Add additional references (TOP include):</b>

DATA:
      g_event_receiver         TYPE REF TO lcl_event_receiver,
      g_container              TYPE REF TO cl_gui_custom_container,
" New reference variables
      g_container2             type ref to cl_gui_custom_container,
      g_textedit2              type ref to cl_gui_textedit,
**      g_behaviour_textedit2    TYPE REF TO cl_dragdrop,  " NOTE: not required!!!

      g_splitter               TYPE REF TO
                                    cl_gui_easy_splitter_container,
...

<b>

3. Create 2nd container and textedit control (parent = g_container2 ).

4. Assign Drag&Drop behaviour to 2nd textedit control:</b>

* assign drag & drop object to TextEdit control
  CALL METHOD g_textedit->set_dragdrop
    EXPORTING
      dragdrop = g_behaviour_textedit.

  CALL METHOD g_textedit2->set_dragdrop
    EXPORTING
      dragdrop = g_behaviour_textedit.  " same behaviour !!!

<b>

5. Set event handler for 2nd textedit control:</b>

* set handler for (some of) the events of the TeextEdit control -------*
* will be called to perform actions on the drop target
  SET HANDLER g_event_receiver->handle_textedit_drop
    FOR g_textedit.
* will be called when more than one flavor matches between drag source
*  and drop target
  SET HANDLER g_event_receiver->select_textedit_flavor
    FOR g_textedit.

  SET HANDLER g_event_receiver->handle_textedit_drop
    FOR g_textedit2.
  SET HANDLER g_event_receiver->select_textedit_flavor
    FOR g_textedit2.

<b>6. And here is the "magic" piece of coding:</b>

  METHOD handle_tree_drop_complete.

    IF drag_drop_object->effect = cl_dragdrop=>move.
      CALL METHOD sender->delete_node
        EXPORTING
          node_key = node_key.
      DELETE g_node_table WHERE node_key = node_key.
    ENDIF.

    CASE drag_drop_object->droptargetctrl. " !!!
      WHEN g_textedit.
        MESSAGE 'Text dropped on 1st textedit control.' TYPE 'I'.

      WHEN g_textedit2.
        MESSAGE 'Text dropped on 2nd textedit control.' TYPE 'I'.
      WHEN OTHERS.
    ENDCASE.

  ENDMETHOD.                    "handle_tree_drop_complete

Regards

Uwe

0 Kudos
56

Hi Uwe,

Thanks for the response. Here is what I did

data : lcl_edit type ref to cl_gui_textedit.

catch system-exceptions move_cast_error = 1.

drag_object ?= dragdrop_object->object.

lcl_edit ?= dragdrop_object->droptargetctrl. "local copy of the text-editor

endcatch.

if sy-subrc = 1.

else.

endif.