X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fviews%2FJcrResultListView.java;h=322256b7194caf56c8d68c5e7f82676618757151;hb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;hp=11eb02fd07c9722dadbdff89b0ca5175a40af313;hpb=eef4888d3214ab92c5df3768d08c3e26269cc429;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java index 11eb02fd0..322256b71 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.client.ui.views; import java.text.DateFormat; @@ -7,16 +22,15 @@ import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; -import javax.jcr.Property; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.observation.Event; -import javax.jcr.observation.EventIterator; import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; import javax.jcr.query.Query; import org.argeo.eclipse.ui.jcr.AsyncUiEventListener; +import org.argeo.eclipse.ui.jcr.NodeElementComparer; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.editors.ProcessEditor; @@ -36,6 +50,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.ui.IWorkbenchPage; @@ -64,23 +79,20 @@ public class JcrResultListView extends ViewPart implements SlcNames { viewer.setContentProvider(new ViewContentProvider()); viewer.setInput(getViewSite()); viewer.addDoubleClickListener(new ViewDoubleClickListener()); + viewer.setComparer(new NodeElementComparer()); getViewSite().setSelectionProvider(viewer); - resultsObserver = new AsyncUiEventListener(viewer.getTable() - .getDisplay()) { - protected void onEventInUiThread(EventIterator events) { - // TODO optimize by updating only the changed result - viewer.refresh(); - } - }; + resultsObserver = new ResultObserver(viewer.getTable().getDisplay()); try { ObservationManager observationManager = session.getWorkspace() .getObservationManager(); + String[] nodeTypes = { SlcTypes.SLC_RESULT }; + // FIXME Will not be notified if empty result is deleted observationManager.addEventListener(resultsObserver, - Event.NODE_ADDED | Event.NODE_REMOVED - | Event.PROPERTY_CHANGED, - SlcJcrConstants.RESULTS_BASE_PATH, true, null, null, false); + Event.PROPERTY_ADDED | Event.NODE_REMOVED, + SlcJcrConstants.RESULTS_BASE_PATH, true, null, nodeTypes, + false); } catch (RepositoryException e) { throw new SlcException("Cannot register listeners", e); } @@ -126,6 +138,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { try { if (obj instanceof Node) { Node node = (Node) obj; + // FIXME: open a default result editor if (node.isNodeType(SlcTypes.SLC_PROCESS)) { IWorkbenchPage activePage = PlatformUI.getWorkbench() .getActiveWorkbenchWindow().getActivePage(); @@ -201,9 +214,13 @@ public class JcrResultListView extends ViewPart implements SlcNames { switch (index) { case 0: - return dateFormat.format(node - .getProperty(Property.JCR_LAST_MODIFIED).getDate() - .getTime()); + if (node.hasProperty(SLC_COMPLETED)) { + return dateFormat + .format(node.getProperty(SLC_COMPLETED) + .getDate().getTime()); + } else { + return "OPEN"; + } case 1: return node.getProperty(SlcNames.SLC_UUID).getString(); } @@ -222,6 +239,40 @@ public class JcrResultListView extends ViewPart implements SlcNames { } + class ResultObserver extends AsyncUiEventListener { + + public ResultObserver(Display display) { + super(display); + } + + @Override + protected Boolean willProcessInUiThread(List events) + throws RepositoryException { + for (Event event : events) { + // getLog().debug("Received event " + event); + int eventType = event.getType(); + if (eventType == Event.NODE_REMOVED) + return true; + String path = event.getPath(); + int index = path.lastIndexOf('/'); + String propertyName = path.substring(index + 1); + if (propertyName.equals(SLC_COMPLETED) + || propertyName.equals(SLC_UUID)) { + return true; + } + } + return false; + } + + protected void onEventInUiThread(List events) + throws RepositoryException { + if (getLog().isTraceEnabled()) + getLog().trace("Refresh result list"); + viewer.refresh(); + } + + } + public void setSession(Session session) { this.session = session; }