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.main;
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.Rectangle;
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035: import java.awt.event.WindowEvent;
036: import java.awt.event.WindowListener;
037: import java.util.ArrayList;
038:
039: import javax.swing.Box;
040: import javax.swing.BoxLayout;
041: import javax.swing.JButton;
042: import javax.swing.JDialog;
043: import javax.swing.JLabel;
044: import javax.swing.JPanel;
045:
046: import org.objectweb.salome_tmf.api.ApiConstants;
047: import org.objectweb.salome_tmf.data.AutomaticTest;
048: import org.objectweb.salome_tmf.data.Execution;
049: import org.objectweb.salome_tmf.data.ExecutionResult;
050: import org.objectweb.salome_tmf.data.ExecutionTestResult;
051: import org.objectweb.salome_tmf.data.Script;
052: import org.objectweb.salome_tmf.ihm.IHMConstants;
053: import org.objectweb.salome_tmf.ihm.languages.Language;
054: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
055: import org.objectweb.salome_tmf.ihm.main.datawrapper.TestMethods;
056: import org.objectweb.salome_tmf.ihm.models.ScriptExecutionException;
057: import org.objectweb.salome_tmf.ihm.tools.Tools;
058:
059: /**
060: * @author teaml039
061: */
062: public class AutomaticExecution extends JDialog implements
063: ApiConstants, Runnable, IHMConstants {
064:
065: /**
066: * Label du test
067: */
068: JLabel testName;
069:
070: /**
071: * Vrai si l'utilisateur a interrompu l'ex?cution
072: */
073: boolean executionInterruption;
074:
075: /**
076: * Label du r?sultat
077: */
078: JLabel resultLabel;
079:
080: Execution exec;
081:
082: ArrayList automaticTestList;
083:
084: // REMOVE FOR V2 EXEC
085: //ArrayList execResultList;
086:
087: Thread t;
088:
089: //ExecutionView execView;
090:
091: boolean stop_exec = false;
092: /**
093: * Constructeur.
094: * @param list
095: */
096: ExecutionResult finalExecResult;
097:
098: boolean finished = false;
099:
100: public AutomaticExecution(ArrayList autoTestList,
101: Execution execution, ExecutionResult finalExecResult) {
102:
103: super (SalomeTMFContext.getInstance().ptrFrame);
104: this .finalExecResult = finalExecResult;
105: resultLabel = new JLabel();
106: exec = execution;
107: finished = false;
108: // REMOVE FOR V2 EXEC
109: //this.execResultList = executionResultList;
110:
111: this .automaticTestList = autoTestList;
112: //this.execView = execView;
113: testName = new JLabel("");
114: testName.setBackground(Color.WHITE);
115:
116: JLabel runLabel = new JLabel(Language.getInstance().getText(
117: "est_en_cours_d'_exécution..."));
118: runLabel.setBackground(Color.WHITE);
119:
120: // Bouton d'annulation
121: JButton cancelButton = new JButton(Language.getInstance()
122: .getText("Annuler"));
123: cancelButton.addActionListener(new ActionListener() {
124: public void actionPerformed(ActionEvent e) {
125: TestMethods.annulScript();
126: stop_exec = true;
127: finished = true;
128: AutomaticExecution.this .finalExecResult
129: .setExecutionStatusInModel(INTERRUPT);
130: AutomaticExecution.this .dispose();
131: }
132: });
133:
134: // Bouton d'annulation
135: JButton termineButton = new JButton(Language.getInstance()
136: .getText("Terminer"));
137: termineButton.addActionListener(new ActionListener() {
138: public void actionPerformed(ActionEvent e) {
139: TestMethods.annulScript();
140: stop_exec = true;
141: finished = true;
142: AutomaticExecution.this .dispose();
143: }
144: });
145:
146: JPanel cancelButtonPanel = new JPanel(new FlowLayout(
147: FlowLayout.RIGHT));
148: cancelButtonPanel.add(cancelButton);
149: cancelButtonPanel.add(termineButton);
150: cancelButtonPanel.setBackground(Color.WHITE);
151:
152: // Modification du curseur
153: try {
154: Cursor c = new Cursor(Cursor.WAIT_CURSOR);
155: this .setCursor(c);
156: } catch (Exception e) {
157:
158: }
159: // Images des engrenages
160: JLabel imageLabel = new JLabel();
161: imageLabel.setIcon(Tools.createAppletImageIcon(
162: PATH_TO_ENGRENAGE_ICON, ""));
163:
164: JPanel textPanel = new JPanel();
165: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
166: textPanel.add(testName);
167: textPanel.add(Box.createRigidArea(new Dimension(10, 5)));
168: textPanel.add(runLabel);
169: textPanel.add(Box.createRigidArea(new Dimension(10, 5)));
170: textPanel.add(resultLabel);
171: textPanel.add(Box.createRigidArea(new Dimension(10, 5)));
172: textPanel.add(cancelButtonPanel);
173: textPanel.setBackground(Color.WHITE);
174:
175: JPanel page = new JPanel(new FlowLayout(FlowLayout.LEFT));
176:
177: page.add(imageLabel);
178: page.add(Box.createRigidArea(new Dimension(10, 1)));
179: page.add(textPanel);
180: page.setBackground(Color.WHITE);
181: page.setPreferredSize(new Dimension(500, 100));
182:
183: this .addWindowListener(new WindowListener() {
184: public void windowClosing(WindowEvent e) {
185: TestMethods.annulScript();
186: finished = true;
187: stop_exec = true;
188: }
189:
190: public void windowDeiconified(WindowEvent e) {
191: }
192:
193: public void windowOpened(WindowEvent e) {
194: }
195:
196: public void windowActivated(WindowEvent e) {
197: }
198:
199: public void windowDeactivated(WindowEvent e) {
200: }
201:
202: public void windowClosed(WindowEvent e) {
203: }
204:
205: public void windowIconified(WindowEvent e) {
206: }
207: });
208:
209: Container contentPaneFrame = this .getContentPane();
210: contentPaneFrame.add(page, BorderLayout.CENTER);
211:
212: this .setTitle(Language.getInstance().getText(
213: "Execution_d'un_test_automatique_(exéc._en_cours_:_")
214: + execution.getNameFromModel() + ")");
215: /**this.setLocationRelativeTo(this.getParent());
216: this.pack();
217: */
218: centerScreen();
219: }
220:
221: void centerScreen() {
222: Dimension dim = getToolkit().getScreenSize();
223: this .pack();
224: Rectangle abounds = getBounds();
225: setLocation((dim.width - abounds.width) / 2,
226: (dim.height - abounds.height) / 2);
227: //this.setVisible(true);
228: //requestFocus();
229: }
230:
231: public void lauchAutomaticExecution() {
232: t = new Thread(this );
233: t.start();
234: }
235:
236: // methode de l'interface Runnable
237: // lance un nouveau thread qui va executer le code de la methode longTraitement
238: public void run() {
239: if (SalomeTMFContext.getInstance().getSalomeFrame() != null) {
240: this .setVisible(true);
241: }
242: stop_exec = false;
243: this .automaticExecution();
244: }
245:
246: public void automaticExecution() {
247: ExecutionResult execResult = finalExecResult;
248: String result = null;
249: int i = 0;
250: while (i < automaticTestList.size() && !stop_exec) {
251: AutomaticTest test = (AutomaticTest) automaticTestList
252: .get(i);
253: ExecutionTestResult execTestResult = null;
254:
255: execTestResult = finalExecResult
256: .getExecutionTestResultFromModel(test);
257: if (execTestResult == null) {
258: execTestResult = new ExecutionTestResult(test);
259: }
260:
261: //Maj de la fen?tre
262: this .setTestNameLabel(((AutomaticTest) automaticTestList
263: .get(i)).getNameFromModel());
264: this .setTestResultLabel(Language.getInstance().getText(
265: "Résultat_:_"));
266: Script script = test.getScriptFromModel();
267: if (script != null && !script.getNameFromModel().equals("")) {
268: try {
269: execTestResult.setStatusInModel("");
270: result = TestMethods.callScript(exec
271: .getDataSetFromModel()
272: .getParametersHashMapFromModel(), script,
273: test, DataModel.getCurrentCampaign(),
274: DataModel.getCurrentProject(), exec
275: .getEnvironmentFromModel(),
276: execResult, exec, execTestResult);
277: execTestResult.setStatusInModel(result);
278: } catch (ScriptExecutionException see) {
279: // ne peut pas se produire en principe
280: TestMethods.fileCreationAndAttachToExecResult(
281: execResult, execTestResult, see
282: .getMessage(), exec, Language
283: .getInstance().getText(
284: "erreur_exec_")
285: + test.getNameFromModel());
286: }
287:
288: this .setTestResultLabel(Language.getInstance().getText(
289: "Résultat_:_")
290: + result);
291: execResult
292: .setTestExecutionTestResultInModel(
293: ((AutomaticTest) automaticTestList
294: .get(i)),
295: execTestResult,
296: exec
297: .getCampagneFromModel()
298: .getTestOrderInModel(
299: ((AutomaticTest) automaticTestList
300: .get(i))));
301: } else {
302: this .setTestResultLabel(Language.getInstance().getText(
303: "Résultat_:_")
304: + SUCCESS);
305: execTestResult.setStatusInModel(SUCCESS);
306: execResult
307: .setTestExecutionTestResultInModel(
308: ((AutomaticTest) automaticTestList
309: .get(i)),
310: execTestResult,
311: exec
312: .getCampagneFromModel()
313: .getTestOrderInModel(
314: ((AutomaticTest) automaticTestList
315: .get(i))));
316:
317: }
318:
319: i++;
320: }
321:
322: /*if (stop_exec == true) {
323: execResult.setExecutionStatus(INTERRUPT);
324: }
325: */
326:
327: finished = true;
328: this .dispose();
329: }
330:
331: /**
332: * @param label
333: */
334: public void setTestNameLabel(String text) {
335: testName.setText(text);
336: }
337:
338: /**
339: * @param label
340: */
341: public void setTestResultLabel(String text) {
342: resultLabel.setText(text);
343: }
344:
345: public boolean isFinished() {
346: return finished;
347: }
348:
349: public boolean isStoped() {
350: return stop_exec;
351: }
352:
353: public void setFinished(boolean b) {
354: finished = b;
355: }
356:
357: } // Fin de la classe AutomaticExecution
|