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
.argeo
.api
.cms
.CmsLog
;
12 import org
.argeo
.eclipse
.ui
.EclipseUiException
;
13 import org
.eclipse
.swt
.widgets
.Display
;
16 * {@link EventListener} which simplifies running actions within the UI thread.
18 public abstract class AsyncUiEventListener
implements EventListener
{
19 // private final static Log logSuper = LogFactory
20 // .getLog(AsyncUiEventListener.class);
21 private final CmsLog logThis
= CmsLog
.getLog(getClass());
23 private final Display display
;
25 public AsyncUiEventListener(Display display
) {
27 this.display
= display
;
30 /** Called asynchronously in the UI thread. */
31 protected abstract void onEventInUiThread(List
<Event
> events
) throws RepositoryException
;
34 * Whether these events should be processed in the UI or skipped with no UI
37 protected Boolean
willProcessInUiThread(List
<Event
> events
) throws RepositoryException
{
41 protected CmsLog
getLog() {
45 public final void onEvent(final EventIterator eventIterator
) {
46 final List
<Event
> events
= new ArrayList
<Event
>();
47 while (eventIterator
.hasNext())
48 events
.add(eventIterator
.nextEvent());
50 if (logThis
.isTraceEnabled())
51 logThis
.trace("Received " + events
.size() + " events");
54 if (!willProcessInUiThread(events
))
56 } catch (RepositoryException e
) {
57 throw new EclipseUiException("Cannot test skip events " + events
, e
);
60 // Job job = new Job("JCR Events") {
61 // protected IStatus run(IProgressMonitor monitor) {
62 // if (display.isDisposed()) {
63 // logSuper.warn("Display is disposed cannot update UI");
64 // return Status.CANCEL_STATUS;
67 if (!display
.isDisposed())
68 display
.asyncExec(new Runnable() {
71 onEventInUiThread(events
);
72 } catch (RepositoryException e
) {
73 throw new EclipseUiException("Cannot process events " + events
, e
);
78 // return Status.OK_STATUS;