1 package org
.argeo
.eclipse
.ui
.jcr
;
3 import java
.util
.ArrayList
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.observation
.Event
;
8 import javax
.jcr
.observation
.EventIterator
;
9 import javax
.jcr
.observation
.EventListener
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.ArgeoException
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.core
.runtime
.jobs
.Job
;
18 import org
.eclipse
.swt
.widgets
.Display
;
20 /** {@link EventListener} which simplifies running actions within the UI thread. */
21 public abstract class AsyncUiEventListener
implements EventListener
{
22 private final static Log logSuper
= LogFactory
23 .getLog(AsyncUiEventListener
.class);
24 private final Log logThis
= LogFactory
.getLog(getClass());
26 private final Display display
;
28 public AsyncUiEventListener(Display display
) {
30 this.display
= display
;
33 /** Called asynchronously in the UI thread. */
34 protected abstract void onEventInUiThread(List
<Event
> events
)
35 throws RepositoryException
;
38 * Whether these events should be processed in the UI or skipped with no UI
41 protected Boolean
willProcessInUiThread(List
<Event
> events
)
42 throws RepositoryException
{
46 protected Log
getLog() {
50 public final void onEvent(final EventIterator eventIterator
) {
51 final List
<Event
> events
= new ArrayList
<Event
>();
52 while (eventIterator
.hasNext())
53 events
.add(eventIterator
.nextEvent());
55 if (logThis
.isDebugEnabled())
56 logThis
.debug("Received " + events
.size() + " events");
59 if (!willProcessInUiThread(events
))
61 } catch (RepositoryException e
) {
62 throw new ArgeoException("Cannot test skip events " + events
, e
);
65 // Job job = new Job("JCR Events") {
66 // protected IStatus run(IProgressMonitor monitor) {
67 // if (display.isDisposed()) {
68 // logSuper.warn("Display is disposed cannot update UI");
69 // return Status.CANCEL_STATUS;
72 display
.asyncExec(new Runnable() {
75 onEventInUiThread(events
);
76 } catch (RepositoryException e
) {
77 throw new ArgeoException("Cannot process events "
83 // return Status.OK_STATUS;