]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/SimpleNodeFolder.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 / SimpleNodeFolder.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.argeo.slc.SlcException;
24 import org.argeo.slc.jcr.SlcNames;
25 import org.argeo.slc.jcr.SlcTypes;
26
27 /**
28 * UI Tree component that wrap a node of type NT_UNSTRUCTURED. list either other
29 * folders and/or a list of results. keeps a reference to its parent.
30 */
31 public class SimpleNodeFolder extends ResultParent {
32
33 private Node node = null;
34
35 /**
36 *
37 * @param parent
38 * @param node
39 * throws an exception if null
40 * @param name
41 */
42 public SimpleNodeFolder(SimpleNodeFolder parent, Node node, String name) {
43 super(name);
44 if (node == null)
45 throw new SlcException("Node Object cannot be null");
46 setParent(parent);
47 this.node = node;
48 }
49
50 @Override
51 protected void initialize() {
52 try {
53 NodeIterator ni = node.getNodes();
54 while (ni.hasNext()) {
55 Node currNode = ni.nextNode();
56 if (currNode.isNodeType(SlcTypes.SLC_TEST_RESULT)) {
57 SingleResultNode srn = new SingleResultNode(this, currNode,
58 currNode.getProperty(SlcNames.SLC_TEST_CASE)
59 .getString());
60 addChild(srn);
61 } else if (currNode.isNodeType(NodeType.NT_UNSTRUCTURED))
62 addChild(new SimpleNodeFolder(this, currNode,
63 currNode.getName()));
64 }
65 } catch (RepositoryException re) {
66 throw new SlcException(
67 "Unexpected error while initializing simple node folder : "
68 + getName(), re);
69 }
70 }
71
72 @Override
73 public synchronized void dispose() {
74 super.dispose();
75 }
76
77 public Node getNode() {
78 return node;
79 }
80 }