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