1 package org
.argeo
.slc
.client
.contentprovider
;
4 import java
.util
.SortedMap
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.eclipse
.ui
.TreeParent
;
9 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
10 import org
.argeo
.slc
.core
.test
.tree
.PartSubList
;
11 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
12 import org
.argeo
.slc
.test
.TestResultPart
;
13 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
14 import org
.eclipse
.jface
.viewers
.Viewer
;
17 * Basic tree view of the chosen process details
19 public class ResultDetailContentProvider
implements ITreeContentProvider
{
20 private final static Log log
= LogFactory
21 .getLog(ResultDetailContentProvider
.class);
23 private TreeTestResult treeTestResult
;
25 public Object
[] getChildren(Object parent
) {
26 if (parent
instanceof TreeTestResult
) {
27 log
.error("We should not reach this point.");
31 if (parent
instanceof TreeParent
) {
32 return ((TreeParent
) parent
).getChildren();
35 if (parent
instanceof ResultPartNode
) {
42 public Object
getParent(Object node
) {
43 if (node
instanceof TreeParent
) {
44 return ((TreeParent
) node
).getParent();
49 public boolean hasChildren(Object parent
) {
50 if (parent
instanceof TreeParent
&& ((TreeParent
) parent
).isLoaded()) {
51 return ((TreeParent
) parent
).hasChildren();
56 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
59 public void dispose() {
62 public Object
[] getElements(Object parent
) {
63 if (parent
instanceof TreeTestResult
) {
64 treeTestResult
= (TreeTestResult
) parent
;
66 // We wrap domain object in ViewSpecificObjects.
67 ResultTreeParent root
= new ResultTreeParent("Test "
68 + treeTestResult
.getUuid());
69 SortedMap
<TreeSPath
, PartSubList
> partSubLists
= treeTestResult
72 for (TreeSPath key
: partSubLists
.keySet()) {
73 String relPath
= key
.getAsUniqueString();
75 // get rid of '/' that begins every TreeSPath Unique string
76 relPath
= relPath
.substring(1);
77 String
[] pathes
= relPath
.split("/"); // parse the TreeSPath
78 ResultTreeParent curTreeParent
= root
;
80 // We create intermediate folders if needed
81 for (int i
= 0; i
< pathes
.length
; i
++) {
82 // if (log.isDebugEnabled())
83 // log.debug("i = " + i + " - " + pathes[i]);
85 if (curTreeParent
.getChildByName(pathes
[i
]) == null) {
86 ResultTreeParent child
= new ResultTreeParent(pathes
[i
]);
87 curTreeParent
.addChild(child
);
88 curTreeParent
= child
;
90 curTreeParent
= (ResultTreeParent
) curTreeParent
91 .getChildByName(pathes
[i
]);
95 List
<TestResultPart
> parts
= partSubLists
.get(key
).getParts();
96 for (TestResultPart part
: parts
) {
97 ResultPartNode node
= new ResultPartNode(part
.toString(),
98 part
.getStatus(), part
.getMessage(),
99 part
.getExceptionMessage());
100 curTreeParent
.addChild(node
);
104 // We must set status isPassed for each node.
106 return root
.getChildren();
111 public void setIsPassed(StatusAware node
) {
113 if (node
instanceof ResultTreeObject
) {
114 ResultTreeObject rto
= (ResultTreeObject
) node
;
115 rto
.isPassed
= rto
.isPassed();
118 if (node
instanceof ResultTreeParent
) {
119 ResultTreeParent rtp
= (ResultTreeParent
) node
;
120 // we dig the tree recursivly
121 for (Object to
: rtp
.getChildren())
122 setIsPassed((StatusAware
) to
);
124 for (Object to
: rtp
.getChildren()) {
125 if (!((StatusAware
) to
).isPassed()) {
126 rtp
.isPassed
= false;
134 // To enable display of color to show if a test is passed or not even when
135 // hidden. We say a test is in error if its status is FAILED or ERROR (e.g,
136 // if it has not executed completely due to technical problems).
137 public interface StatusAware
{
138 public void setPassed(boolean isPassed
);
140 public boolean isPassed();
143 public class ResultTreeParent
extends TreeParent
implements StatusAware
{
145 public ResultTreeParent(String name
) {
149 private boolean isPassed
= true;
151 public void setPassed(boolean isPassed
) {
152 this.isPassed
= isPassed
;
155 public boolean isPassed() {
160 public class ResultTreeObject
extends TreeParent
implements StatusAware
{
162 public ResultTreeObject(String name
) {
166 private boolean isPassed
= true;
168 public void setPassed(boolean isPassed
) {
169 this.isPassed
= isPassed
;
172 public boolean isPassed() {
177 // Specific inner classes
178 public class ResultPartNode
extends ResultTreeObject
{
180 private String status
;
181 private String message
;
182 private String exceptionMessage
;
184 public ResultPartNode(String label
, Integer status
, String message
) {
186 handleStatus(status
);
187 this.message
= message
;
190 public ResultPartNode(String label
, Integer status
, String message
,
191 String exceptionMessage
) {
193 handleStatus(status
);
194 this.message
= message
;
195 this.exceptionMessage
= exceptionMessage
;
198 private void handleStatus(Integer status
) {
201 this.status
= "PASSED";
205 this.status
= "FAILED";
209 this.status
= "ERROR";
213 // for the moment being we don't have a relevant label
216 public String
getStatus() {
220 public String
getMessage() {
224 public String
getExceptionMessage() {
225 return exceptionMessage
;