Papyrus/Papyrus Developer Guide/Papyrus Structure Behavior
will be done...
Model Explorer: Internal drag and drop
This documentation explains the drag and drag from the model explorer to the model explorer.
The drag and drop is done thanks to the class org.eclipse.papyrus.modelexplorer.dnd.CommonDropAdapterAssistant.
This class is referenced into the eclipse framework by using the extension point org.eclipse.ui.navigator.navigatorContent
It contains an attribute drop assistant. See the following example:
<dropAssistant class="org.eclipse.papyrus.modelexplorer.dnd.CommonDropAdapterAssistant" id="org.eclipse.papyrus.modelexplorer.dnd.CommonDropAdapterAssistant"> <possibleDropTargets> <or> <instanceof value="org.eclipse.gmf.runtime.notation.impl.DiagramImpl"> </instanceof> <adapt type="org.eclipse.emf.ecore.EObject"> </adapt> </or></possibleDropTargets> </dropAssistant>
To do the concrete drop, the following method has to be implemented:
public abstract IStatus handleDrop(CommonDropAdapter aDropAdapter,DropTargetEvent aDropTargetEvent, Object aTarget);
In the subclass, the handleDrop method asks and executes a command. I separate the problem of construction of the commands of its execution.
The creation of the command is done into the method getDrop()
There are several cases of the drop event:
The mouse is placed just before an element
The mouse is placed just after an element
The mouse is placed on an element
The first two events are changments of order, we call the getChangeOrder in charge of building orders to rearrange the elements
For Location_on, this is a change of container, we call the method getDropIntoCommand in charge of creating the command to change container.
The operation is quite simple: It is to create a query such as MoveRequest with child elements. If a child is a diagram, it requires a specific command to change the parent of the diagram.
This algorithm is more complicated. If we move the elements before or after another, there may be changes in container. It is therefore essential to create a MoveRequest in order to ensure semantics and graphic consistency thanks to the Edit Service.
For this we test the first selected item if the list that moves. We test if there is a change of parent. If it is, a MoveRequest with all the children will be built and a move command is executed.
Since then we specify the position of the (LOCATION_AFTER, LOCATION_BEFORE) you have to build a request such SetRequest. The collection of future collection is calculated (location of children in the future collection)
All command are inside a commpound command in order to ensure a atomic do, undo , redo.