From 8257c30918a213e580e048171078c7689926d68f Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 28 Sep 2018 09:19:02 +0300 Subject: [PATCH] Fixed synchronousness problem in drag event transferable handling Previously handleEvent would post the event for asynchronous handling while handling the drag starting via Transferable requires the drag to be started synchronously within the AWT drag start event handler. Added syncHandleEvent to AbstractEventHandler to support this. gitlab #112 Change-Id: I694844fbfc1be74b9f6b620afc8fc441a0ab4d31 (cherry picked from commit 96ae58fda842dcd8266192eeb1399324b092154a) --- .../src/org/simantics/diagram/elements/TextNode.java | 1 - .../g2d/events/adapter/AWTMouseEventAdapter.java | 2 +- .../g2d/events/adapter/AbstractEventAdapter.java | 9 +++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java index 43653cbd0..0b33ae3c4 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java @@ -62,7 +62,6 @@ import org.simantics.scenegraph.g2d.events.MouseEvent.MouseClickEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin; import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent; -import org.simantics.scenegraph.g2d.events.NodeEventHandler; import org.simantics.scenegraph.g2d.events.command.CommandEvent; import org.simantics.scenegraph.g2d.events.command.Commands; import org.simantics.scenegraph.utils.GeometryUtils; diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AWTMouseEventAdapter.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AWTMouseEventAdapter.java index e01876c6d..d5b2aac41 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AWTMouseEventAdapter.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AWTMouseEventAdapter.java @@ -317,7 +317,7 @@ public class AWTMouseEventAdapter extends AbstractEventAdapter implements MouseL controlPos, getScreenPosition(e)); - handleEvent(event); + syncHandleEvent(event); if (event.transferable != null) { ds.startDrag(dge, null, event.transferable, null); diff --git a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java index ef7184568..a0e0fd47f 100644 --- a/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java +++ b/bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java @@ -53,4 +53,13 @@ public abstract class AbstractEventAdapter { delegator.handleEvent(e); } + protected void syncHandleEvent(Event e) { + if (queue instanceof IEventHandler) + ((IEventHandler) queue).handleEvent(e); + else if (delegator != null && EventTypes.passes(delegator, e)) + delegator.handleEvent(e); + else + throw new UnsupportedOperationException("Cannot handle event synchronously, no handler available: " + e); + } + } -- 2.47.1