X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.client.ui%2Fsrc%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fviews%2FJcrProcessListView.java;h=7a921441f6a101623b2e6545ba2c4fd3b24bd21b;hb=e07ded4632e53f8b8869763bc1f1f4091361e76e;hp=8ab5c8f6f74dce185f458fff569cd6ccafdbd8d3;hpb=4644a05f259abb229a77ef7203687e139f01939a;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrProcessListView.java b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrProcessListView.java index 8ab5c8f6f..7a921441f 100644 --- a/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrProcessListView.java +++ b/org.argeo.slc.client.ui/src/org/argeo/slc/client/ui/views/JcrProcessListView.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; @@ -31,17 +16,18 @@ import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; import javax.jcr.query.Query; +import org.argeo.api.NodeConstants; import org.argeo.eclipse.ui.jcr.AsyncUiEventListener; 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.SlcImages; import org.argeo.slc.client.ui.editors.ProcessEditor; import org.argeo.slc.client.ui.editors.ProcessEditorInput; import org.argeo.slc.execution.ExecutionProcess; import org.argeo.slc.jcr.SlcJcrUtils; -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.IDoubleClickListener; @@ -50,6 +36,7 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.rap.rwt.service.ServerPushSession; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; @@ -64,22 +51,23 @@ public class JcrProcessListView extends ViewPart { public static final String ID = ClientUiPlugin.ID + ".jcrProcessListView"; private TableViewer viewer; + private ServerPushSession pushSession; private Repository repository; private Session session; private EventListener processesObserver; - 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) { + pushSession = new ServerPushSession(); + pushSession.start(); try { - session = repository.login(); + session = repository.login(NodeConstants.HOME_WORKSPACE); } catch (RepositoryException re) { - throw new SlcException("Unable to log in Repository " + repository, - re); + throw new SlcException("Unable to log in Repository " + repository, re); } Table table = createTable(parent); viewer = new TableViewer(table); @@ -88,21 +76,17 @@ public class JcrProcessListView extends ViewPart { viewer.setInput(getViewSite()); viewer.addDoubleClickListener(new ViewDoubleClickListener()); - processesObserver = new AsyncUiEventListener(viewer.getTable() - .getDisplay()) { + processesObserver = new AsyncUiEventListener(viewer.getTable().getDisplay()) { protected void onEventInUiThread(List events) { // TODO optimize by updating only the changed process viewer.refresh(); } }; try { - ObservationManager observationManager = session.getWorkspace() - .getObservationManager(); + ObservationManager observationManager = session.getWorkspace().getObservationManager(); observationManager.addEventListener(processesObserver, - Event.NODE_ADDED | Event.NODE_REMOVED - | Event.PROPERTY_CHANGED, - SlcJcrUtils.getSlcProcessesBasePath(session), true, null, - null, false); + Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_CHANGED, + SlcJcrUtils.getSlcProcessesBasePath(session), true, null, null, false); } catch (RepositoryException e) { throw new SlcException("Cannot register listeners", e); } @@ -110,8 +94,7 @@ public class JcrProcessListView extends ViewPart { } protected Table createTable(Composite parent) { - int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL - | SWT.FULL_SELECTION; + int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION; // does not function with RAP, commented for the time being // | SWT.HIDE_SELECTION; @@ -149,13 +132,11 @@ public class JcrProcessListView extends ViewPart { try { // TODO filter, optimize with virtual table, ... String sql = "SELECT * from [slc:process] ORDER BY [jcr:lastModified] DESC"; - Query query = session.getWorkspace().getQueryManager() - .createQuery(sql, Query.JCR_SQL2); + 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(); @@ -172,22 +153,18 @@ public class JcrProcessListView extends ViewPart { } - class LabelProvider extends ColumnLabelProvider implements - ITableLabelProvider { + class LabelProvider extends ColumnLabelProvider implements ITableLabelProvider { public Image getColumnImage(Object obj, int columnIndex) { if (columnIndex != 0) return null; try { Node node = (Node) obj; - String status = node.getProperty(SlcNames.SLC_STATUS) - .getString(); - if (status.equals(ExecutionProcess.NEW) - || status.equals(ExecutionProcess.INITIALIZED) + String status = node.getProperty(SlcNames.SLC_STATUS).getString(); + if (status.equals(ExecutionProcess.NEW) || status.equals(ExecutionProcess.INITIALIZED) || status.equals(ExecutionProcess.SCHEDULED)) return SlcImages.PROCESS_SCHEDULED; - else if (status.equals(ExecutionProcess.ERROR) - || status.equals(ExecutionProcess.UNKOWN)) + else if (status.equals(ExecutionProcess.ERROR) || status.equals(ExecutionProcess.UNKOWN)) return SlcImages.PROCESS_ERROR; else if (status.equals(ExecutionProcess.COMPLETED)) return SlcImages.PROCESS_COMPLETED; @@ -208,9 +185,7 @@ public class JcrProcessListView extends ViewPart { switch (index) { case 0: - return dateFormat.format(node - .getProperty(Property.JCR_LAST_MODIFIED).getDate() - .getTime()); + return dateFormat.format(node.getProperty(Property.JCR_LAST_MODIFIED).getDate().getTime()); case 1: return "local"; case 2: @@ -228,17 +203,14 @@ public class JcrProcessListView extends ViewPart { class ViewDoubleClickListener implements IDoubleClickListener { public void doubleClick(DoubleClickEvent evt) { - Object obj = ((IStructuredSelection) evt.getSelection()) - .getFirstElement(); + Object obj = ((IStructuredSelection) evt.getSelection()).getFirstElement(); try { if (obj instanceof Node) { Node node = (Node) obj; 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) { @@ -251,6 +223,8 @@ public class JcrProcessListView extends ViewPart { public void dispose() { JcrUtils.unregisterQuietly(session.getWorkspace(), processesObserver); JcrUtils.logoutQuietly(session); + if (pushSession != null) + pushSession.stop(); super.dispose(); }