]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/views/JcrResultListView.java
Migrate SLC modules
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / views / JcrResultListView.java
index 322256b7194caf56c8d68c5e7f82676618757151..4bfb57c194a00f4a8d3fdc07a7d4fbcd8813fe2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * 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.
@@ -22,6 +22,7 @@ import java.util.List;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.observation.Event;
@@ -33,9 +34,10 @@ 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.ClientUiPlugin;
 import org.argeo.slc.client.ui.editors.ProcessEditor;
 import org.argeo.slc.client.ui.editors.ProcessEditorInput;
-import org.argeo.slc.jcr.SlcJcrConstants;
+import org.argeo.slc.jcr.SlcJcrResultUtils;
 import org.argeo.slc.jcr.SlcNames;
 import org.argeo.slc.jcr.SlcTypes;
 import org.eclipse.jface.viewers.ColumnLabelProvider;
@@ -59,7 +61,7 @@ import org.eclipse.ui.part.ViewPart;
 
 /** Displays results. */
 public class JcrResultListView extends ViewPart implements SlcNames {
-       public static final String ID = "org.argeo.slc.client.ui.jcrResultListView";
+       public static final String ID = ClientUiPlugin.ID + ".jcrResultListView";
 
        private TableViewer viewer;
 
@@ -87,12 +89,12 @@ public class JcrResultListView extends ViewPart implements SlcNames {
                try {
                        ObservationManager observationManager = session.getWorkspace()
                                        .getObservationManager();
-                       String[] nodeTypes = { SlcTypes.SLC_RESULT };
+                       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,
-                                       SlcJcrConstants.RESULTS_BASE_PATH, true, null, nodeTypes,
-                                       false);
+                                       SlcJcrResultUtils.getSlcResultsBasePath(session), true,
+                                       null, nodeTypes, false);
                } catch (RepositoryException e) {
                        throw new SlcException("Cannot register listeners", e);
                }
@@ -156,18 +158,13 @@ public class JcrResultListView extends ViewPart implements SlcNames {
                viewer.getControl().setFocus();
        }
 
-       @Override
-       public void dispose() {
-               JcrUtils.unregisterQuietly(session.getWorkspace(), resultsObserver);
-               super.dispose();
-       }
-
        class ViewContentProvider implements IStructuredContentProvider {
 
                public Object[] getElements(Object inputElement) {
                        try {
                                // TODO filter, optimize with virtual table, ...
-                               String sql = "SELECT * from [slc:result] ORDER BY [jcr:lastModified] DESC";
+                               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
@@ -270,11 +267,25 @@ public class JcrResultListView extends ViewPart implements SlcNames {
                                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);
+               super.dispose();
+       }
+
+       public void setRepository(Repository repository) {
+               try {
+                       session = repository.login();
+               } catch (RepositoryException re) {
+                       throw new SlcException("Unable to log in Repository " + repository,
+                                       re);
+               }
+       }
 }
\ No newline at end of file