From 2247846769e070a9005cab307e630de83e52c94e Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sun, 26 Jun 2011 21:14:30 +0000 Subject: [PATCH] Provide Display to ui event listener git-svn-id: https://svn.argeo.org/commons/trunk@4610 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../eclipse/ui/jcr/AsyncUiEventListener.java | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) 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 index a54f63e69..6a83ef374 100644 --- 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 @@ -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); + // } + // }); } } -- 2.30.2