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