1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package fr.ens.transcriptome.doelan.gui;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import fr.ens.transcriptome.doelan.algorithms.DoelanConfigure;
28 import fr.ens.transcriptome.doelan.algorithms.QualityTest;
29 import fr.ens.transcriptome.doelan.algorithms.QualityUnitTest;
30 import fr.ens.transcriptome.doelan.data.QualityTestResult;
31 import fr.ens.transcriptome.doelan.data.QualityUnitTestResult;
32 import fr.ens.transcriptome.nividic.platform.PlatformException;
33 import fr.ens.transcriptome.nividic.platform.module.AboutModule;
34 import fr.ens.transcriptome.nividic.platform.module.Module;
35 import fr.ens.transcriptome.nividic.platform.workflow.Algorithm;
36 import fr.ens.transcriptome.nividic.platform.workflow.AlgorithmEvent;
37 import fr.ens.transcriptome.nividic.platform.workflow.WorkflowElement;
38 import fr.ens.transcriptome.nividic.platform.workflow.gui.WorkflowTableAbstractModel;
39
40 /***
41 * Table model for QualityUnitTest
42 * @author Laurent Jourdren
43 */
44 public class QualityTestSuiteTableModel extends WorkflowTableAbstractModel {
45
46 private Map testsResults = new HashMap();
47 private boolean configurePass;
48
49 private final String[] columnNames = new String[] {"Test name",
50 "Description", "Finished", "Passed"};
51
52 private final Class[] columnClasses = new Class[] {String.class,
53 String.class, Boolean.class, Boolean.class};
54
55
56
57
58
59 /***
60 * Get a result from an algorithm *
61 * @param algorithm Algorithm of the result
62 * @return The result of an algorithm
63 */
64 private QualityUnitTestResult getResult(final Algorithm algorithm) {
65 return (QualityUnitTestResult) this.testsResults.get(algorithm);
66 }
67
68 /***
69 * Get a result from an algorithm *
70 * @param element Workflow element of the result
71 * @return The result of an algorithm
72 */
73 private QualityTestResult getResult(final WorkflowElement element) {
74 if (element == null)
75 return null;
76 return (QualityTestResult) this.testsResults.get(element.getAlgorithm());
77 }
78
79
80
81
82
83 /***
84 * Set a result from an algorithm
85 * @param algorithm Algorithm of the result
86 * @param result to set
87 */
88 private void setResult(final Algorithm algorithm,
89 final QualityTestResult result) {
90
91 if (algorithm == null || result == null)
92 return;
93 this.testsResults.put(algorithm, result);
94 }
95
96
97
98
99
100 /***
101 * Get the name of a column.
102 * @param col number of the column
103 * @return the name of the column
104 */
105 public String getColumnName(final int col) {
106 return columnNames[col];
107 }
108
109 /***
110 * Get the class of a column.
111 * @param col number of the column
112 * @return the class of the column
113 */
114 public Class getColumnClass(final int col) {
115 return columnClasses[col];
116 }
117
118 /***
119 * Get the number of column.
120 * @return the column count
121 */
122 public int getColumnCount() {
123 return columnNames.length;
124 }
125
126 /***
127 * Get a value.
128 * @param rowIndex index of the row
129 * @param columnIndex index of the column
130 * @return An object with the value
131 */
132 public Object getValueAt(final int rowIndex, final int columnIndex) {
133
134 final WorkflowElement wfe = getWorkflowElementAt(rowIndex);
135 Algorithm algo = null;
136
137 if (wfe != null)
138 algo = wfe.getAlgorithm();
139
140 switch (columnIndex) {
141 case 0:
142 if (wfe == null)
143 return null;
144 return "" + wfe.getId();
145
146 case 1:
147
148 if (algo == null || !(algo instanceof Module))
149 return null;
150
151 return ((Module) algo).aboutModule().getShortDescription();
152
153 case 2:
154
155 if (algo == null || algo instanceof DoelanConfigure)
156 return new Boolean(this.configurePass);
157
158 QualityTestResult result1 = getResult(wfe);
159 return new Boolean(result1 != null);
160
161 case 3:
162
163 if (algo == null || algo instanceof DoelanConfigure)
164 return new Boolean(this.configurePass);
165
166 QualityTestResult result2 = getResult(wfe);
167 return new Boolean(result2 == null ? false : result2.getResult());
168
169 default:
170 return null;
171 }
172 }
173
174 /***
175 * Get the tip
176 * @param row the row number
177 * @return The tip about the test
178 */
179 public String getTip(final int row) {
180
181 final WorkflowElement wfe = getWorkflowElementAt(row);
182 final Algorithm algo = wfe.getAlgorithm();
183
184 if (algo instanceof Module)
185
186 return "Description : "
187 + ((Module) algo).aboutModule().getShortDescription();
188
189 return null;
190 }
191
192 /***
193 * Returns true if the cell at rowIndex and columnIndex is editable.
194 * Otherwise, setValueAt on the cell will not change the value of that cell.
195 * @param rowIndex the row whose value to be queried
196 * @param columnIndex the column whose value to be queried
197 * @return true if the cell is editable
198 */
199 public boolean isCellEditable(final int rowIndex, final int columnIndex) {
200
201 return false;
202 }
203
204 /***
205 * Sets the value in the cell at columnIndex and rowIndex to aValue.
206 * @param aValue the new value
207 * @param rowIndex the row whose value is to be changed
208 * @param columnIndex the column whose value is to be changed
209 */
210 public void setValueAt(final Object aValue, final int rowIndex,
211 final int columnIndex) {
212
213 if (columnIndex != 0)
214 return;
215
216 final WorkflowElement wfe = getWorkflowElementAt(rowIndex);
217 final QualityUnitTest test = (QualityUnitTest) wfe.getAlgorithm();
218
219 if (aValue == null || !(aValue instanceof String))
220 return;
221
222 }
223
224
225
226
227
228 /***
229 * Test if an element is a showable Workflow element.
230 * @param element Element to test
231 * @return true if the element to test is showable Workflow element
232 */
233 public boolean filterWorkflowElement(final WorkflowElement element) {
234
235 if (element == null)
236 return false;
237 final Algorithm algo = element.getAlgorithm();
238 if (algo == null)
239 return false;
240
241 if (algo instanceof QualityTest)
242 return ((QualityTest) algo).isShowable();
243
244 return false;
245 }
246
247 /***
248 * Test if an algorithm is a showable quality test.
249 * @param about Information about the algorithm
250 * @param algorithm Algorithm to test
251 * @return true if the algorithm to test is showable
252 */
253 public boolean filterModule(final AboutModule about,
254 final Algorithm algorithm, final boolean local) {
255
256 if (!local || algorithm == null)
257 return false;
258
259 if (algorithm instanceof QualityTest)
260 return ((QualityTest) algorithm).isShowable();
261
262 return false;
263 }
264
265
266
267
268
269 /***
270 * Handle algorithm events
271 * @param e Algorithm event
272 */
273 public void algorithmStateChanged(final AlgorithmEvent e) {
274
275 if (e == null)
276 return;
277
278 if (e.getId() == QualityTest.RESULT_EVENT
279 || e.getId() == QualityTest.CONFIGURE_TEST_EVENT) {
280
281 final QualityTest qut = (QualityTest) e.getSource();
282 final int pos = getRowAlgorithm(qut);
283
284 if (e.getId() == QualityTest.RESULT_EVENT)
285 setResult(qut, (QualityTestResult) e.getObjectValue());
286 else
287 this.configurePass = true;
288
289 fireTableCellUpdated(pos, 3);
290 fireTableCellUpdated(pos, 2);
291 }
292
293 }
294
295 /***
296 * Throws an execption to a listener.
297 * @param e Exception to throw.
298 */
299 public void workflowNewException(final PlatformException e) {
300 }
301
302
303
304
305
306 /***
307 * Clear results.
308 */
309 public void clearResults() {
310 this.testsResults.clear();
311 }
312
313
314
315
316
317 public QualityTestSuiteTableModel() {
318 super();
319 }
320
321 }