]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AbstractEventAdapter.java
Fixed synchronousness problem in drag event transferable handling
[simantics/platform.git] / bundles / org.simantics.scenegraph / src / org / simantics / scenegraph / g2d / events / adapter / AbstractEventAdapter.java
index 0817c71dd70907ecb61104807432709c46580359..a0e0fd47feaecdf4f834db1d24230ac29b535413 100644 (file)
@@ -1,56 +1,65 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-/*\r
- *\r
- * @author Toni Kalajainen\r
- */\r
-package org.simantics.scenegraph.g2d.events.adapter;\r
-\r
-import org.simantics.scenegraph.g2d.events.Event;\r
-import org.simantics.scenegraph.g2d.events.EventTypes;\r
-import org.simantics.scenegraph.g2d.events.IEventHandler;\r
-import org.simantics.scenegraph.g2d.events.IEventQueue;\r
-\r
-/**\r
- * Adapts SWT, AWT and multitouch events\r
- */\r
-public abstract class AbstractEventAdapter {\r
-\r
-    /** Used for delegating events */\r
-    protected final IEventHandler delegator;\r
-    protected final IEventQueue   queue;\r
-    protected final Object        sender;\r
-\r
-    public AbstractEventAdapter(Object sender, IEventHandler delegator) {\r
-        if (delegator == null)\r
-            throw new IllegalArgumentException("null delegator");\r
-        this.delegator = delegator;\r
-        this.queue = null;\r
-        this.sender = sender;\r
-    }\r
-\r
-    public AbstractEventAdapter(Object sender, IEventQueue queue) {\r
-        if (queue == null)\r
-            throw new IllegalArgumentException("null event queue");\r
-        this.delegator = null;\r
-        this.queue = queue;\r
-        this.sender = sender;\r
-    }\r
-\r
-    protected void handleEvent(Event e) {\r
-        if (queue != null)\r
-            queue.queueEvent(e);\r
-        else if (EventTypes.passes(delegator, e))\r
-            delegator.handleEvent(e);\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+/*
+ *
+ * @author Toni Kalajainen
+ */
+package org.simantics.scenegraph.g2d.events.adapter;
+
+import org.simantics.scenegraph.g2d.events.Event;
+import org.simantics.scenegraph.g2d.events.EventTypes;
+import org.simantics.scenegraph.g2d.events.IEventHandler;
+import org.simantics.scenegraph.g2d.events.IEventQueue;
+
+/**
+ * Adapts SWT, AWT and multitouch events
+ */
+public abstract class AbstractEventAdapter {
+
+    /** Used for delegating events */
+    protected final IEventHandler delegator;
+    protected final IEventQueue   queue;
+    protected final Object        sender;
+
+    public AbstractEventAdapter(Object sender, IEventHandler delegator) {
+        if (delegator == null)
+            throw new IllegalArgumentException("null delegator");
+        this.delegator = delegator;
+        this.queue = null;
+        this.sender = sender;
+    }
+
+    public AbstractEventAdapter(Object sender, IEventQueue queue) {
+        if (queue == null)
+            throw new IllegalArgumentException("null event queue");
+        this.delegator = null;
+        this.queue = queue;
+        this.sender = sender;
+    }
+
+    protected void handleEvent(Event e) {
+        if (queue != null)
+            queue.queueEvent(e);
+        else if (EventTypes.passes(delegator, e))
+            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);
+    }
+
+}