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
.swt
.widgets
.Display
;
16 /** {@link EventListener} which simplifies running actions within the UI thread. */
17 public abstract class AsyncUiEventListener
implements EventListener
{
18 // private final static Log logSuper = LogFactory
19 // .getLog(AsyncUiEventListener.class);
20 private final Log logThis
= LogFactory
.getLog(getClass());
22 private final Display display
;
24 public AsyncUiEventListener(Display display
) {
26 this.display
= display
;
29 /** Called asynchronously in the UI thread. */
30 protected abstract void onEventInUiThread(List
<Event
> events
)
31 throws RepositoryException
;
34 * Whether these events should be processed in the UI or skipped with no UI
37 protected Boolean
willProcessInUiThread(List
<Event
> events
)
38 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 ArgeoException("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 display
.asyncExec(new Runnable() {
71 onEventInUiThread(events
);
72 } catch (RepositoryException e
) {
73 throw new ArgeoException("Cannot process events "
79 // return Status.OK_STATUS;