]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ParentNodeFolder.java
Analyse issue with reasult display
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / model / ParentNodeFolder.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.client.ui.model;
17
18 import javax.jcr.Node;
19 import javax.jcr.NodeIterator;
20 import javax.jcr.RepositoryException;
21 import javax.jcr.nodetype.NodeType;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.argeo.slc.SlcException;
26 import org.argeo.slc.jcr.SlcJcrResultUtils;
27 import org.argeo.slc.jcr.SlcNames;
28 import org.argeo.slc.jcr.SlcTypes;
29
30 /**
31 * UI Tree component that wrap a node of type NT_UNSTRUCTURED.
32 *
33 * It is used for
34 * <ul>
35 * <li>automatically generated tree structure to store results (typically
36 * Year/Month/Day...)</li>
37 * <li>parent node for user defined tree structure (typically My Results node)</li>
38 * </ul>
39 * It thus lists either result folders, other folders and/or a list of results
40 * and keeps a reference to its parent.
41 */
42 public class ParentNodeFolder extends ResultParent {
43 private final static Log log = LogFactory.getLog(ParentNodeFolder.class);
44
45 private Node node = null;
46
47 /**
48 *
49 * @param parent
50 * @param node
51 * throws an exception if null
52 * @param name
53 */
54 public ParentNodeFolder(ParentNodeFolder parent, Node node, String name) {
55 super(name);
56 if (node == null)
57 throw new SlcException("Node Object cannot be null");
58 setParent(parent);
59 this.node = node;
60 }
61
62 @Override
63 protected void initialize() {
64 try {
65 NodeIterator ni = node.getNodes();
66 while (ni.hasNext()) {
67 Node currNode = ni.nextNode();
68 if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) {
69 SingleResultNode srn = new SingleResultNode(this, currNode,
70 currNode.getProperty(SlcNames.SLC_TEST_CASE)
71 .getString());
72 addChild(srn);
73 } else if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {
74 // FIXME change label
75 ResultFolder rf = new ResultFolder(this, currNode,
76 currNode.getName());
77 addChild(rf);
78 } else if (currNode.isNodeType(SlcTypes.SLC_CHECK)) {
79 // FIXME : manually skip node types that are not to be
80 // displayed
81 // Do nothing
82 } else if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
83 addChild(new ParentNodeFolder(this, currNode,
84 currNode.getName()));
85 }
86 } catch (RepositoryException re) {
87 throw new SlcException(
88 "Unexpected error while initializing ParentNodeFolder : "
89 + getName(), re);
90 }
91 }
92
93 @Override
94 public synchronized void dispose() {
95 super.dispose();
96 }
97
98 public Node getNode() {
99 return node;
100 }
101
102 /**
103 * Overriden in the specific case of "My result" root object to return an
104 * ordered list of children
105 */
106 public synchronized Object[] getChildren() {
107 Object[] children = super.getChildren();
108 try {
109 if (node.getPath().equals(
110 SlcJcrResultUtils.getMyResultsBasePath(node.getSession())))
111 return ResultParentUtils.orderChildren(children);
112 else
113 return children;
114 } catch (RepositoryException re) {
115 throw new SlcException(
116 "Unexpected error while initializing simple node folder : "
117 + getName(), re);
118 }
119 }
120 }