001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Color;
028: import java.awt.Container;
029: import java.awt.Cursor;
030: import java.awt.Dimension;
031: import java.awt.FlowLayout;
032: import java.awt.event.ActionEvent;
033: import java.awt.event.ActionListener;
034: import java.awt.event.WindowEvent;
035: import java.awt.event.WindowListener;
036: import java.util.ArrayList;
037:
038: import javax.swing.Box;
039: import javax.swing.BoxLayout;
040: import javax.swing.JButton;
041: import javax.swing.JFrame;
042: import javax.swing.JLabel;
043: import javax.swing.JPanel;
044:
045: import org.objectweb.salome_tmf.api.ApiConstants;
046: import org.objectweb.salome_tmf.data.AutomaticTest;
047: import org.objectweb.salome_tmf.data.Execution;
048: import org.objectweb.salome_tmf.data.ExecutionResult;
049: import org.objectweb.salome_tmf.data.ExecutionTestResult;
050: import org.objectweb.salome_tmf.data.ProjectData;
051: import org.objectweb.salome_tmf.data.Script;
052: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
053: import org.objectweb.salome_tmf.ihm.datawrapper.TestMethods;
054: import org.objectweb.salome_tmf.ihm.languages.Language;
055: import org.objectweb.salome_tmf.ihm.models.ScriptExecutionException;
056: import org.objectweb.salome_tmf.ihm.tools.Tools;
057:
058: /**
059: * @author teaml039
060: */
061: public class AutomaticExecution extends JFrame implements ApiConstants,
062: Runnable, IHMConstants {
063:
064: /**
065: * Label du test
066: */
067: JLabel testName;
068:
069: /**
070: * Vrai si l'utilisateur a interrompu l'ex?cution
071: */
072: boolean executionInterruption;
073:
074: /**
075: * Label du r?sultat
076: */
077: JLabel resultLabel;
078:
079: Execution exec;
080:
081: ArrayList automaticTestList;
082:
083: // REMOVE FOR V2 EXEC
084: //ArrayList execResultList;
085:
086: Thread t;
087:
088: //ExecutionView execView;
089:
090: boolean stop_exec = false;
091: /**
092: * Constructeur.
093: * @param list
094: */
095: ExecutionResult finalExecResult;
096:
097: boolean finished = false;
098:
099: public AutomaticExecution(ArrayList autoTestList,
100: Execution execution, ExecutionResult finalExecResult) {
101:
102: super ();
103: this .finalExecResult = finalExecResult;
104: resultLabel = new JLabel();
105: exec = execution;
106: finished = false;
107: // REMOVE FOR V2 EXEC
108: //this.execResultList = executionResultList;
109:
110: this .automaticTestList = autoTestList;
111: //this.execView = execView;
112: testName = new JLabel("");
113: testName.setBackground(Color.WHITE);
114:
115: JLabel runLabel = new JLabel(Language.getInstance().getText(
116: "est_en_cours_d'_exécution..."));
117: runLabel.setBackground(Color.WHITE);
118:
119: // Bouton d'annulation
120: JButton cancelButton = new JButton(Language.getInstance()
121: .getText("Annuler"));
122: cancelButton.addActionListener(new ActionListener() {
123: public void actionPerformed(ActionEvent e) {
124: TestMethods.annulScript();
125: stop_exec = true;
126: finished = true;
127: AutomaticExecution.this .finalExecResult
128: .setExecutionStatus(INTERRUPT);
129: AutomaticExecution.this .dispose();
130: }
131: });
132:
133: // Bouton d'annulation
134: JButton termineButton = new JButton(Language.getInstance()
135: .getText("Terminer"));
136: termineButton.addActionListener(new ActionListener() {
137: public void actionPerformed(ActionEvent e) {
138: TestMethods.annulScript();
139: stop_exec = true;
140: finished = true;
141: AutomaticExecution.this .dispose();
142: }
143: });
144:
145: JPanel cancelButtonPanel = new JPanel(new FlowLayout(
146: FlowLayout.RIGHT));
147: cancelButtonPanel.add(cancelButton);
148: cancelButtonPanel.add(termineButton);
149: cancelButtonPanel.setBackground(Color.WHITE);
150:
151: // Modification du curseur
152: try {
153: Cursor c = new Cursor(Cursor.WAIT_CURSOR);
154: this .setCursor(c);
155: } catch (Exception e) {
156:
157: }
158: // Images des engrenages
159: JLabel imageLabel = new JLabel();
160: imageLabel.setIcon(Tools.createAppletImageIcon(
161: PATH_TO_ENGRENAGE_ICON, ""));
162:
163: JPanel textPanel = new JPanel();
164: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
165: textPanel.add(testName);
166: textPanel.add(Box.createRigidArea(new Dimension(10, 5)));
167: textPanel.add(runLabel);
168: textPanel.add(Box.createRigidArea(new Dimension(10, 5)));
169: textPanel.add(resultLabel);
170: textPanel.add(Box.createRigidArea(new Dimension(10, 5)));
171: textPanel.add(cancelButtonPanel);
172: textPanel.setBackground(Color.WHITE);
173:
174: JPanel page = new JPanel(new FlowLayout(FlowLayout.LEFT));
175:
176: page.add(imageLabel);
177: page.add(Box.createRigidArea(new Dimension(10, 1)));
178: page.add(textPanel);
179: page.setBackground(Color.WHITE);
180: page.setPreferredSize(new Dimension(500, 100));
181:
182: this .addWindowListener(new WindowListener() {
183: public void windowClosing(WindowEvent e) {
184: TestMethods.annulScript();
185: finished = true;
186: stop_exec = true;
187: }
188:
189: public void windowDeiconified(WindowEvent e) {
190: }
191:
192: public void windowOpened(WindowEvent e) {
193: }
194:
195: public void windowActivated(WindowEvent e) {
196: }
197:
198: public void windowDeactivated(WindowEvent e) {
199: }
200:
201: public void windowClosed(WindowEvent e) {
202: }
203:
204: public void windowIconified(WindowEvent e) {
205: }
206: });
207:
208: Container contentPaneFrame = this .getContentPane();
209: contentPaneFrame.add(page, BorderLayout.CENTER);
210:
211: this .setLocation(300, 300);
212: this .setTitle(Language.getInstance().getText(
213: "Execution_d'un_test_automatique_(exéc._en_cours_:_")
214: + execution.getName() + ")");
215: this .pack();
216:
217: }
218:
219: public void lauchAutomaticExecution() {
220: t = new Thread(this );
221: t.start();
222: }
223:
224: // methode de l'interface Runnable
225: // lance un nouveau thread qui va executer le code de la methode longTraitement
226: public void run() {
227: this .setVisible(true);
228: stop_exec = false;
229: this .automaticExecution();
230: }
231:
232: public void automaticExecution() {
233: ExecutionResult execResult = finalExecResult;
234: String result = null;
235: int i = 0;
236: while (i < automaticTestList.size() && !stop_exec) {
237: ExecutionTestResult execTestResult = new ExecutionTestResult();
238: AutomaticTest test = (AutomaticTest) automaticTestList
239: .get(i);
240: execTestResult.setTest(test);
241: //Maj de la fen?tre
242: this .setTestNameLabel(((AutomaticTest) automaticTestList
243: .get(i)).getName());
244: this .setTestResultLabel(Language.getInstance().getText(
245: "Résultat_:_"));
246: Script script = test.getScript();
247: if (script != null && !script.getName().equals("")) {
248: try {
249: execTestResult.setStatus("");
250: result = TestMethods.callScript(exec.getDataSet()
251: .getParametersHashMap(), script, test,
252: DataModel.getCurrentCampaign(), ProjectData
253: .getCurrentProject(), exec
254: .getEnvironment(), execResult,
255: exec, execTestResult);
256: execTestResult.setStatus(result);
257: } catch (ScriptExecutionException see) {
258: // ne peut pas se produire en principe
259: TestMethods.fileCreationAndAttachToExecResult(
260: execResult, execTestResult, see
261: .getMessage(), exec, Language
262: .getInstance().getText(
263: "erreur_exec_")
264: + test.getName());
265: }
266:
267: this .setTestResultLabel(Language.getInstance().getText(
268: "Résultat_:_")
269: + result);
270: execResult.setTestExecutionTestResult(
271: ((AutomaticTest) automaticTestList.get(i)),
272: execTestResult,
273: exec.getCampagne().getTestOrder(
274: ((AutomaticTest) automaticTestList
275: .get(i))));
276: } else {
277: this .setTestResultLabel(Language.getInstance().getText(
278: "Résultat_:_")
279: + SUCCESS);
280: execTestResult.setStatus(SUCCESS);
281: execResult.setTestExecutionTestResult(
282: ((AutomaticTest) automaticTestList.get(i)),
283: execTestResult,
284: exec.getCampagne().getTestOrder(
285: ((AutomaticTest) automaticTestList
286: .get(i))));
287:
288: }
289:
290: i++;
291: }
292:
293: /*if (stop_exec == true) {
294: execResult.setExecutionStatus(INTERRUPT);
295: }
296: */
297:
298: finished = true;
299: this .dispose();
300: }
301:
302: /**
303: * @param label
304: */
305: public void setTestNameLabel(String text) {
306: testName.setText(text);
307: }
308:
309: /**
310: * @param label
311: */
312: public void setTestResultLabel(String text) {
313: resultLabel.setText(text);
314: }
315:
316: public boolean isFinished() {
317: return finished;
318: }
319:
320: public boolean isStoped() {
321: return stop_exec;
322: }
323:
324: public void setFinished(boolean b) {
325: finished = b;
326: }
327:
328: } // Fin de la classe AutomaticExecution
|