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
.TreeObject
;
9 import org
.argeo
.eclipse
.ui
.TreeParent
;
10 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
11 import org
.argeo
.slc
.core
.test
.tree
.PartSubList
;
12 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
13 import org
.argeo
.slc
.test
.TestResultPart
;
14 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
15 import org
.eclipse
.jface
.viewers
.Viewer
;
18 * Basic tree view of the chosen process details
20 public class ResultDetailContentProvider
implements ITreeContentProvider
{
21 private final static Log log
= LogFactory
22 .getLog(ResultDetailContentProvider
.class);
24 private TreeTestResult treeTestResult
;
26 public Object
[] getChildren(Object parent
) {
27 if (parent
instanceof TreeTestResult
) {
28 log
.error("We should not reach this point.");
32 if (parent
instanceof TreeParent
) {
33 return ((TreeParent
) parent
).getChildren();
36 if (parent
instanceof ResultPartNode
) {
43 public Object
getParent(Object node
) {
44 if (node
instanceof TreeObject
) {
45 return ((TreeObject
) node
).getParent();
50 public boolean hasChildren(Object parent
) {
51 if (parent
instanceof TreeParent
&& ((TreeParent
) parent
).isLoaded()) {
52 return ((TreeParent
) parent
).hasChildren();
57 public void inputChanged(Viewer v
, Object oldInput
, Object newInput
) {
60 public void dispose() {
63 public Object
[] getElements(Object parent
) {
64 if (parent
instanceof TreeTestResult
) {
65 treeTestResult
= (TreeTestResult
) parent
;
67 // We wrap domain object in ViewSpecificObjects.
68 ResultTreeParent root
= new ResultTreeParent("Test "
69 + treeTestResult
.getUuid());
70 SortedMap
<TreeSPath
, PartSubList
> partSubLists
= treeTestResult
73 for (TreeSPath key
: partSubLists
.keySet()) {
74 String relPath
= key
.getAsUniqueString();
76 // get rid of '/' that begins every TreeSPath Unique string
77 relPath
= relPath
.substring(1);
78 String
[] pathes
= relPath
.split("/"); // parse the TreeSPath
79 ResultTreeParent curTreeParent
= root
;
81 // We create intermediate folders if needed
82 for (int i
= 0; i
< pathes
.length
; i
++) {
83 if (log
.isDebugEnabled())
84 log
.debug("i = " + i
+ " - " + pathes
[i
]);
86 if (curTreeParent
.getChildByName(pathes
[i
]) == null) {
87 ResultTreeParent child
= new ResultTreeParent(pathes
[i
]);
88 curTreeParent
.addChild(child
);
89 curTreeParent
= child
;
91 curTreeParent
= (ResultTreeParent
) curTreeParent
92 .getChildByName(pathes
[i
]);
96 List
<TestResultPart
> parts
= partSubLists
.get(key
).getParts();
97 for (TestResultPart part
: parts
) {
98 ResultPartNode node
= new ResultPartNode(part
.toString(),
99 part
.getStatus(), part
.getMessage(),
100 part
.getExceptionMessage());
101 curTreeParent
.addChild(node
);
105 // We must set status isPassed for each node.
107 return root
.getChildren();
112 public void setIsPassed(StatusAware node
) {
114 if (node
instanceof ResultTreeObject
) {
115 ResultTreeObject rto
= (ResultTreeObject
) node
;
116 rto
.isPassed
= rto
.isPassed();
119 if (node
instanceof ResultTreeParent
) {
120 ResultTreeParent rtp
= (ResultTreeParent
) node
;
121 // we dig the tree recursivly
122 for (TreeObject to
: rtp
.getChildren())
123 setIsPassed((StatusAware
) to
);
125 for (TreeObject to
: rtp
.getChildren()) {
126 if (!((StatusAware
) to
).isPassed()) {
127 rtp
.isPassed
= false;
135 // To enable display of color to show if a test is passed or not even when
136 // hidden. We say a test is in error if its status is FAILED or ERROR (e.g,
137 // if it has not executed completely due to technical problems).
138 public interface StatusAware
{
139 public void setPassed(boolean isPassed
);
141 public boolean isPassed();
144 public class ResultTreeParent
extends TreeParent
implements StatusAware
{
146 public ResultTreeParent(String name
) {
150 private boolean isPassed
= true;
152 public void setPassed(boolean isPassed
) {
153 this.isPassed
= isPassed
;
156 public boolean isPassed() {
161 public class ResultTreeObject
extends TreeObject
implements StatusAware
{
163 public ResultTreeObject(String name
) {
167 private boolean isPassed
= true;
169 public void setPassed(boolean isPassed
) {
170 this.isPassed
= isPassed
;
173 public boolean isPassed() {
178 // Specific inner classes
179 public class ResultPartNode
extends ResultTreeObject
{
181 private String status
;
182 private String message
;
183 private String exceptionMessage
;
185 public ResultPartNode(String label
, Integer status
, String message
) {
187 handleStatus(status
);
188 this.message
= message
;
191 public ResultPartNode(String label
, Integer status
, String message
,
192 String exceptionMessage
) {
194 handleStatus(status
);
195 this.message
= message
;
196 this.exceptionMessage
= exceptionMessage
;
199 private void handleStatus(Integer status
) {
202 this.status
= "PASSED";
206 this.status
= "FAILED";
210 this.status
= "ERROR";
214 // for the moment being we don't have a relevant label
217 public String
getStatus() {
221 public String
getMessage() {
225 public String
getExceptionMessage() {
226 return exceptionMessage
;