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.Container;
028: import java.awt.Dimension;
029: import java.awt.FlowLayout;
030: import java.awt.Font;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.util.ArrayList;
034: import java.util.Collection;
035: import java.util.HashMap;
036: import java.util.Iterator;
037: import java.util.Vector;
038:
039: import javax.swing.BorderFactory;
040: import javax.swing.BoxLayout;
041: import javax.swing.ImageIcon;
042: import javax.swing.JButton;
043: import javax.swing.JDialog;
044: import javax.swing.JLabel;
045: import javax.swing.JPanel;
046: import javax.swing.JScrollPane;
047: import javax.swing.JTable;
048: import javax.swing.ListSelectionModel;
049: import javax.swing.event.ListSelectionEvent;
050: import javax.swing.event.ListSelectionListener;
051:
052: import org.objectweb.salome_tmf.api.Api;
053: import org.objectweb.salome_tmf.data.Attachment;
054: import org.objectweb.salome_tmf.data.DataConstants;
055: import org.objectweb.salome_tmf.data.ExecutionResult;
056: import org.objectweb.salome_tmf.data.FileAttachment;
057: import org.objectweb.salome_tmf.data.ManualTest;
058: import org.objectweb.salome_tmf.data.Test;
059: import org.objectweb.salome_tmf.data.TestPlanData;
060: import org.objectweb.salome_tmf.data.UrlAttachment;
061: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
062: import org.objectweb.salome_tmf.ihm.languages.Language;
063: import org.objectweb.salome_tmf.ihm.models.ActionDetailsResultMouseListener;
064: import org.objectweb.salome_tmf.ihm.models.AutomaticTestResultMouseListener;
065: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
066: import org.objectweb.salome_tmf.ihm.models.TableSorter;
067: import org.objectweb.salome_tmf.ihm.plugins.PluginsTools;
068: import org.objectweb.salome_tmf.ihm.tools.Tools;
069:
070: /**
071: * Classe repr?sentant la vue sur les ex?cutions de test
072: * @author teaml039
073: * @version 0.1
074: */
075: public class ExecutionResultView extends JDialog implements
076: DataConstants, IHMConstants {
077:
078: /**
079: * Mod?le de donn?es de la table
080: */
081: MyTableModel testResultTableModel;
082:
083: /**
084: * Table des r?sultats sur les tests
085: */
086: JTable testResultTable;
087: TableSorter sorter;
088:
089: ListSelectionModel rowSM;
090:
091: ExecutionResult currentExecResult;
092:
093: JButton detailsButton;
094:
095: /******************************************************************************/
096: /** CONSTRUCTEUR ***/
097: /******************************************************************************/
098:
099: /**
100: * Constructeur de la vue sur les ex?cutions de tests
101: * @param name le label d'information sur l'ex?cution
102: */
103: public ExecutionResultView(String name,
104: ExecutionResult executionResult) {
105:
106: super (SalomeTMF.ptrFrame, true);
107: testResultTableModel = new MyTableModel();
108: testResultTable = new JTable();
109: JLabel executionName = new JLabel(name);
110: executionName.setFont(new Font(null, Font.BOLD, 18));
111:
112: testResultTableModel.addColumnNameAndColumn(Language
113: .getInstance().getText("Famille"));
114: testResultTableModel.addColumnNameAndColumn(Language
115: .getInstance().getText("Suite"));
116: testResultTableModel.addColumnNameAndColumn(Language
117: .getInstance().getText("Test"));
118: testResultTableModel.addColumnNameAndColumn(Language
119: .getInstance().getText("Résultats"));
120:
121: sorter = new TableSorter(testResultTableModel);
122: testResultTable.setModel(sorter);
123: //testResultTable.setModel(testResultTableModel);
124:
125: sorter.setTableHeader(testResultTable.getTableHeader());
126:
127: testResultTable
128: .setPreferredScrollableViewportSize(new Dimension(600,
129: 200));
130: testResultTable
131: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
132:
133: // Mapping entre objets graphiques et constantes
134: SalomeTMF.addToUIComponentsMap(
135: UICompCst.EXECUTION_RESULT_DETAILS_TESTS_TABLE,
136: testResultTable);
137: // Activation des plugins associ?s
138: PluginsTools
139: .activateAssociatedPlgs(UICompCst.EXECUTION_RESULT_DETAILS_TESTS_TABLE);
140:
141: JScrollPane tablePane = new JScrollPane(testResultTable);
142: tablePane.setBorder(BorderFactory.createRaisedBevelBorder());
143:
144: rowSM = testResultTable.getSelectionModel();
145: rowSM.addListSelectionListener(new ListSelectionListener() {
146: public void valueChanged(ListSelectionEvent e) {
147: if (e.getValueIsAdjusting())
148: return;
149:
150: int selectedRowIndex = testResultTable.getSelectedRow();
151: if (selectedRowIndex != -1
152: && testResultTableModel.getRowCount() > 0) {
153: Test test = TestPlanData.getTest((String) sorter
154: .getValueAt(selectedRowIndex, 0),
155: (String) sorter.getValueAt(
156: selectedRowIndex, 1),
157: (String) sorter.getValueAt(
158: selectedRowIndex, 2));
159: DataModel.setTestObservedInExecution(test);
160: DataModel
161: .setCurrentExecutionTestResult(currentExecResult
162: .getExecutionTestResult(test));
163: detailsButton.setEnabled(true);
164: } else {
165: detailsButton.setEnabled(false);
166: }
167: }
168: });
169:
170: // Gestion de la souris
171: testResultTable
172: .addMouseListener(new ActionDetailsResultMouseListener());
173: testResultTable
174: .addMouseListener(new AutomaticTestResultMouseListener());
175:
176: JButton quitButton = new JButton(Language.getInstance()
177: .getText("Terminer"));
178: quitButton.addActionListener(new ActionListener() {
179: public void actionPerformed(ActionEvent e) {
180: ExecutionResultView.this .dispose();
181: }
182: });
183:
184: detailsButton = new JButton(Language.getInstance().getText(
185: "Détails"));
186: detailsButton.setEnabled(false);
187: detailsButton.addActionListener(new ActionListener() {
188: public void actionPerformed(ActionEvent e) {
189: if (DataModel.getTestObservedInExecution() instanceof ManualTest) {
190: new ActionDetailsView((ManualTest) DataModel
191: .getTestObservedInExecution(), DataModel
192: .getObservedExecution(), DataModel
193: .getObservedExecutionResult(), DataModel
194: .getCurrentExecutionTestResult());
195: } else {
196: HashMap oldAttachMap = (HashMap) DataModel
197: .getCurrentExecutionTestResult()
198: .getAttachmentMap().clone();
199: AttachmentViewWindow attachWindow = new AttachmentViewWindow(
200: SalomeTMF.ptrSalomeTMF,
201: EXECUTION_RESULT_TEST, DataModel
202: .getCurrentExecutionTestResult(),
203: DataModel.getObservedExecution(), DataModel
204: .getObservedExecutionResult(),
205: DataModel.getTestObservedInExecution());
206:
207: if (!attachWindow.cancelPerformed) {
208: int transNumber = -1;
209: try {
210: Api
211: .log("[ExecutionResultView] Api.INSERT_ATTACHMENT");
212: transNumber = Api
213: .beginTransaction(Api.INSERT_ATTACHMENT);
214: Vector oldFileAttachNamesVector = DataModel
215: .getObservedExecutionResult()
216: .getExecTestResAttachFilesFromDB(
217: DataModel
218: .getTestObservedInExecution()
219: .getIdBDD());
220: // Liste des anciennes urls attach?es
221: Vector oldUrlAttachVector = DataModel
222: .getObservedExecutionResult()
223: .getExecTestResAttachUrlsFromDB(
224: DataModel
225: .getTestObservedInExecution()
226: .getIdBDD());
227: Collection attachValues = DataModel
228: .getCurrentExecutionTestResult()
229: .getAttachmentMap().values();
230: for (Iterator iter = attachValues
231: .iterator(); iter.hasNext();) {
232: Attachment attach = (Attachment) iter
233: .next();
234: if (attach instanceof FileAttachment) {
235: if (!oldFileAttachNamesVector
236: .contains(attach.getName())) {
237: DataModel
238: .getObservedExecutionResult()
239: .addAttachFile2ExecTestResInDB(
240: DataModel
241: .getTestObservedInExecution()
242: .getIdBDD(),
243: (FileAttachment) attach);
244: }
245: } else {
246: if (!oldUrlAttachVector
247: .contains(attach.getName())) {
248: DataModel
249: .getObservedExecutionResult()
250: .addAttachUrl2ExecTestResInDB(
251: DataModel
252: .getTestObservedInExecution()
253: .getIdBDD(),
254: (UrlAttachment) attach);
255: }
256: }
257: oldAttachMap.remove(attach.getName());
258: }
259:
260: attachValues = oldAttachMap.values();
261: for (Iterator iter = attachValues
262: .iterator(); iter.hasNext();) {
263: Attachment attach = (Attachment) iter
264: .next();
265: if ((oldFileAttachNamesVector
266: .contains(attach.getName()))
267: || (oldUrlAttachVector
268: .contains(attach
269: .getName())))
270: currentExecResult
271: .deleteAttachFromExecTestResultInDB(
272: DataModel
273: .getTestObservedInExecution()
274: .getIdBDD(),
275: attach.getIdBdd());
276: }
277: Api.commitTrans(transNumber);
278:
279: } catch (Exception exception) {
280: Api.forceRollBackTrans(transNumber);
281: DataModel.getCurrentExecutionTestResult()
282: .setAttachmentMap(oldAttachMap);
283: Tools
284: .ihmExceptionView(exception
285: .toString());
286: }
287: }
288:
289: }
290:
291: }
292: });
293:
294: JPanel upPart = new JPanel(new BorderLayout());
295: upPart.add(executionName, BorderLayout.NORTH);
296:
297: JPanel allView = new JPanel(new BorderLayout());
298:
299: allView.add(upPart, BorderLayout.NORTH);
300: allView.add(tablePane, BorderLayout.CENTER);
301:
302: JPanel buttonPanel = new JPanel(new FlowLayout(
303: FlowLayout.CENTER));
304: buttonPanel.add(detailsButton);
305: buttonPanel.add(quitButton);
306:
307: JPanel panel = new JPanel();
308: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
309: panel.add(allView);
310: panel.add(buttonPanel);
311:
312: initTestResults(executionResult);
313:
314: Container contentPaneFrame = this .getContentPane();
315: contentPaneFrame.add(panel, BorderLayout.CENTER);
316: this .setLocation(400, 300);
317: this .setTitle(Language.getInstance().getText(
318: "Résultats_d'exécution"));
319: this .pack();
320: this .setVisible(true);
321:
322: } // Fin du constructeur ExecutionResult/1
323:
324: /**
325: *
326: * @param executionResult
327: */
328: public void initTestResults(ExecutionResult executionResult) {
329:
330: Test[] pTabTest = executionResult.getTestOrdered();
331: for (int j = 0; j < pTabTest.length; j++) {
332: Test test = pTabTest[j];
333: ArrayList data = new ArrayList();
334: data.add(test.getTestList().getFamily().toString());
335: data.add(test.getTestList().toString());
336: data.add(test.toString());
337: ImageIcon image = Tools.getActionStatusIcon(executionResult
338: .getTestResultStatus(test));
339: if (image == null) {
340: data.add(Tools.createAppletImageIcon(PATH_TO_GOON_ICON,
341: ""));
342: } else {
343: data.add(Tools.getActionStatusIcon(executionResult
344: .getTestResultStatus(test)));
345:
346: }
347: currentExecResult = executionResult;
348: testResultTableModel.addRow(data);
349:
350: }
351: } // Fin de la m?thode initTestResults/1
352:
353: } // Fin de la classe ExecutionResult
|