Process Flow of a Drag and Drop Operation
The following section explains how a drag and drop operation works, examining into the roles of the application server and frontend, and going on to identify the individual steps required to program drag and drop in an application.
You create the
You register the
drag and drop events.
You define the drag and drop behavior for the individual custom controls or their components. To do this, you create an
instance of the class
CL_DRAGDROP. You then
assign one or more flavors to this instance. These describe the drag and drop behavior of the relevant custom control. During the program, you can
query the flavors in your program. You can also
destroy the entire instance.
You assign flavors to the custom control using specific methods of the relevant control. For further information, refer to the corresponding control documentation.
The following steps are performed by the system at the frontend. They are only listed here so that you can understand what happens during a drag and drop operation. Once the use has selected an object with the left mouse button, the drag and drop service starts.
The drag and drop service checks whether a drag and drop behavior has been defined for the object, and whether the object can be dragged (DragSource attribute).
If, according to the DragSource attribute, the object can be dragged, the drag and drop operation starts. The mouse pointer then changes automatically.
As long as the left mouse button remains pressed, the system continually checks whether the mouse pointer is positioned over an object in a custom control that can receive a dropped object (DropTarget attribute), and whether the flavor of that object is the same as the flavor of the source. If this is the case, the mouse pointer changes again to inform the user.
If the user now drops the object, an event is triggered to inform the application server.
This concludes the drag and drop operation for the frontend. However, there has not yet been any change to the contents of the custom control.
The drag and drop service of the application server creates an instance of the class
CL_DRAGDROPOBJECT. You can use this instance (for example,
) in all events of the drag and drop process as an event parameter. You can use it to find out the context between the events.
The drag and drop service checks whether the drag object and drop object have more than one flavor in common. If this is the case, the event
is triggered. In the corresponding handler method, you must decide which flavor to use. You do this using the method
Now, the drag and drop event
is triggered. It has event parameters that tell you which object the user has dragged. Within the handler routine, you must pass the context (information about the source object) to the instance of the drag and drop data object created in step 9.
drag_drop_object->object = mydragobject.
event is triggered. The corresponding handler method serves to process the drag and drop data object. Here, you have to implement the changes that are to be made to the target object based on the drag and drop operation.
The last event of the drag and drop operation is
. This is where you can make your last changes to the drag and drop object. In particular, you should use this event to delete the source object from the DragSource control and the corresponding data structures if you have used the drag and drop operation to move the object.
Example of Drag and Drop Programming contains an example of a drag and drop operation between a SAP Tree and a SAP Textedit.