]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/ResultFolder.java
Improve UI dist
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / model / ResultFolder.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
22 import org.argeo.slc.SlcException;
23 import org.argeo.slc.jcr.SlcNames;
24 import org.argeo.slc.jcr.SlcTypes;
25
26 /**
27 * UI Tree component that wrap a node of type ResultFolder. list either other
28 * folders and/or a list of results. keeps a reference to its parent.
29 */
30 public class ResultFolder extends ResultParent implements Comparable<ResultFolder> {
31
32 private Node node = null;
33
34 /**
35 *
36 * @param parent
37 * @param node
38 * throws an exception if null
39 * @param name
40 */
41 public ResultFolder(ResultParent parent, Node node, String name) {
42 super(name);
43 try {
44 if (node == null)
45 throw new SlcException("Node Object cannot be null");
46 setParent(parent);
47 this.node = node;
48 // initialize passed status if possible
49 if (node.hasNode(SlcNames.SLC_STATUS))
50 setPassed(node.getNode(SlcNames.SLC_STATUS)
51 .getProperty(SlcNames.SLC_SUCCESS).getBoolean());
52 } catch (RepositoryException re) {
53 throw new SlcException(
54 "Unexpected error while initializing result folder : "
55 + getName(), re);
56 }
57
58 }
59
60 @Override
61 protected void initialize() {
62 try {
63 NodeIterator ni = node.getNodes();
64 while (ni.hasNext()) {
65 Node currNode = ni.nextNode();
66 if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) {
67 SingleResultNode srn = new SingleResultNode(this, currNode,
68 currNode.getProperty(SlcNames.SLC_TEST_CASE)
69 .getString());
70 addChild(srn);
71 } else if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {
72 // FIXME change label
73 ResultFolder rf = new ResultFolder(this, currNode,
74 currNode.getName());
75 addChild(rf);
76 }
77 }
78 } catch (RepositoryException re) {
79 throw new SlcException(
80 "Unexpected error while initializing result folder : "
81 + getName(), re);
82 }
83 }
84
85 @Override
86 public synchronized void dispose() {
87 super.dispose();
88 }
89
90 public Node getNode() {
91 return node;
92 }
93
94 /**
95 * Overriden to return an ordered list of children
96 */
97 public synchronized Object[] getChildren() {
98 Object[] children = super.getChildren();
99 return ResultParentUtils.orderChildren(children);
100 }
101
102 public int compareTo(ResultFolder o) {
103 return super.compareTo(o);
104 }
105 }