Since I migrated on Mars the drag and drop functionality of my RCP app is not working anymore.
After some debugging I found out a different behavior in Mars from Luna in this class org.eclipse.gef.ui.parts.DomainEventDispatcher in the method:
/**
* @see EventDispatcher#dispatchMouseMoved(org.eclipse.swt.events.MouseEvent)
*/
public void dispatchMouseMoved(org.eclipse.swt.events.MouseEvent me) {
if (!editorCaptured) {
super.dispatchMouseMoved(me);
if (draw2dBusy())
return;
}
if (okToDispatch()) {
if ((me.stateMask & InputEvent.ANY_BUTTON) != 0)
domain.mouseDrag(me, viewer);
else
domain.mouseMove(me, viewer);
}
}
The distinguish between mouseDrag and mouseMove is not revealed anymore because me.stateMask is 0 even when I am dragging the mouse (click and drag) inside the editor. Does anyone know if this is an Eclipse Bug or new behavior?
UPDATE:
I researched more and the problem doesn't come from there, but there is a method: receive(org.eclipse.swt.events.MouseEvent me) in the SWTEventDispatcher:
private void receive(org.eclipse.swt.events.MouseEvent me) {
currentEvent = null;
updateFigureUnderCursor(me);
if (captured) {
if (mouseTarget != null)
currentEvent = new MouseEvent(this, mouseTarget, me);
} else {
IFigure f = root.findMouseEventTargetAt(me.x, me.y);
if (f == mouseTarget) {
if (mouseTarget != null)
currentEvent = new MouseEvent(this, mouseTarget, me);
return;
}
if (mouseTarget != null) {
currentEvent = new MouseEvent(this, mouseTarget, me);
mouseTarget.handleMouseExited(currentEvent);
}
setMouseTarget(f);
if (mouseTarget != null) {
currentEvent = new MouseEvent(this, mouseTarget, me);
mouseTarget.handleMouseEntered(currentEvent);
}
}
}
In the specific case when I click on a figure/editpart, after dispatchMouseReleased is called (from SWTEventDispatcher), in the method receive(..), on Luna 'IFigure f = root.findMouseEventTargetAt(me.x, me.y);' is null and now on Mars it returns a Figure. This is the current difference I found that makes the drag and drop not work.
Yet..I don't understand what the difference is between Luna and Mars that org.eclipse.draw2d.findMouseEventTargetAt works differently.
So I managed to solve this problem.. org.eclipse.draw2d.Figure.findMouseEventTargetInDescendantsAt was changed from Luna to Mars.
in Luna we have this code:
if (fig.containsPoint(PRIVATE_POINT.x, PRIVATE_POINT.y)) {
fig = fig.findMouseEventTargetAt(PRIVATE_POINT.x,
PRIVATE_POINT.y);
return fig;
}
Mars:
if (fig.containsPoint(PRIVATE_POINT.x, PRIVATE_POINT.y)) {
fig = fig.findMouseEventTargetAt(PRIVATE_POINT.x,
PRIVATE_POINT.y);
if (fig != null) {
return fig;
}
}
I have my own class that extends LayeredPane and I had to override this method to always return the figure, even when it's null. Somehow in the receive(MouseEvent me) method from SWTEventDispatcher the root.findMouseEventTargetAt(me.x, me.y) should return null in the specific case a figure is being clicked and dragged but was returning a value != null.