View Javadoc
1   /*
2    * Copyright (C) 2007-2012 Argeo GmbH
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.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;
53  			if (node.hasNode(SlcNames.SLC_AGGREGATED_STATUS)) {
54  				check = node.getNode(SlcNames.SLC_AGGREGATED_STATUS);
55  				passed = check.getProperty(SlcNames.SLC_SUCCESS).getBoolean();
56  				return passed;
57  			} else
58  				// Happens only if the UI triggers a refresh while the execution
59  				// is in progress and the corresponding node is being built
60  				return false;
61  		} catch (RepositoryException re) {
62  			throw new SlcException(
63  					"Unexpected error while checking result status", re);
64  		}
65  	}
66  
67  	/** returns the node wrapped by the current UI object */
68  	public Node getNode() {
69  		return node;
70  	}
71  
72  	/**
73  	 * Override normal behavior : Results have no children for this view
74  	 */
75  	@Override
76  	public synchronized Object[] getChildren() {
77  		return null;
78  	}
79  
80  	@Override
81  	public boolean hasChildren() {
82  		return false;
83  	}
84  
85  	public boolean isPassed() {
86  		return passed;
87  	}
88  
89  	@Override
90  	protected void initialize() {
91  		// Do nothing this object is fully initialized at instantiation time.
92  	}
93  
94  	public int compareTo(SingleResultNode o) {
95  		return super.compareTo(o);
96  	}
97  
98  }