import org.argeo.eclipse.ui.dialogs.SingleValue;
import org.argeo.slc.SlcException;
import org.argeo.slc.client.ui.ClientUiPlugin;
+import org.argeo.slc.client.ui.model.ParentNodeFolder;
import org.argeo.slc.client.ui.model.ResultFolder;
import org.argeo.slc.jcr.SlcJcrResultUtils;
import org.eclipse.core.commands.AbstractHandler;
// Sanity check, already done when populating the corresponding popup
// menu.
- if (selection != null && selection.size() == 1
- && selection.getFirstElement() instanceof ResultFolder) {
- ResultFolder rf = (ResultFolder) selection.getFirstElement();
+ if (selection != null && selection.size() == 1) {
+ Object obj = selection.getFirstElement();
+
try {
- String folderName = SingleValue.ask("Folder name",
- "Enter folder name");
- if (folderName != null) {
- Node parentNode = rf.getNode();
- String absPath = parentNode.getPath()+ "/"
- + folderName;
- SlcJcrResultUtils.createResultFolderNode(
- parentNode.getSession(), absPath);
+ Node parentNode = null;
+
+ if (obj instanceof ResultFolder) {
+ ResultFolder rf = (ResultFolder) obj;
+ parentNode = rf.getNode();
+ } else if (obj instanceof ParentNodeFolder) {
+ Node node = ((ParentNodeFolder) obj).getNode();
+ if (node.getPath().startsWith(
+ SlcJcrResultUtils.getMyResultsBasePath(node
+ .getSession())))
+ parentNode = node;
+ }
+
+ if (parentNode != null) {
+ String folderName = SingleValue.ask("Folder name",
+ "Enter folder name");
+ if (folderName != null) {
+ String absPath = parentNode.getPath() + "/"
+ + folderName;
+ SlcJcrResultUtils.createResultFolderNode(
+ parentNode.getSession(), absPath);
+ }
}
} catch (RepositoryException e) {
throw new SlcException(
\r
import org.argeo.eclipse.ui.ErrorFeedback;\r
import org.argeo.slc.client.ui.model.ResultFolder;\r
+import org.argeo.slc.client.ui.model.ResultParentUtils;\r
import org.argeo.slc.client.ui.model.SingleResultNode;\r
+import org.argeo.slc.jcr.SlcNames;\r
import org.eclipse.core.commands.AbstractHandler;\r
import org.eclipse.core.commands.ExecutionEvent;\r
import org.eclipse.core.commands.ExecutionException;\r
for (final String path : nodes) {\r
if (session.itemExists(path)) {\r
node = session.getNode(path);\r
+ Node parent = node.getParent();\r
node.remove();\r
+ ResultParentUtils.updateStatusOnRemoval(parent);\r
}\r
monitor.worked(1);\r
}\r
*/
package org.argeo.slc.client.ui.decorators;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.argeo.slc.client.ui.ClientUiPlugin;
import org.argeo.slc.client.ui.model.ResultParent;
import org.eclipse.jface.resource.ImageDescriptor;
public class ResultFailedDecorator extends LabelProvider implements
ILabelDecorator {
- private final static Log log = LogFactory
- .getLog(ResultFailedDecorator.class);
+ // private final static Log log = LogFactory
+ // .getLog(ResultFailedDecorator.class);
public ResultFailedDecorator() {
super();
// decorates resource icon with basic decorations provided
// by Eclipse
if (object instanceof ResultParent) {
- log.debug("decorate : " + ((ResultParent) object).getName()
- + " - passed : " + ((ResultParent) object).isPassed());
if (!((ResultParent) object).isPassed()) {
ImageDescriptor desc = ClientUiPlugin.getDefault()
.getWorkbench().getSharedImages()
--- /dev/null
+/*
+ * 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.model;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
+
+import org.argeo.slc.SlcException;
+import org.argeo.slc.jcr.SlcJcrResultUtils;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+
+/**
+ * UI Tree component that wrap a node of type NT_UNSTRUCTURED. list either
+ * result folders, other folders and/or a list of results. keeps a reference to
+ * its parent.
+ */
+public class ParentNodeFolder extends ResultParent {
+
+ private Node node = null;
+
+ /**
+ *
+ * @param parent
+ * @param node
+ * throws an exception if null
+ * @param name
+ */
+ public ParentNodeFolder(ParentNodeFolder parent, Node node, String name) {
+ super(name);
+ if (node == null)
+ throw new SlcException("Node Object cannot be null");
+ setParent(parent);
+ this.node = node;
+ }
+
+ @Override
+ protected void initialize() {
+ try {
+ NodeIterator ni = node.getNodes();
+ while (ni.hasNext()) {
+ Node currNode = ni.nextNode();
+ if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) {
+ SingleResultNode srn = new SingleResultNode(this, currNode,
+ currNode.getProperty(SlcNames.SLC_TEST_CASE)
+ .getString());
+ addChild(srn);
+ } else if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {
+ // FIXME change label
+ ResultFolder rf = new ResultFolder(this, currNode,
+ currNode.getName());
+ addChild(rf);
+ } else if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
+ addChild(new ParentNodeFolder(this, currNode,
+ currNode.getName()));
+ }
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while initializing simple node folder : "
+ + getName(), re);
+ }
+ }
+
+ @Override
+ public synchronized void dispose() {
+ super.dispose();
+ }
+
+ public Node getNode() {
+ return node;
+ }
+
+ /**
+ * Overriden in the specific case of "My result" root object to return an
+ * ordered list of children
+ */
+ public synchronized Object[] getChildren() {
+ Object[] children = super.getChildren();
+ try {
+ if (node.getPath().equals(
+ SlcJcrResultUtils.getMyResultsBasePath(node.getSession())))
+ return ResultParentUtils.orderChildren(children);
+ else
+ return children;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while initializing simple node folder : "
+ + getName(), re);
+ }
+ }
+}
\ No newline at end of file
* UI Tree component that wrap a node of type ResultFolder. list either other
* folders and/or a list of results. keeps a reference to its parent.
*/
-public class ResultFolder extends ResultParent {
+public class ResultFolder extends ResultParent implements Comparable<ResultFolder> {
private Node node = null;
* throws an exception if null
* @param name
*/
- public ResultFolder(ResultFolder parent, Node node, String name) {
+ public ResultFolder(ResultParent parent, Node node, String name) {
super(name);
try {
if (node == null)
throw new SlcException("Node Object cannot be null");
setParent(parent);
this.node = node;
- // initialize passed status
- setPassed(node.getNode(SlcNames.SLC_STATUS)
- .getProperty(SlcNames.SLC_SUCCESS).getBoolean());
+ // initialize passed status if possible
+ if (node.hasNode(SlcNames.SLC_STATUS))
+ setPassed(node.getNode(SlcNames.SLC_STATUS)
+ .getProperty(SlcNames.SLC_SUCCESS).getBoolean());
} catch (RepositoryException re) {
throw new SlcException(
"Unexpected error while initializing result folder : "
return node;
}
- // /** Override normal behavior to initialize display */
- // @Override
- // public synchronized Object[] getChildren() {
- // if (isLoaded()) {
- // return super.getChildren();
- // } else {
- // // initialize current object
- // try {
- // if (node != null) {
- // NodeIterator ni = node.getNodes();
- // while (ni.hasNext()) {
- // Node currNode = ni.nextNode();
- // if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT))
- // addChild(new SingleResultNode(this, node, node
- // .getProperty(SlcNames.SLC_TEST_CASE)
- // .getString()));
- // else if (currNode
- // .isNodeType(SlcTypes.SLC_RESULT_FOLDER))
- // addChild(new ResultFolder(this, node,
- // node.getName()));
- // }
- // }
- // return super.getChildren();
- // } catch (RepositoryException e) {
- // throw new ArgeoException(
- // "Cannot initialize WorkspaceNode UI object."
- // + getName(), e);
- // }
- // }
- // }
-
- // @Override
- // public boolean refreshPassedStatus() {
- // Object[] children = getChildren();
- // isPassed = true;
- // checkChildrenStatus: for (int i = 0; i <= children.length; i++) {
- // if (children[i] instanceof ResultFolder) {
- //
- // }
- // if (!((ResultParent) children[i]).isPassed()) {
- // isPassed = false;
- // break checkChildrenStatus;
- // }
- // }
- // return isPassed;
- // }
+ /**
+ * Overriden to return an ordered list of children
+ */
+ public synchronized Object[] getChildren() {
+ Object[] children = super.getChildren();
+ return ResultParentUtils.orderChildren(children);
+ }
+ public int compareTo(ResultFolder o) {
+ return super.compareTo(o);
+ }
}
\ No newline at end of file
--- /dev/null
+package org.argeo.slc.client.ui.model;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+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.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.jcr.SlcJcrResultUtils;
+import org.argeo.slc.jcr.SlcNames;
+import org.argeo.slc.jcr.SlcTypes;
+
+public class ResultParentUtils {
+ private final static Log log = LogFactory.getLog(ResultParentUtils.class);
+
+ public static Object[] orderChildren(Object[] children) {
+ List<ResultFolder> folders = new ArrayList<ResultFolder>();
+ List<SingleResultNode> results = new ArrayList<SingleResultNode>();
+ for (Object child : children) {
+ if (child instanceof ResultFolder)
+ folders.add((ResultFolder) child);
+ else if (child instanceof SingleResultNode)
+ results.add((SingleResultNode) child);
+ }
+
+ // Comparator first = Collections.reverseOrder();
+ Collections.sort(folders);
+ // Comparator<SingleResultNode> second = Collections.reverseOrder();
+ Collections.sort(results);
+
+ Object[] orderedChildren = new Object[children.length];
+ int i = 0;
+ Iterator<ResultFolder> it = folders.iterator();
+ while (it.hasNext()) {
+ orderedChildren[i] = it.next();
+ i++;
+ }
+ Iterator<SingleResultNode> it2 = results.iterator();
+ while (it2.hasNext()) {
+ orderedChildren[i] = it2.next();
+ i++;
+ }
+ return orderedChildren;
+ }
+
+ public static ResultParent[] getResultsForDates(Session session,
+ List<String> dateRelPathes) {
+ if (dateRelPathes == null || dateRelPathes.size() == 0)
+ throw new SlcException("Specify at least one correct date as Path");
+
+ try {
+ String basePath = SlcJcrResultUtils.getSlcResultsBasePath(session);
+ Iterator<String> it = dateRelPathes.iterator();
+ StringBuffer clause = new StringBuffer();
+ clause.append("SELECT * FROM [");
+ clause.append(SlcTypes.SLC_DIFF_RESULT);
+ clause.append("] as results");
+ clause.append(" WHERE ");
+ while (it.hasNext()) {
+ String absPath = basePath + "/" + it.next();
+ clause.append("ISDESCENDANTNODE(results, [");
+ clause.append(absPath);
+ clause.append("]) ");
+ clause.append(" OR ");
+ }
+ // remove last " OR "
+ clause.delete(clause.length() - 4, clause.length());
+ clause.append(" ORDER BY results.[" + Property.JCR_CREATED
+ + "] DESC");
+
+ // log.debug("request : " + clause.toString());
+ QueryManager qm = session.getWorkspace().getQueryManager();
+ Query q = qm.createQuery(clause.toString(), Query.JCR_SQL2);
+ QueryResult result = q.execute();
+
+ NodeIterator ni = result.getNodes();
+ ResultParent[] results = new ResultParent[(int) ni.getSize()];
+ int i = 0;
+ while (ni.hasNext()) {
+ Node currNode = ni.nextNode();
+ SingleResultNode srn = new SingleResultNode(null, currNode,
+ currNode.getProperty(SlcNames.SLC_TEST_CASE)
+ .getString());
+
+ results[i] = srn;
+ i++;
+ }
+ return results;
+ } catch (RepositoryException re) {
+ throw new SlcException(
+ "Unexpected error while getting Results for given date", re);
+ }
+ }
+
+ /**
+ * recursively update passed status of the parent ResultFolder and its
+ * parent if needed
+ *
+ * @param node
+ * cannot be null
+ *
+ */
+ public static void updatePassedStatus(Node node, boolean passed) {
+ try {
+ Node pNode = node.getParent();
+ if (!pNode.hasNode(SlcNames.SLC_STATUS))
+ // we have reached the root of the tree. stop the
+ // recursivity
+ return;
+ boolean pStatus = pNode.getNode(SlcNames.SLC_STATUS)
+ .getProperty(SlcNames.SLC_SUCCESS).getBoolean();
+ if (pStatus == passed)
+ // nothing to update
+ return;
+ else if (!passed) {
+ // error we only update status of the result folder and its
+ // parent if needed
+ pNode.getNode(SlcNames.SLC_STATUS).setProperty(
+ SlcNames.SLC_SUCCESS, passed);
+ updatePassedStatus(pNode, passed);
+ } else {
+ // success we must first check if all siblings have also
+ // successfully completed
+ boolean success = true;
+ NodeIterator ni = pNode.getNodes();
+ children: while (ni.hasNext()) {
+ Node currNode = ni.nextNode();
+ if ((currNode.isNodeType(SlcTypes.SLC_DIFF_RESULT) || currNode
+ .isNodeType(SlcTypes.SLC_RESULT_FOLDER))
+ && !currNode.getNode(SlcNames.SLC_STATUS)
+ .getProperty(SlcNames.SLC_SUCCESS)
+ .getBoolean()) {
+ success = false;
+ break children;
+ }
+ }
+ if (success) {
+ pNode.getNode(SlcNames.SLC_STATUS).setProperty(
+ SlcNames.SLC_SUCCESS, passed);
+ updatePassedStatus(pNode, passed);
+ } else
+ // one of the siblings had also the failed status so
+ // above tree remains unchanged.
+ return;
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot register listeners", e);
+ }
+ }
+
+ public static void updateStatusOnRemoval(Node node) {
+ try {
+ if (!node.hasNode(SlcNames.SLC_STATUS))
+ // nothing to do
+ return;
+ boolean pStatus = node.getNode(SlcNames.SLC_STATUS)
+ .getProperty(SlcNames.SLC_SUCCESS).getBoolean();
+ if (pStatus == true)
+ // nothing to update
+ return;
+ else {
+ // success we must first check if all siblings have also
+ // successfully completed
+ boolean success = true;
+ NodeIterator ni = node.getNodes();
+ children: while (ni.hasNext()) {
+ Node currNode = ni.nextNode();
+ if ((currNode.isNodeType(SlcTypes.SLC_DIFF_RESULT) || currNode
+ .isNodeType(SlcTypes.SLC_RESULT_FOLDER))
+ && !currNode.getNode(SlcNames.SLC_STATUS)
+ .getProperty(SlcNames.SLC_SUCCESS)
+ .getBoolean()) {
+ success = false;
+ break children;
+ }
+ }
+ if (success) {
+ node.getNode(SlcNames.SLC_STATUS).setProperty(
+ SlcNames.SLC_SUCCESS, true);
+ updatePassedStatus(node, true);
+ } else
+ // one of the siblings had also the failed status so
+ // above tree remains unchanged.
+ return;
+ }
+ } catch (RepositoryException e) {
+ throw new SlcException("Unexpected error while updating status on removal", e);
+ }
+ }
+
+}
+++ /dev/null
-/*
- * 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.model;
-
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-
-import org.argeo.slc.SlcException;
-import org.argeo.slc.jcr.SlcNames;
-import org.argeo.slc.jcr.SlcTypes;
-
-/**
- * UI Tree component that wrap a node of type NT_UNSTRUCTURED. list either other
- * folders and/or a list of results. keeps a reference to its parent.
- */
-public class SimpleNodeFolder extends ResultParent {
-
- private Node node = null;
-
- /**
- *
- * @param parent
- * @param node
- * throws an exception if null
- * @param name
- */
- public SimpleNodeFolder(SimpleNodeFolder parent, Node node, String name) {
- super(name);
- if (node == null)
- throw new SlcException("Node Object cannot be null");
- setParent(parent);
- this.node = node;
- }
-
- @Override
- protected void initialize() {
- try {
- NodeIterator ni = node.getNodes();
- while (ni.hasNext()) {
- Node currNode = ni.nextNode();
- if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) {
- SingleResultNode srn = new SingleResultNode(this, currNode,
- currNode.getProperty(SlcNames.SLC_TEST_CASE)
- .getString());
- addChild(srn);
- } else if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
- addChild(new SimpleNodeFolder(this, currNode,
- currNode.getName()));
- }
- } catch (RepositoryException re) {
- throw new SlcException(
- "Unexpected error while initializing simple node folder : "
- + getName(), re);
- }
- }
-
- @Override
- public synchronized void dispose() {
- super.dispose();
- }
-
- public Node getNode() {
- return node;
- }
-}
\ No newline at end of file
* It has no child.
*/
-public class SingleResultNode extends ResultParent {
+public class SingleResultNode extends ResultParent implements
+ Comparable<SingleResultNode> {
private final Node node;
private boolean passed;
// Do nothing this object is fully initialized at instantiation time.
}
+ public int compareTo(SingleResultNode o) {
+ return super.compareTo(o);
+ }
+
}
*/
package org.argeo.slc.client.ui.model;
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.slc.jcr.SlcNames;
-import org.argeo.slc.jcr.SlcTypes;
-
/**
* UI Tree component. Virtual folder to list either other folders and/or a list
* of results. Keeps a reference to its parent that might be null if the .
*/
public class VirtualFolder extends ResultParent {
+ ResultParent[] children;
- private Node node = null;
- private boolean isPassed = true;
-
- public VirtualFolder(VirtualFolder parent, Node node, String name) {
+ public VirtualFolder(VirtualFolder parent, ResultParent[] children,
+ String name) {
super(name);
setParent(parent);
- this.node = node;
+ this.children = children;
}
@Override
super.dispose();
}
- /** Override normal behavior to initialize display */
- @Override
- public synchronized Object[] getChildren() {
- if (isLoaded()) {
- return super.getChildren();
- } else {
- // initialize current object
- try {
- if (node != null) {
- NodeIterator ni = node.getNodes();
- while (ni.hasNext()) {
- Node currNode = ni.nextNode();
- if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT))
- addChild(new SingleResultNode(this, node, node
- .getProperty(SlcNames.SLC_TEST_CASE)
- .getString()));
- else if (currNode
- .isNodeType(SlcTypes.SLC_RESULT_FOLDER))
- addChild(new VirtualFolder(this, node,
- node.getName()));
- }
- }
- return super.getChildren();
- } catch (RepositoryException e) {
- throw new ArgeoException(
- "Cannot initialize WorkspaceNode UI object."
- + getName(), e);
- }
- }
- }
-
- // @Override
- // public boolean refreshPassedStatus() {
- // Object[] children = getChildren();
- // isPassed = true;
- // checkChildrenStatus: for (int i = 0; i <= children.length; i++) {
- // if (children[i] instanceof VirtualFolder) {
- //
- // }
- // if (!((ResultParent) children[i]).isPassed()) {
- // isPassed = false;
- // break checkChildrenStatus;
- // }
- // }
- // return isPassed;
- // }
-
@Override
protected void initialize() {
- // TODO Auto-generated method stub
+ if (children != null)
+ for (ResultParent child : children)
+ addChild(child);
}
+ public void resetChildren(ResultParent[] children) {
+ clearChildren();
+ this.children = children;
+ initialize();
+ }
}
\ No newline at end of file
package org.argeo.slc.client.ui.views;\r
\r
import java.util.ArrayList;\r
+import java.util.Calendar;\r
import java.util.List;\r
\r
import javax.jcr.Node;\r
import javax.jcr.RepositoryException;\r
import javax.jcr.Session;\r
import javax.jcr.Value;\r
+import javax.jcr.nodetype.NodeType;\r
import javax.jcr.observation.Event;\r
import javax.jcr.observation.EventListener;\r
import javax.jcr.observation.ObservationManager;\r
import org.argeo.slc.SlcException;\r
import org.argeo.slc.client.ui.ClientUiPlugin;\r
import org.argeo.slc.client.ui.commands.AddResultFolder;\r
+import org.argeo.slc.client.ui.model.ParentNodeFolder;\r
import org.argeo.slc.client.ui.model.ResultFolder;\r
import org.argeo.slc.client.ui.model.ResultParent;\r
-import org.argeo.slc.client.ui.model.SimpleNodeFolder;\r
+import org.argeo.slc.client.ui.model.ResultParentUtils;\r
import org.argeo.slc.client.ui.model.SingleResultNode;\r
+import org.argeo.slc.client.ui.model.VirtualFolder;\r
import org.argeo.slc.client.ui.providers.ResultTreeContentProvider;\r
import org.argeo.slc.client.ui.providers.ResultTreeLabelProvider;\r
import org.argeo.slc.jcr.SlcJcrResultUtils;\r
\r
private EventListener resultsObserver = null;\r
\r
- private final static String[] observedNodeTypes = { SlcTypes.SLC_TEST_RESULT };\r
+ private final static String[] observedNodeTypes = {\r
+ SlcTypes.SLC_TEST_RESULT, SlcTypes.SLC_RESULT_FOLDER,\r
+ NodeType.NT_UNSTRUCTURED };\r
+\r
+ // FIXME cache to ease refresh after D&D\r
+ private ResultParent lastSelectedElement;\r
+ private ResultParent lastSelectedElementParent;\r
\r
/**\r
* To be overridden to adapt size of form and result frames.\r
\r
// Refresh the view to initialize it\r
refresh(null);\r
-\r
- try {\r
- ObservationManager observationManager = session.getWorkspace()\r
- .getObservationManager();\r
- // FIXME Will not be notified if empty result is deleted\r
- if (UserJcrUtils.getUserHome(session) != null) {\r
- resultsObserver = new ResultObserver(resultTreeViewer.getTree()\r
- .getDisplay());\r
- observationManager.addEventListener(resultsObserver,\r
- Event.PROPERTY_ADDED | Event.NODE_REMOVED, UserJcrUtils\r
- .getUserHome(session).getPath(), true, null,\r
- observedNodeTypes, false);\r
- }\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot register listeners", e);\r
- }\r
-\r
}\r
\r
// The main tree viewer\r
.getNode());\r
else\r
propertiesViewer.setInput(null);\r
+ lastSelectedElement = (ResultParent) firstItem;\r
+ lastSelectedElementParent = (ResultParent) ((ResultParent) firstItem)\r
+ .getParent();\r
}\r
}\r
});\r
-\r
return viewer;\r
}\r
\r
if (resultParent == null) {\r
resultTreeViewer.setInput(initializeResultTree());\r
if (resultsObserver == null) {\r
- // force initialization of the resultsObserver, only useful\r
- // if the current view has been displayed before a single\r
- // test has been run\r
try {\r
ObservationManager observationManager = session\r
.getWorkspace().getObservationManager();\r
resultsObserver = new ResultObserver(resultTreeViewer\r
.getTree().getDisplay());\r
observationManager.addEventListener(resultsObserver,\r
- Event.PROPERTY_ADDED | Event.NODE_REMOVED, UserJcrUtils\r
+ Event.NODE_ADDED | Event.NODE_REMOVED, UserJcrUtils\r
.getUserHome(session).getPath(), true,\r
null, observedNodeTypes, false);\r
} catch (RepositoryException e) {\r
ResultFolder currFolder = (ResultFolder) resultParent;\r
jcrRefresh(currFolder.getNode());\r
currFolder.forceFullRefresh();\r
+ resultTreeViewer.refresh(lastSelectedElement);\r
}\r
}\r
}\r
\r
private ResultParent[] initializeResultTree() {\r
- ResultParent[] roots = new ResultParent[2];\r
try {\r
- roots[0] = new ResultFolder(null,\r
- SlcJcrResultUtils.getMyResultParentNode(session),\r
- "My results");\r
- Node otherResultsPar = session.getNode(SlcJcrResultUtils\r
- .getSlcResultsBasePath(session));\r
- roots[1] = new SimpleNodeFolder(null, otherResultsPar,\r
- "All results");\r
- return roots;\r
+ if (session.nodeExists(SlcJcrResultUtils\r
+ .getSlcResultsBasePath(session))) {\r
+ ResultParent[] roots = new ResultParent[5];\r
+\r
+ // My results\r
+ roots[0] = new ParentNodeFolder(null,\r
+ SlcJcrResultUtils.getMyResultParentNode(session),\r
+ "My results");\r
+\r
+ // today\r
+ Calendar cal = Calendar.getInstance();\r
+ String relPath = JcrUtils.dateAsPath(cal);\r
+ List<String> datePathes = new ArrayList<String>();\r
+ datePathes.add(relPath);\r
+ roots[1] = new VirtualFolder(null,\r
+ ResultParentUtils.getResultsForDates(session,\r
+ datePathes), "Today");\r
+\r
+ // Yesterday\r
+ cal = Calendar.getInstance();\r
+ cal.add(Calendar.DAY_OF_YEAR, -1);\r
+ relPath = JcrUtils.dateAsPath(cal);\r
+ datePathes = new ArrayList<String>();\r
+ datePathes.add(relPath);\r
+ roots[2] = new VirtualFolder(null,\r
+ ResultParentUtils.getResultsForDates(session,\r
+ datePathes), "Yesterday");\r
+ // Last 7 days\r
+\r
+ cal = Calendar.getInstance();\r
+ datePathes = new ArrayList<String>();\r
+\r
+ for (int i = 0; i < 7; i++) {\r
+ cal.add(Calendar.DAY_OF_YEAR, -i);\r
+ relPath = JcrUtils.dateAsPath(cal);\r
+ datePathes.add(relPath);\r
+ }\r
+ roots[3] = new VirtualFolder(null,\r
+ ResultParentUtils.getResultsForDates(session,\r
+ datePathes), "Last 7 days");\r
+\r
+ // All results\r
+ Node otherResultsPar = session.getNode(SlcJcrResultUtils\r
+ .getSlcResultsBasePath(session));\r
+ roots[4] = new ParentNodeFolder(null, otherResultsPar,\r
+ "All results");\r
+ return roots;\r
+ } else\r
+ // no test has yet been processed, we leave the viewer blank\r
+ return null;\r
} catch (RepositoryException re) {\r
throw new ArgeoException(\r
"Unexpected error while initializing ResultTree.", re);\r
if (selection.size() == 1) {\r
Object obj = selection.getFirstElement();\r
try {\r
- Node targetParentNode = null;\r
- if (obj instanceof ResultFolder) {\r
- targetParentNode = ((ResultFolder) obj).getNode();\r
-\r
- if (targetParentNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER))\r
- isMyResultFolder = true;\r
- }\r
+ if (obj instanceof ResultFolder\r
+ && (((ResultFolder) obj).getNode())\r
+ .isNodeType(SlcTypes.SLC_RESULT_FOLDER))\r
+ isMyResultFolder = true;\r
+ else if (obj instanceof ParentNodeFolder\r
+ && (((ParentNodeFolder) obj).getNode().getPath()\r
+ .startsWith(SlcJcrResultUtils\r
+ .getMyResultsBasePath(session))))\r
+ isMyResultFolder = true;\r
} catch (RepositoryException re) {\r
throw new SlcException(\r
"unexpected error while building condition for context menu",\r
// We can only drop under myResults\r
Node targetParentNode = null;\r
if (target instanceof ResultFolder) {\r
- Node currNode = ((ResultFolder) target).getNode();\r
-\r
- if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {\r
- targetParentNode = currNode;\r
- }\r
+ targetParentNode = ((ResultFolder) target).getNode();\r
+ } else if (target instanceof ParentNodeFolder) {\r
+ if ((((ParentNodeFolder) target).getNode().getPath()\r
+ .startsWith(SlcJcrResultUtils\r
+ .getMyResultsBasePath(session))))\r
+ targetParentNode = ((ParentNodeFolder) target)\r
+ .getNode();\r
} else if (target instanceof SingleResultNode) {\r
Node currNode = ((SingleResultNode) target).getNode();\r
- if (currNode.getParent().isNodeType(\r
- SlcTypes.SLC_RESULT_FOLDER))\r
+ if (currNode\r
+ .getParent()\r
+ .getPath()\r
+ .startsWith(\r
+ SlcJcrResultUtils\r
+ .getMyResultsBasePath(session)))\r
targetParentNode = currNode.getParent();\r
}\r
if (targetParentNode != null) {\r
currParentNode = targetParentNode;\r
validDrop = true;\r
+ // FIXME\r
+ lastSelectedElement = (ResultParent) target;\r
+ lastSelectedElementParent = (ResultParent) ((ResultParent) target)\r
+ .getParent();\r
}\r
} catch (RepositoryException re) {\r
throw new SlcException(\r
Node target = currParentNode.addNode(source.getName(), source\r
.getPrimaryNodeType().getName());\r
JcrUtils.copy(source, target);\r
- updatePassedStatus(target, target.getNode(SlcNames.SLC_STATUS)\r
+ ResultParentUtils.updatePassedStatus(target, target.getNode(SlcNames.SLC_STATUS)\r
.getProperty(SlcNames.SLC_SUCCESS).getBoolean());\r
target.getSession().save();\r
} catch (RepositoryException re) {\r
}\r
return true;\r
}\r
-\r
- /**\r
- * recursively update passed status of the parent ResultFolder and its\r
- * parent if needed\r
- * \r
- * @param node\r
- * cannot be null\r
- * \r
- */\r
- private void updatePassedStatus(Node node, boolean passed) {\r
- try {\r
- Node pNode = node.getParent();\r
- boolean pStatus = pNode.getNode(SlcNames.SLC_STATUS)\r
- .getProperty(SlcNames.SLC_SUCCESS).getBoolean();\r
- if (pStatus == passed)\r
- // nothing to update\r
- return;\r
- else if (!passed) {\r
- // error we only update status of the result folder and its\r
- // parent if needed\r
- pNode.getNode(SlcNames.SLC_STATUS).setProperty(\r
- SlcNames.SLC_SUCCESS, passed);\r
- updatePassedStatus(pNode, passed);\r
- } else {\r
- // success we must first check if all siblings have also\r
- // successfully completed\r
- boolean success = true;\r
- NodeIterator ni = pNode.getNodes();\r
- children: while (ni.hasNext()) {\r
- Node currNode = ni.nextNode();\r
- if ((currNode.isNodeType(SlcTypes.SLC_DIFF_RESULT) || currNode\r
- .isNodeType(SlcTypes.SLC_RESULT_FOLDER))\r
- && !currNode.getNode(SlcNames.SLC_STATUS)\r
- .getProperty(SlcNames.SLC_SUCCESS)\r
- .getBoolean()) {\r
- success = false;\r
- break children;\r
- }\r
- }\r
- if (success) {\r
- pNode.getNode(SlcNames.SLC_STATUS).setProperty(\r
- SlcNames.SLC_SUCCESS, passed);\r
- updatePassedStatus(pNode, passed);\r
- } else\r
- // one of the siblings had also the failed status so\r
- // above tree remains unchanged.\r
- return;\r
- }\r
-\r
- } catch (RepositoryException e) {\r
- throw new SlcException("Cannot register listeners", e);\r
- }\r
- }\r
}\r
\r
class ResultObserver extends AsyncUiEventListener {\r
@Override\r
protected Boolean willProcessInUiThread(List<Event> events)\r
throws RepositoryException {\r
+ // unfiltered for the time being\r
+ return true;\r
+ // for (Event event : events) {\r
+ // getLog().debug("Received event " + event);\r
+ // int eventType = event.getType();\r
+ // if (eventType == Event.NODE_REMOVED)\r
+ // ;//return true;\r
+ // String path = event.getPath();\r
+ // int index = path.lastIndexOf('/');\r
+ // String propertyName = path.substring(index + 1);\r
+ // if (propertyName.equals(SlcNames.SLC_COMPLETED)\r
+ // || propertyName.equals(SlcNames.SLC_UUID)) {\r
+ // ;//return true;\r
+ // }\r
+ // }\r
+ // return false;\r
+ }\r
+\r
+ protected void onEventInUiThread(List<Event> events)\r
+ throws RepositoryException {\r
+\r
for (Event event : events) {\r
- // getLog().debug("Received event " + event);\r
+ getLog().debug("Received event " + event);\r
int eventType = event.getType();\r
- if (eventType == Event.NODE_REMOVED)\r
- return true;\r
- String path = event.getPath();\r
- int index = path.lastIndexOf('/');\r
- String propertyName = path.substring(index + 1);\r
- if (propertyName.equals(SlcNames.SLC_COMPLETED)\r
- || propertyName.equals(SlcNames.SLC_UUID)) {\r
- return true;\r
+ if (eventType == Event.NODE_REMOVED) {\r
+ String path = event.getPath();\r
+ int index = path.lastIndexOf('/');\r
+ String parPath = path.substring(0, index + 1);\r
+ if (session.nodeExists(parPath)) {\r
+ Node currNode = session.getNode(parPath);\r
+ if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED)) {\r
+ refresh(null);\r
+ jcrRefresh(currNode);\r
+ resultTreeViewer.refresh(true);\r
+ resultTreeViewer.expandToLevel(\r
+ lastSelectedElementParent, 1);\r
+ \r
+ }\r
+ }\r
+ } else if (eventType == Event.NODE_ADDED) {\r
+ String path = event.getPath();\r
+ if (session.nodeExists(path)) {\r
+ Node currNode = session.getNode(path);\r
+ if (currNode.isNodeType(SlcTypes.SLC_DIFF_RESULT)\r
+ || currNode\r
+ .isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {\r
+ refresh(null);\r
+ resultTreeViewer.expandToLevel(lastSelectedElement,\r
+ 1);\r
+ }\r
+ }\r
}\r
+ // String path = event.getPath();\r
+ // int index = path.lastIndexOf('/');\r
+ // String propertyName = path.substring(index + 1);\r
+ // if (propertyName.equals(SlcNames.SLC_COMPLETED)\r
+ // || propertyName.equals(SlcNames.SLC_UUID)) {\r
+ // }\r
}\r
- return false;\r
- }\r
\r
- protected void onEventInUiThread(List<Event> events)\r
- throws RepositoryException {\r
// FIXME implement correct behaviour. treeViewer selection is\r
// disposed by the drag & drop.\r
// resultTreeViewer.refresh();\r
// refresh(null);\r
// log.warn("Implement refresh.");\r
}\r
-\r
}\r
\r
class PropertiesContentProvider implements IStructuredContentProvider {\r
/*
* SLC SPECIFIC JCR PATHS
*/
- public final static String SLC_MYRESULT_BASEPATH = "slc:myResults/";
+ public final static String SLC_MYRESULT_BASEPATH = "slc:myResults";
}
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
+import javax.jcr.nodetype.NodeType;
+import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
import org.argeo.ArgeoException;
import org.argeo.jcr.JcrUtils;
import org.argeo.jcr.UserJcrUtils;
}
}
+ /**
+ * Creates a new node with type NodeType.NT_UNSTRUCTURED at the given
+ * absolute path. If a node already exists at the given path, returns that
+ * node if it has the correct type and throws an exception otherwise.
+ *
+ * @param session
+ * @return
+ */
public static Node getMyResultParentNode(Session session) {
try {
- if (session.nodeExists(SlcJcrResultUtils
- .getMyResultsBasePath(session)))
- return session.getNode(getMyResultsBasePath(session));
- else
- return createResultFolderNode(session,
- getMyResultsBasePath(session));
+ String absPath = getMyResultsBasePath(session);
+ if (session.nodeExists(absPath)) {
+ Node currNode = session.getNode(absPath);
+ if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
+ return currNode;
+ else
+ throw new SlcException(
+ "A node already exists at this path : " + absPath
+ + " that has the wrong type. ");
+ } else {
+ Node myResParNode = JcrUtils.mkdirs(session, absPath);
+ myResParNode.setPrimaryType(NodeType.NT_UNSTRUCTURED);
+ session.save();
+ return myResParNode;
+ }
} catch (RepositoryException re) {
throw new ArgeoException(
"Unexpected error while creating user MyResult base node.",
re);
}
-
}
/**