]> 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
Refactor JCR utils and home usage
[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 {
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(ResultFolder 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
49 setPassed(node.getNode(SlcNames.SLC_STATUS)
50 .getProperty(SlcNames.SLC_SUCCESS).getBoolean());
51 } catch (RepositoryException re) {
52 throw new SlcException(
53 "Unexpected error while initializing result folder : "
54 + getName(), re);
55 }
56
57 }
58
59 @Override
60 protected void initialize() {
61 try {
62 NodeIterator ni = node.getNodes();
63 while (ni.hasNext()) {
64 Node currNode = ni.nextNode();
65 if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) {
66 SingleResultNode srn = new SingleResultNode(this, currNode,
67 currNode.getProperty(SlcNames.SLC_TEST_CASE)
68 .getString());
69 addChild(srn);
70 } else if (currNode.isNodeType(SlcTypes.SLC_RESULT_FOLDER)) {
71 // FIXME change label
72 ResultFolder rf = new ResultFolder(this, currNode,
73 currNode.getName());
74 addChild(rf);
75 }
76 }
77 } catch (RepositoryException re) {
78 throw new SlcException(
79 "Unexpected error while initializing result folder : "
80 + getName(), re);
81 }
82 }
83
84 @Override
85 public synchronized void dispose() {
86 super.dispose();
87 }
88
89 public Node getNode() {
90 return node;
91 }
92
93 // /** Override normal behavior to initialize display */
94 // @Override
95 // public synchronized Object[] getChildren() {
96 // if (isLoaded()) {
97 // return super.getChildren();
98 // } else {
99 // // initialize current object
100 // try {
101 // if (node != null) {
102 // NodeIterator ni = node.getNodes();
103 // while (ni.hasNext()) {
104 // Node currNode = ni.nextNode();
105 // if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT))
106 // addChild(new SingleResultNode(this, node, node
107 // .getProperty(SlcNames.SLC_TEST_CASE)
108 // .getString()));
109 // else if (currNode
110 // .isNodeType(SlcTypes.SLC_RESULT_FOLDER))
111 // addChild(new ResultFolder(this, node,
112 // node.getName()));
113 // }
114 // }
115 // return super.getChildren();
116 // } catch (RepositoryException e) {
117 // throw new ArgeoException(
118 // "Cannot initialize WorkspaceNode UI object."
119 // + getName(), e);
120 // }
121 // }
122 // }
123
124 // @Override
125 // public boolean refreshPassedStatus() {
126 // Object[] children = getChildren();
127 // isPassed = true;
128 // checkChildrenStatus: for (int i = 0; i <= children.length; i++) {
129 // if (children[i] instanceof ResultFolder) {
130 //
131 // }
132 // if (!((ResultParent) children[i]).isPassed()) {
133 // isPassed = false;
134 // break checkChildrenStatus;
135 // }
136 // }
137 // return isPassed;
138 // }
139
140 }