]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/model/SingleResultNode.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 / SingleResultNode.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.RepositoryException;
20 import javax.jcr.Workspace;
21
22 import org.argeo.eclipse.ui.TreeParent;
23 import org.argeo.slc.SlcException;
24 import org.argeo.slc.jcr.SlcNames;
25
26 /**
27 * UI Tree component. Wraps a result node of a JCR {@link Workspace}. It also
28 * keeps a reference to its parent node that can either be a
29 * {@link ResultFolder}, a {@link SingleResultNode} or a {@link VirtualFolder}.
30 * It has no child.
31 */
32
33 public class SingleResultNode extends ResultParent implements
34 Comparable<SingleResultNode> {
35
36 private final Node node;
37 private boolean passed;
38
39 // keeps a local reference to the node's name to avoid exception when the
40 // session is lost
41
42 /** Creates a new UiNode in the UI Tree */
43 public SingleResultNode(TreeParent parent, Node node, String name) {
44 super(name);
45 setParent(parent);
46 this.node = node;
47 setPassed(refreshPassedStatus());
48 }
49
50 public boolean refreshPassedStatus() {
51 try {
52 Node check = node.getNode(SlcNames.SLC_STATUS);
53 passed = check.getProperty(SlcNames.SLC_SUCCESS).getBoolean();
54 return passed;
55 } catch (RepositoryException re) {
56 throw new SlcException(
57 "Unexpected error while checking result status", re);
58 }
59 }
60
61 /** returns the node wrapped by the current UI object */
62 public Node getNode() {
63 return node;
64 }
65
66 /**
67 * Override normal behavior : Results have no children for this view
68 */
69 @Override
70 public synchronized Object[] getChildren() {
71 return null;
72 }
73
74 @Override
75 public boolean hasChildren() {
76 return false;
77 }
78
79 public boolean isPassed() {
80 return passed;
81 }
82
83 @Override
84 protected void initialize() {
85 // Do nothing this object is fully initialized at instantiation time.
86 }
87
88 public int compareTo(SingleResultNode o) {
89 return super.compareTo(o);
90 }
91
92 }