Provide Display to ui event listener
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 26 Jun 2011 21:14:30 +0000 (21:14 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 26 Jun 2011 21:14:30 +0000 (21:14 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4610 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java

index a54f63e69a9fdfc70442e755f454354610a7c6c1..6a83ef3749d3e89d4d66f141fe439fb0732499e4 100644 (file)
@@ -3,18 +3,44 @@ package org.argeo.eclipse.ui.jcr;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
 
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Display;
 
 /** {@link EventListener} which simplifies running actions within the UI thread. */
 public abstract class AsyncUiEventListener implements EventListener {
+       private final Display display;
+       
+       public AsyncUiEventListener(Display display) {
+               super();
+               this.display = display;
+       }
+
        /** 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);
+               Job job = new Job("JCR Events") {
+                       protected IStatus run(IProgressMonitor monitor) {
+                               //Display display = Display.getCurrent();
+                               //Display display = PlatformUI.getWorkbench().getDisplay();
+
+                               display.asyncExec(new Runnable() {
+                                       public void run() {
+                                               onEventInUiThread(events);
+                                       }
+                               });
+                               return Status.OK_STATUS;
                        }
-               });
+               };
+               job.schedule();
+
+               // PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+               // public void run() {
+               // onEventInUiThread(events);
+               // }
+               // });
        }
 }