X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.client.ui%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fviews%2FJcrResultListView.java;h=41a1d52d04c0a87638dcb7ae5df3ed31bebd05f5;hb=58b35f147f3c1c1a12a07c303105618f679c7161;hp=4bfb57c194a00f4a8d3fdc07a7d4fbcd8813fe2d;hpb=2db415932b071525adb52c6374e021174512a924;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrResultListView.java b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrResultListView.java index 4bfb57c19..41a1d52d0 100644 --- a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrResultListView.java +++ b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrResultListView.java @@ -1,18 +1,3 @@ -/* - * Copyright (C) 2007-2012 Argeo GmbH - * - * 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; @@ -34,12 +19,12 @@ 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.SlcNames; +import org.argeo.slc.SlcTypes; import org.argeo.slc.client.ui.ClientUiPlugin; import org.argeo.slc.client.ui.editors.ProcessEditor; import org.argeo.slc.client.ui.editors.ProcessEditorInput; import org.argeo.slc.jcr.SlcJcrResultUtils; -import org.argeo.slc.jcr.SlcNames; -import org.argeo.slc.jcr.SlcTypes; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.DoubleClickEvent; import org.eclipse.jface.viewers.IBaseLabelProvider; @@ -65,15 +50,20 @@ public class JcrResultListView extends ViewPart implements SlcNames { private TableViewer viewer; + private Repository repository; private Session session; private EventListener resultsObserver; - private DateFormat dateFormat = new SimpleDateFormat( - "EEE, dd MMM yyyy HH:mm:ss"); + private DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss"); private Integer queryLimit = 2000; public void createPartControl(Composite parent) { + try { + session = repository.login(); + } catch (RepositoryException e1) { + throw new SlcException("Cannot log in to repository"); + } Table table = createTable(parent); viewer = new TableViewer(table); @@ -87,14 +77,11 @@ public class JcrResultListView extends ViewPart implements SlcNames { resultsObserver = new ResultObserver(viewer.getTable().getDisplay()); try { - ObservationManager observationManager = session.getWorkspace() - .getObservationManager(); + ObservationManager observationManager = session.getWorkspace().getObservationManager(); String[] nodeTypes = { SlcTypes.SLC_TEST_RESULT }; // FIXME Will not be notified if empty result is deleted - observationManager.addEventListener(resultsObserver, - Event.PROPERTY_ADDED | Event.NODE_REMOVED, - SlcJcrResultUtils.getSlcResultsBasePath(session), true, - null, nodeTypes, false); + observationManager.addEventListener(resultsObserver, Event.PROPERTY_ADDED | Event.NODE_REMOVED, + SlcJcrResultUtils.getSlcResultsBasePath(session), true, null, nodeTypes, false); } catch (RepositoryException e) { throw new SlcException("Cannot register listeners", e); } @@ -102,8 +89,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { } protected Table createTable(Composite parent) { - int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL - | SWT.FULL_SELECTION | SWT.MULTI; + int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI; // does not work with RAP, commented for the time being // | SWT.HIDE_SELECTION; @@ -135,18 +121,14 @@ public class JcrResultListView extends ViewPart implements SlcNames { } protected void processDoubleClick(DoubleClickEvent evt) { - Object obj = ((IStructuredSelection) evt.getSelection()) - .getFirstElement(); + Object obj = ((IStructuredSelection) evt.getSelection()).getFirstElement(); 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(); - activePage.openEditor( - new ProcessEditorInput(node.getPath()), - ProcessEditor.ID); + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + activePage.openEditor(new ProcessEditorInput(node.getPath()), ProcessEditor.ID); } } } catch (Exception e) { @@ -159,19 +141,17 @@ public class JcrResultListView extends ViewPart implements SlcNames { } class ViewContentProvider implements IStructuredContentProvider { + private static final long serialVersionUID = -4719077015405546260L; public Object[] getElements(Object inputElement) { try { // TODO filter, optimize with virtual table, ... - String sql = "SELECT * from [" + SlcTypes.SLC_TEST_RESULT - + "] ORDER BY [jcr:lastModified] DESC"; - Query query = session.getWorkspace().getQueryManager() - .createQuery(sql, Query.JCR_SQL2); + String sql = "SELECT * from [" + SlcTypes.SLC_TEST_RESULT + "] ORDER BY [jcr:lastModified] DESC"; + Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2); // TODO paging query.setLimit(queryLimit); List nodes = new ArrayList(); - for (NodeIterator nit = query.execute().getNodes(); nit - .hasNext();) { + for (NodeIterator nit = query.execute().getNodes(); nit.hasNext();) { nodes.add(nit.nextNode()); } return nodes.toArray(); @@ -188,8 +168,8 @@ public class JcrResultListView extends ViewPart implements SlcNames { } - class ViewLabelProvider extends ColumnLabelProvider implements - ITableLabelProvider { + class ViewLabelProvider extends ColumnLabelProvider implements ITableLabelProvider { + private static final long serialVersionUID = -6323202576386795247L; public Image getColumnImage(Object obj, int columnIndex) { if (columnIndex != 0) @@ -212,9 +192,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { case 0: if (node.hasProperty(SLC_COMPLETED)) { - return dateFormat - .format(node.getProperty(SLC_COMPLETED) - .getDate().getTime()); + return dateFormat.format(node.getProperty(SLC_COMPLETED).getDate().getTime()); } else { return "OPEN"; } @@ -243,8 +221,7 @@ public class JcrResultListView extends ViewPart implements SlcNames { } @Override - protected Boolean willProcessInUiThread(List events) - throws RepositoryException { + protected Boolean willProcessInUiThread(List events) throws RepositoryException { for (Event event : events) { // getLog().debug("Received event " + event); int eventType = event.getType(); @@ -253,27 +230,20 @@ public class JcrResultListView extends ViewPart implements SlcNames { String path = event.getPath(); int index = path.lastIndexOf('/'); String propertyName = path.substring(index + 1); - if (propertyName.equals(SLC_COMPLETED) - || propertyName.equals(SLC_UUID)) { + if (propertyName.equals(SLC_COMPLETED) || propertyName.equals(SLC_UUID)) { return true; } } return false; } - protected void onEventInUiThread(List events) - throws RepositoryException { + protected void onEventInUiThread(List events) throws RepositoryException { if (getLog().isTraceEnabled()) getLog().trace("Refresh result list"); viewer.refresh(); } } - @Deprecated - public void setSession(Session session) { - this.session = session; - } - public void dispose() { JcrUtils.unregisterQuietly(session.getWorkspace(), resultsObserver); JcrUtils.logoutQuietly(session); @@ -281,11 +251,6 @@ public class JcrResultListView extends ViewPart implements SlcNames { } public void setRepository(Repository repository) { - try { - session = repository.login(); - } catch (RepositoryException re) { - throw new SlcException("Unable to log in Repository " + repository, - re); - } + this.repository = repository; } } \ No newline at end of file