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
.eclipse
.ui
.EclipseUiException
;
14 import org
.eclipse
.swt
.widgets
.Display
;
17 * {@link EventListener} which simplifies running actions within the UI thread.
19 public abstract class AsyncUiEventListener
implements EventListener
{
20 // private final static Log logSuper = LogFactory
21 // .getLog(AsyncUiEventListener.class);
22 private final Log logThis
= LogFactory
.getLog(getClass());
24 private final Display display
;
26 public AsyncUiEventListener(Display display
) {
28 this.display
= display
;
31 /** Called asynchronously in the UI thread. */
32 protected abstract void onEventInUiThread(List
<Event
> events
) throws RepositoryException
;
35 * Whether these events should be processed in the UI or skipped with no UI
38 protected Boolean
willProcessInUiThread(List
<Event
> events
) throws RepositoryException
{
42 protected Log
getLog() {
46 public final void onEvent(final EventIterator eventIterator
) {
47 final List
<Event
> events
= new ArrayList
<Event
>();
48 while (eventIterator
.hasNext())
49 events
.add(eventIterator
.nextEvent());
51 if (logThis
.isTraceEnabled())
52 logThis
.trace("Received " + events
.size() + " events");
55 if (!willProcessInUiThread(events
))
57 } catch (RepositoryException e
) {
58 throw new EclipseUiException("Cannot test skip events " + events
, e
);
61 // Job job = new Job("JCR Events") {
62 // protected IStatus run(IProgressMonitor monitor) {
63 // if (display.isDisposed()) {
64 // logSuper.warn("Display is disposed cannot update UI");
65 // return Status.CANCEL_STATUS;
68 if (!display
.isDisposed())
69 display
.asyncExec(new Runnable() {
72 onEventInUiThread(events
);
73 } catch (RepositoryException e
) {
74 throw new EclipseUiException("Cannot process events " + events
, e
);
79 // return Status.OK_STATUS;