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.awt.GridBagConstraints;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.awt.event.KeyEvent;
28 import java.io.File;
29
30 import javax.swing.JLabel;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33
34 import org.apache.log4j.Logger;
35
36 import fr.ens.transcriptome.doelan.Core;
37 import fr.ens.transcriptome.doelan.Defaults;
38 import fr.ens.transcriptome.doelan.DoelanException;
39 import fr.ens.transcriptome.doelan.DoelanRegistery;
40 import fr.ens.transcriptome.doelan.data.QualityTestSuiteList;
41 import fr.ens.transcriptome.doelan.data.QualityTestSuiteURL;
42 import fr.ens.transcriptome.doelan.io.QualityTestIOFactory;
43 import fr.ens.transcriptome.doelan.io.QualityTestSuiteListIO;
44 import fr.ens.transcriptome.nividic.platform.PlatformException;
45 import fr.ens.transcriptome.nividic.platform.workflow.WorkflowEvent;
46 import fr.ens.transcriptome.nividic.platform.workflow.WorkflowListener;
47 import fr.ens.transcriptome.nividic.util.SystemUtils;
48
49 /***
50 * Main Panel.
51 * @author Laurent Jourdren
52 */
53 public class MainTabWidget extends JPanel implements WorkflowListener {
54
55
56 private static Logger log = Logger.getLogger(MainTabWidget.class);
57
58 private SuiteChooserWidget chooser;
59 private FileChooserWidget gprFileChooser;
60 private FileChooserWidget galFileChooser;
61 private DescriptionWidget descriptionWidget;
62
63
64
65 private javax.swing.JPanel commandPanel;
66 private javax.swing.JButton startButton;
67 private javax.swing.JButton stopButton;
68
69 private StatusWidget status;
70 private QualityTestSuiteURL qtsURL;
71 private boolean working;
72
73
74
75
76
77 /***
78 * Test if the application is working.
79 * @return true if the application is working
80 */
81 private boolean isWorking() {
82 return working;
83 }
84
85
86
87
88
89 /***
90 * Set the state of the application.
91 * @param working The state of the application
92 */
93 public void setWorking(final boolean working) {
94 this.working = working;
95 workingButtons();
96 }
97
98
99
100
101
102 /***
103 * Show the enable/disable state of the start/stop buttons.
104 */
105 private void workingButtons() {
106
107 if (isWorking()) {
108 startButton.setEnabled(false);
109 if (Core.getCore().getTable() != null)
110 Core.getCore().getTable().setStartButtonEnable(false);
111 stopButton.setEnabled(true);
112 } else {
113 startButton.setEnabled(true);
114 if (Core.getCore().getTable() != null)
115 Core.getCore().getTable().setStartButtonEnable(true);
116 stopButton.setEnabled(false);
117 }
118
119 startButton.repaint();
120 stopButton.repaint();
121 }
122
123 private void init() {
124
125
126
127 commandPanel = new javax.swing.JPanel();
128 startButton = new javax.swing.JButton();
129 stopButton = new javax.swing.JButton();
130
131 setLayout(new java.awt.BorderLayout());
132
133 add(new AboutWidget(), java.awt.BorderLayout.NORTH);
134
135 startButton.setText("Start");
136 startButton.setToolTipText("Press this button to launch the test suite");
137 startButton.addActionListener(new ActionListener() {
138 public void actionPerformed(final ActionEvent e) {
139 start();
140 }
141 });
142 commandPanel.add(startButton);
143
144 stopButton.setText("Stop");
145 stopButton
146 .setToolTipText("Press this button to stop the running test suite");
147 stopButton.addActionListener(new ActionListener() {
148 public void actionPerformed(final ActionEvent e) {
149 stop();
150 }
151 });
152 commandPanel.add(stopButton);
153
154 if (!SystemUtils.isMacOsX()) {
155 startButton.setMnemonic(KeyEvent.VK_S);
156 stopButton.setMnemonic(KeyEvent.VK_P);
157 }
158
159 workingButtons();
160
161 add(commandPanel, java.awt.BorderLayout.SOUTH);
162
163 JPanel centerPanel = new JPanel();
164 centerPanel.setLayout(new java.awt.GridBagLayout());
165
166 gprFileChooser = new FileChooserWidget(!DoelanRegistery.isAppletMode(),
167 "Select the GenePix file to analyzed:", KeyEvent.VK_G, ".gpr",
168 "Genepix Result", "Choose GPR file", centerPanel, 0);
169
170 galFileChooser = new FileChooserWidget(!DoelanRegistery.isAppletMode(),
171 "Load the Gene Array List (optional):", KeyEvent.VK_L, ".gal",
172 "Genepix Array List", "Choose GAL file", centerPanel, 2);
173
174
175
176 GridBagConstraints gridBagConstraints;
177 gridBagConstraints = new java.awt.GridBagConstraints();
178 gridBagConstraints.gridx = 0;
179 gridBagConstraints.gridy = 3;
180 gridBagConstraints.ipady = 40;
181 centerPanel.add(new JLabel(""), gridBagConstraints);
182
183
184 descriptionWidget = new DescriptionWidget("Array description (optional):",
185 KeyEvent.VK_D, centerPanel, 3);
186
187
188 gridBagConstraints = new java.awt.GridBagConstraints();
189 gridBagConstraints.gridx = 0;
190 gridBagConstraints.gridy = 4;
191 gridBagConstraints.ipady = 40;
192 centerPanel.add(new JLabel(""), gridBagConstraints);
193
194 chooser = new SuiteChooserWidget(this, centerPanel, 6);
195
196
197 add(centerPanel, java.awt.BorderLayout.CENTER);
198
199
200 gridBagConstraints = new java.awt.GridBagConstraints();
201 gridBagConstraints.gridx = 0;
202 gridBagConstraints.gridy = 7;
203 gridBagConstraints.ipady = 40;
204 centerPanel.add(new JLabel(""), gridBagConstraints);
205
206
207 gridBagConstraints = new java.awt.GridBagConstraints();
208 gridBagConstraints.gridx = 0;
209 gridBagConstraints.gridy = 7;
210 gridBagConstraints.ipady = 40;
211
212 status = new StatusWidget(centerPanel, 10);
213
214 Core.getCore().setStatus(status);
215
216 loadTestSuiteList();
217 }
218
219 /***
220 * Load the list of testsuites
221 */
222 private void loadTestSuiteList() {
223
224 String file = DoelanRegistery.getTestSuiteListFilename();
225
226 log.info("Load test suite list file: " + file);
227
228
229 QualityTestSuiteListIO qtslio = new QualityTestIOFactory()
230 .createQualityTestSuiteListIO(file);
231
232 QualityTestSuiteList tsl = null;
233 boolean oneOrMoreTestSuite;
234
235 try {
236 tsl = qtslio.read();
237 chooser.setTestSuiteList(tsl);
238 oneOrMoreTestSuite = tsl.isATestSuite();
239 } catch (DoelanException e) {
240 oneOrMoreTestSuite = false;
241 chooser.setTestSuiteList(new QualityTestSuiteList());
242 if (DoelanRegistery.isAppletMode())
243 CommonWindow.showMessage(
244 "Unable to read the list os test suites. Start "
245 + Defaults.APP_NAME
246 + " in standalone mode to create test suite lists.", true);
247 }
248
249 if (!oneOrMoreTestSuite) {
250
251 if (DoelanRegistery.isAppletMode())
252 CommonWindow.showMessage("No test suite found. Start "
253 + Defaults.APP_NAME
254 + " in standalone mode to create test suite lists.", true);
255
256 else
257 CommonWindow
258 .showMessage("No test suite found.\n\n"
259 + "Create a TestSuite and add your own test parameters, then\n"
260 + "select your GPR and GAL files and press on Start button.",
261 false);
262 }
263 }
264
265 /***
266 * Load the test suite.
267 */
268 void load() {
269
270 if (Defaults.DEBUG) {
271 try {
272
273 Core.getCore().createDemoWorkflow();
274 this.qtsURL = new QualityTestSuiteURL();
275 this.qtsURL.setName("debug build-in test suite");
276 } catch (DoelanException e) {
277 CommonWindow.showMessage(e.getMessage(), true);
278 }
279 } else {
280
281
282 QualityTestSuiteURL url = chooser.getQualityTestSuiteSelected();
283
284 if (url == null) {
285 CommonWindow.showMessage("No test suite selected", false);
286 setWorking(false);
287 return;
288 }
289
290 if (!(this.qtsURL == url))
291 try {
292 Core.getCore().loadNewWorkflow(url);
293 } catch (DoelanException e) {
294 CommonWindow.showMessage(e.getMessage(), true);
295 }
296
297 this.qtsURL = url;
298 this.status.setTestSuiteName(this.qtsURL.getName());
299 CommonWindow
300 .showStatusBarMessage(this.qtsURL.getName() + " suite loaded");
301
302 final String chipType = this.chooser.getCurrentChipTypeName();
303 final String testSuite = this.chooser.getCurrentTestSuiteName();
304
305 TestSuiteTabWidget.getTestSuiteTabWidget().setChipType(chipType);
306 TestSuiteTabWidget.getTestSuiteTabWidget().setTestSuite(testSuite);
307 }
308
309 }
310
311 /***
312 * Execute the test suite.
313 */
314 private void execute() {
315
316 final Core core = Core.getCore();
317 final StatusWidget status = StatusWidget.getStatusWidget();
318
319 if (!core.isSuite()) {
320
321 return;
322 }
323
324 status.setStatus(StatusWidget.STATUS_STARTED);
325
326 final File gpr;
327 final File gal;
328
329 if (Defaults.DEBUG) {
330 gpr = new File("/home/jourdren/data/2003-11-25-lame20 ARNu12-11_0635.gpr");
331 gal = new File("/home/jourdren/data/2003-11-25-lame20 ARNu12-11_0635.gpr");
332 } else {
333 gpr = gprFileChooser.getFile();
334 gal = galFileChooser.getFile();
335 }
336
337 if (gpr == null && !DoelanRegistery.isAppletMode()) {
338 status.setStatus(StatusWidget.STATUS_NO_DATA_TO_TEST);
339
340 if (!Core.getCore().isAppletMode())
341 JOptionPane.showMessageDialog(this, "You must enter a Genepix file",
342 "Message", JOptionPane.INFORMATION_MESSAGE);
343 return;
344 }
345
346 try {
347
348
349
350 final String chipType = this.chooser.getCurrentChipTypeName();
351 final String testSuite = this.chooser.getCurrentTestSuiteName();
352 final String description = this.descriptionWidget.getDescription();
353
354
355
356
357 core.startWorkflow(chipType, testSuite, gpr == null ? "" : gpr
358 .getAbsolutePath(), gal == null ? "" : gal.getAbsolutePath(),
359 description,
360 DoelanRegistery.isAppletMode() ? core.getApplet() : null, this);
361
362 } catch (DoelanException e) {
363
364 log.error(e.getMessage());
365 CommonWindow.showMessage(e.getMessage(), true);
366 StatusWidget.getStatusWidget().setStatus(StatusWidget.STATUS_ERROR);
367 }
368
369 }
370
371 /***
372 * Start analysis.
373 */
374 public void start() {
375 load();
376 execute();
377 }
378
379 private void stop() {
380
381 try {
382 Core.getCore().stopWorkflow();
383 } catch (PlatformException e) {
384 CommonWindow.showMessage(e.getMessage(), true);
385 }
386
387 }
388
389
390
391
392
393 /***
394 * Invoked when the target of the listener has changed its state.
395 * @param event a WorkflowEvent object
396 */
397 public void workflowStateChanged(final WorkflowEvent event) {
398
399 if (event == null)
400 return;
401
402 switch (event.getId()) {
403 case WorkflowEvent.START_EVENT:
404 setWorking(true);
405 break;
406
407 case WorkflowEvent.END_EVENT:
408 setWorking(false);
409 break;
410
411 default:
412 break;
413 }
414
415 }
416
417 void showStartButton(final boolean show) {
418 this.startButton.setEnabled(show);
419 }
420
421 /***
422 * Throws an execption to a listener.
423 * @param e Exception to throw.
424 */
425 public void workflowNewException(final PlatformException e) {
426
427 log.error(e.getMessage());
428 CommonWindow.showMessage(e.getMessage(), true);
429 StatusWidget.getStatusWidget().setStatus(StatusWidget.STATUS_ERROR);
430 }
431
432
433
434
435
436 /***
437 * Public constructor.
438 */
439 public MainTabWidget() {
440 init();
441 }
442
443 }