Asynchornous UI thread event listener
authorMathieu Baudier <mbaudier@argeo.org>
Tue, 19 Apr 2011 19:01:33 +0000 (19:01 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Tue, 19 Apr 2011 19:01:33 +0000 (19:01 +0000)
NEW - bug 17: Generalize agent management and registration beyond JMS
https://bugzilla.argeo.org/show_bug.cgi?id=17

git-svn-id: https://svn.argeo.org/commons/trunk@4456 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java [new file with mode: 0644]

diff --git a/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java b/eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java
new file mode 100644 (file)
index 0000000..a54f63e
--- /dev/null
@@ -0,0 +1,20 @@
+package org.argeo.eclipse.ui.jcr;
+
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+
+import org.eclipse.ui.PlatformUI;
+
+/** {@link EventListener} which simplifies running actions within the UI thread. */
+public abstract class AsyncUiEventListener implements EventListener {
+       /** Called asynchronously in the UI thread. */
+       protected abstract void onEventInUiThread(EventIterator events);
+
+       public void onEvent(final EventIterator events) {
+               PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+                       public void run() {
+                               onEventInUiThread(events);
+                       }
+               });
+       }
+}