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.Dimension;
030: import java.awt.FlowLayout;
031: import java.awt.Font;
032: import java.awt.GraphicsConfiguration;
033: import java.awt.GraphicsDevice;
034: import java.awt.GraphicsEnvironment;
035: import java.awt.Rectangle;
036: import java.awt.event.ActionEvent;
037: import java.awt.event.ActionListener;
038: import java.util.ArrayList;
039: import java.util.HashMap;
040:
041: import javax.swing.BorderFactory;
042: import javax.swing.BoxLayout;
043: import javax.swing.JButton;
044: import javax.swing.JDialog;
045: import javax.swing.JLabel;
046: import javax.swing.JPanel;
047: import javax.swing.JScrollPane;
048: import javax.swing.JTabbedPane;
049: import javax.swing.JTable;
050: import javax.swing.JTextPane;
051: import javax.swing.ListSelectionModel;
052: import javax.swing.event.ListSelectionEvent;
053: import javax.swing.event.ListSelectionListener;
054:
055: import org.objectweb.salome_tmf.api.Api;
056: import org.objectweb.salome_tmf.api.ApiConstants;
057: import org.objectweb.salome_tmf.data.Action;
058: import org.objectweb.salome_tmf.data.DataConstants;
059: import org.objectweb.salome_tmf.data.Execution;
060: import org.objectweb.salome_tmf.data.ExecutionResult;
061: import org.objectweb.salome_tmf.data.ExecutionTestResult;
062: import org.objectweb.salome_tmf.data.ManualExecutionResult;
063: import org.objectweb.salome_tmf.data.ManualTest;
064: import org.objectweb.salome_tmf.ihm.languages.Language;
065: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
066: import org.objectweb.salome_tmf.ihm.main.plugins.PluginsTools;
067: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
068: import org.objectweb.salome_tmf.ihm.tools.Tools;
069: import org.objectweb.salome_tmf.plugins.UICompCst;
070:
071: /**
072: * Classe représentant la vue sur le détails des actions de tests
073: * @author teaml039
074: * @version : 0.1
075: */
076: public class ActionDetailsView extends JDialog implements
077: DataConstants, ActionListener, ListSelectionListener {
078:
079: /**
080: * Modèle de données de la table des résultats d'action
081: */
082: MyTableModel actionsResultTableModel;
083:
084: /**
085: * Table des résultats d'action
086: */
087: JTable actionsResultTable;
088:
089: /**
090: * Description de l'action
091: */
092: JTextPane descriptionArea;
093:
094: /**
095: * Description du résultat attendu
096: */
097: JTextPane awaitedResultArea;
098:
099: /**
100: * Description du résultat effectif
101: */
102: JTextPane effectiveResultArea;
103:
104: /**
105: * Le panel des attachements
106: */
107: AttachmentView attachmentPanel;
108:
109: /**
110: * La table des anciens attachements
111: */
112: HashMap oldAttachMap;
113:
114: /**
115: * Le résultat de test courant
116: */
117: ExecutionTestResult effectivExecutionTestResult;
118:
119: /**
120: * Nom de l'exécution courante
121: */
122: String effectivExecutionName;
123:
124: /**
125: * Nom du résultat d'exécution courant
126: */
127: String effectivExecutionResultName;
128:
129: ExecutionResult execRes;
130: /******************************************************************************/
131: /** CONSTRUCTEUR ***/
132: /******************************************************************************/
133: JButton quitButton;
134: JButton saveButton;
135:
136: /**
137: * Constructeur de la vue.
138: */
139: public ActionDetailsView(ManualTest observedTest,
140: Execution execution, ExecutionResult executionResult,
141: ExecutionTestResult executionTestResult, JDialog parent) {
142:
143: super (parent, true);
144: initComponent(observedTest, execution, executionResult,
145: executionTestResult);
146: } // Fin du constructeur ActionDeatilsView
147:
148: public ActionDetailsView(ManualTest observedTest,
149: Execution execution, ExecutionResult executionResult,
150: ExecutionTestResult executionTestResult) {
151:
152: super (SalomeTMFContext.getInstance().ptrFrame, true);
153: initComponent(observedTest, execution, executionResult,
154: executionTestResult);
155: } // Fin du constructeur ActionDeatilsView
156:
157: /******************************************************************************/
158: /** METHODES PUBLIQUES ***/
159: /******************************************************************************/
160: void initComponent(ManualTest observedTest, Execution execution,
161: ExecutionResult executionResult,
162: ExecutionTestResult executionTestResult) {
163:
164: int t_x = 1024 - 100;
165: int t_y = 768 / 3 * 2 - 50;
166: try {
167: GraphicsEnvironment ge = GraphicsEnvironment
168: .getLocalGraphicsEnvironment();
169: GraphicsDevice[] gs = ge.getScreenDevices();
170: GraphicsDevice gd = gs[0];
171: GraphicsConfiguration[] gc = gd.getConfigurations();
172: Rectangle r = gc[0].getBounds();
173: t_x = r.width - 100;
174: t_y = r.height / 3 * 2 - 50;
175: } catch (Exception E) {
176:
177: }
178:
179: execRes = executionResult;
180: oldAttachMap = executionTestResult
181: .getCopyOfAttachmentMapFromModel();
182: // Initialisation des éléments de la fenêtre
183: actionsResultTableModel = new MyTableModel();
184: actionsResultTable = new JTable();
185: effectiveResultArea = new JTextPane();
186: awaitedResultArea = new JTextPane();
187: descriptionArea = new JTextPane();
188: JLabel testName = new JLabel(observedTest
189: .getTestListFromModel().getFamilyFromModel()
190: .getNameFromModel()
191: + "/"
192: + observedTest.getTestListFromModel()
193: .getNameFromModel()
194: + "/"
195: + observedTest.getNameFromModel());
196: testName.setFont(new Font(null, Font.BOLD, 18));
197:
198: // Initialisation du modèle de données de la table
199: actionsResultTableModel.addColumnNameAndColumn(Language
200: .getInstance().getText("Nom"));
201: actionsResultTableModel.addColumnNameAndColumn(Language
202: .getInstance().getText("Description"));
203: actionsResultTableModel.addColumnNameAndColumn(Language
204: .getInstance().getText("Résultat_attendu"));
205: actionsResultTableModel.addColumnNameAndColumn(Language
206: .getInstance().getText("Résultat_effectif"));
207: actionsResultTableModel.addColumnNameAndColumn(Language
208: .getInstance().getText("Statut"));
209:
210: actionsResultTable.setModel(actionsResultTableModel);
211:
212: //actionsResultTable.setPreferredScrollableViewportSize(new Dimension(700,150));
213: actionsResultTable
214: .setPreferredScrollableViewportSize(new Dimension(t_x,
215: t_y / 3));
216: actionsResultTable
217: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
218:
219: // Mapping entre objets graphiques et constantes
220: SalomeTMFContext.getInstance().addToUIComponentsMap(
221: UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTIONS_TABLE,
222: actionsResultTable);
223: // Activation des plugins associés
224: PluginsTools
225: .activateAssociatedPlgs(UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTIONS_TABLE);
226:
227: JScrollPane actionsResultTableScrollPane = new JScrollPane(
228: actionsResultTable);
229: actionsResultTableScrollPane.setMaximumSize(new Dimension(t_x,
230: t_y / 3));
231:
232: // Action lorsqu'un élément est sélectionné dans la table
233: ListSelectionModel rowSM = actionsResultTable
234: .getSelectionModel();
235: rowSM.addListSelectionListener(this );
236:
237: if (Api.isLockExecutedTest()) {
238: descriptionArea.setEditable(false);
239: }
240: //descriptionArea.setPreferredSize(new Dimension(100,100));
241:
242: // Mapping entre objets graphiques et constantes
243: SalomeTMFContext.getInstance().addToUIComponentsMap(
244: UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTION_DESC,
245: descriptionArea);
246: // Activation des plugins associés
247: PluginsTools
248: .activateAssociatedPlgs(UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTION_DESC);
249:
250: JScrollPane descriptionScrollPane = new JScrollPane(
251: descriptionArea);
252: descriptionScrollPane.setBorder(BorderFactory
253: .createTitledBorder(BorderFactory
254: .createLineBorder(Color.BLACK), Language
255: .getInstance().getText("Description")));
256: //descriptionScrollPane.setPreferredSize(new Dimension(100,100));
257: descriptionScrollPane.setPreferredSize(new Dimension(t_x,
258: t_y / 3 / 2));
259:
260: if (Api.isLockExecutedTest()) {
261: awaitedResultArea.setEditable(false);
262: }
263: //awaitedResultArea.setPreferredSize(new Dimension(100,100));
264:
265: // Mapping entre objets graphiques et constantes
266: SalomeTMFContext
267: .getInstance()
268: .addToUIComponentsMap(
269: UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTION_WAITED_RES,
270: awaitedResultArea);
271: // Activation des plugins associés
272: PluginsTools
273: .activateAssociatedPlgs(UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTION_WAITED_RES);
274:
275: JScrollPane awaitedResultScrollPane = new JScrollPane(
276: awaitedResultArea);
277: awaitedResultScrollPane.setBorder(BorderFactory
278: .createTitledBorder(BorderFactory
279: .createLineBorder(Color.BLACK), Language
280: .getInstance().getText("Résultat_attendu")));
281: //awaitedResultScrollPane.setPreferredSize(new Dimension(100,100));
282: //awaitedResultScrollPane.setPreferredSize(new Dimension(t_x/2, t_y/3));
283:
284: if (Api.isLockExecutedTest()) {
285: effectiveResultArea.setEditable(false);
286: }
287: //effectiveResultArea.setPreferredSize(new Dimension(100,100));
288:
289: // Mapping entre objets graphiques et constantes
290: SalomeTMFContext.getInstance().addToUIComponentsMap(
291: UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTION_EFF_RES,
292: effectiveResultArea);
293: // Activation des plugins associés
294: PluginsTools
295: .activateAssociatedPlgs(UICompCst.TEST_EXECUTION_RESULT_DETAILS_ACTION_EFF_RES);
296:
297: JScrollPane effectiveResultScrollPane = new JScrollPane(
298: effectiveResultArea);
299: effectiveResultScrollPane.setBorder(BorderFactory
300: .createTitledBorder(BorderFactory
301: .createLineBorder(Color.BLACK), Language
302: .getInstance().getText("Résultat_effectif")));
303: //effectiveResultScrollPane.setPreferredSize(new Dimension(100,100));
304: //effectiveResultScrollPane.setPreferredSize(new Dimension(t_x/2, t_y/3));
305:
306: quitButton = new JButton(Language.getInstance().getText(
307: "Terminer"));
308: quitButton.addActionListener(this );
309:
310: saveButton = new JButton(Language.getInstance().getText(
311: "Modifier"));
312: saveButton.addActionListener(this );
313: if (Api.isLockExecutedTest()) {
314: saveButton.setEnabled(false);
315: }
316: initActionResultsData(observedTest, executionTestResult,
317: execution.getNameFromModel(), executionResult
318: .getNameFromModel());
319:
320: //attachmentPanel = new AttachmentView(DataModel.getApplet(), EXECUTION_RESULT_TEST, EXECUTION_RESULT_TEST, executionTestResult, SMALL_SIZE_FOR_ATTACH, execution, executionResult, observedTest);
321: attachmentPanel = new AttachmentView(DataModel.getApplet(),
322: EXECUTION_RESULT_TEST, EXECUTION_RESULT_TEST,
323: executionTestResult, SMALL_SIZE_FOR_ATTACH, this );
324:
325: attachmentPanel.setBorder(BorderFactory.createTitledBorder(
326: BorderFactory.createLineBorder(Color.BLACK), Language
327: .getInstance().getText("Attachements")));
328:
329: JPanel downPart = new JPanel(new FlowLayout());
330: downPart.setLayout(new BoxLayout(downPart, BoxLayout.X_AXIS));
331: downPart.setPreferredSize(new Dimension(t_x, t_y / 3 / 2));
332: downPart.add(awaitedResultScrollPane);
333: downPart.add(effectiveResultScrollPane);
334:
335: /*JPanel actionsDetailsPanel = new JPanel(new BorderLayout());
336: actionsDetailsPanel.add(descriptionScrollPane, BorderLayout.NORTH);
337: actionsDetailsPanel.add(downPart, BorderLayout.SOUTH);
338: */
339:
340: JPanel actionsDetailsPanel = new JPanel();
341: actionsDetailsPanel.setLayout(new BoxLayout(
342: actionsDetailsPanel, BoxLayout.Y_AXIS));
343: actionsDetailsPanel.setPreferredSize(new Dimension(t_x,
344: t_y / 3 * 2));
345: actionsDetailsPanel.add(descriptionScrollPane);
346: actionsDetailsPanel.add(downPart);
347:
348: JPanel upPart = new JPanel(new BorderLayout());
349: upPart.add(BorderLayout.NORTH, testName);
350:
351: JPanel allView = new JPanel(new BorderLayout());
352:
353: allView.add(upPart, BorderLayout.NORTH);
354: allView.add(actionsResultTableScrollPane, BorderLayout.CENTER);
355: actionsResultTableScrollPane.setPreferredSize(new Dimension(
356: t_x, t_y / 3 / 2));
357: JPanel buttonPanel = new JPanel(new FlowLayout(
358: FlowLayout.CENTER));
359: buttonPanel.add(saveButton);
360: buttonPanel.add(quitButton);
361:
362: /*
363: Container contentPaneFrame = this.getContentPane();
364: Dimension d = buttonPanel.getSize();
365: contentPaneFrame.setLayout(new BoxLayout(contentPaneFrame, BoxLayout.Y_AXIS));
366:
367: allView.setPreferredSize(new Dimension(t_x, t_y/3/2 - d.height));
368: contentPaneFrame.add(allView);
369:
370: actionsDetailsPanel.setPreferredSize(new Dimension(t_x, t_y/3*2 - d.height));
371: contentPaneFrame.add(actionsDetailsPanel);
372:
373: attachmentPanel.setPreferredSize(new Dimension(t_x, t_y/3 - d.height));
374: contentPaneFrame.add(attachmentPanel);
375:
376: contentPaneFrame.add(buttonPanel);
377: */
378:
379: JTabbedPane pJTabbedPane = new JTabbedPane();
380: Container contentPaneFrame = this .getContentPane();
381: Dimension d = buttonPanel.getSize();
382: contentPaneFrame.setLayout(new BoxLayout(contentPaneFrame,
383: BoxLayout.Y_AXIS));
384:
385: JPanel result = new JPanel();
386: result.setLayout(new BoxLayout(result, BoxLayout.Y_AXIS));
387: allView
388: .setPreferredSize(new Dimension(t_x, t_y / 2 - d.height));
389: actionsDetailsPanel.setPreferredSize(new Dimension(t_x, t_y / 2
390: - d.height));
391: result.add(allView);
392: result.add(actionsDetailsPanel);
393:
394: pJTabbedPane
395: .add(Language.getInstance().getText("Test"), result);
396: pJTabbedPane.add(
397: Language.getInstance().getText("Attachements"),
398: attachmentPanel);
399: contentPaneFrame.add(pJTabbedPane);
400: contentPaneFrame.add(buttonPanel);
401:
402: SalomeTMFContext.getInstance().addToUIComponentsMap(
403: UICompCst.MANUAL_TEST_EXECUTION_RESULT_DETAILS_TAB,
404: pJTabbedPane);
405: PluginsTools
406: .activateAssociatedPlgs(UICompCst.MANUAL_TEST_EXECUTION_RESULT_DETAILS_TAB);
407:
408: setSize(t_x, t_y);
409: //this.setLocation(50,50);
410: this .setTitle(Language.getInstance().getText(
411: "Détails_d'exécutions"));
412: /*this.setLocationRelativeTo(this.getParent());
413: this.pack();
414: this.setVisible(true);*/
415: centerScreen();
416: }
417:
418: void centerScreen() {
419: Dimension dim = getToolkit().getScreenSize();
420: this .pack();
421: Rectangle abounds = getBounds();
422: setLocation((dim.width - abounds.width) / 2,
423: (dim.height - abounds.height) / 2);
424:
425: this .setVisible(true);
426: requestFocus();
427: }
428:
429: /**
430: * Méthode d'initialisation de la table des résultats d'actions
431: */
432: public void initActionResultsData(ManualTest test,
433: ExecutionTestResult execTestResult, String executionName,
434: String executionResultName) {
435: // Conservation des anciennes valeurs
436: //oldAttachMap = execTestResult.getCopyOfAttachmentMapFromModel();
437:
438: effectivExecutionTestResult = execTestResult;
439: effectivExecutionName = executionName;
440: effectivExecutionResultName = executionResultName;
441: ArrayList actionsList = test.getActionListFromModel(false);
442: for (int i = 0; i < actionsList.size(); i++) {
443: ArrayList data = new ArrayList();
444: data.add(((Action) actionsList.get(i)).getNameFromModel());
445: data.add(((ManualExecutionResult) execTestResult)
446: .getDescriptionResultFromModel((Action) actionsList
447: .get(i)));
448: data.add(((ManualExecutionResult) execTestResult)
449: .getAwaitedResultFromModel(((Action) actionsList
450: .get(i))));
451: data.add(((ManualExecutionResult) execTestResult)
452: .getEffectivResultFromModel((Action) actionsList
453: .get(i)));
454: data
455: .add(Tools
456: .getActionStatusIcon(((ManualExecutionResult) execTestResult)
457: .getActionStatusInModel((Action) actionsList
458: .get(i))));
459:
460: actionsResultTableModel.addRow(data);
461: }
462: if (actionsResultTableModel.getRowCount() > 0) {
463: actionsResultTable.getSelectionModel()
464: .setSelectionInterval(0, 0);
465: }
466: } // Fin de la méthode initActionResultsData/0
467:
468: /********************** Manage events *************************/
469:
470: public void actionPerformed(ActionEvent e) {
471: if (e.getSource().equals(quitButton)) {
472: quitPerformed();
473: } else if (e.getSource().equals(saveButton)) {
474: updatePerformed();
475: }
476: }
477:
478: public void valueChanged(ListSelectionEvent e) {
479: if (e.getSource()
480: .equals(actionsResultTable.getSelectionModel())) {
481: actionsResultTableValueChanged(e);
482: }
483: }
484:
485: void actionsResultTableValueChanged(ListSelectionEvent e) {
486: if (e.getValueIsAdjusting())
487: return;
488:
489: //Récupération de la l'index de la ligne sélectionnée
490: int selectedRowIndex = actionsResultTable.getSelectedRow();
491: // Mise à jour des différentes descriptions
492: if (selectedRowIndex != -1) {
493: descriptionArea.setText((String) actionsResultTableModel
494: .getValueAt(selectedRowIndex, 1));
495: descriptionArea.getCaret().setDot(0);
496: awaitedResultArea.setText((String) actionsResultTableModel
497: .getValueAt(selectedRowIndex, 2));
498: awaitedResultArea.getCaret().setDot(0);
499: effectiveResultArea
500: .setText((String) actionsResultTableModel
501: .getValueAt(selectedRowIndex, 3));
502: effectiveResultArea.getCaret().setDot(0);
503: } else {
504: descriptionArea.setText("");
505: awaitedResultArea.setText("");
506: effectiveResultArea.setText("");
507: }
508: }
509:
510: void quitPerformed() {
511: if (Api.isConnected()) {
512: int transNumber = -1;
513: try {
514: transNumber = Api.beginTransaction(100,
515: ApiConstants.INSERT_ATTACHMENT);
516:
517: effectivExecutionTestResult
518: .updateAttachement(oldAttachMap);
519:
520: Api.commitTrans(transNumber);
521:
522: } catch (Exception exception) {
523: Api.forceRollBackTrans(transNumber);
524: Tools.ihmExceptionView(exception);
525: }
526: }
527:
528: //effectivExecutionTestResult.setAttachmentMapInModel(oldAttachMap);
529: ActionDetailsView.this .dispose();
530: }
531:
532: /* Update of current action test result*/
533: void updatePerformed() {
534: ManualExecutionResult pManualExecutionResult;
535: Action pAction;
536: ArrayList actionsList;
537: int selectedRowIndex;
538:
539: try {
540: pManualExecutionResult = (ManualExecutionResult) effectivExecutionTestResult;
541: selectedRowIndex = actionsResultTable.getSelectedRow();
542: actionsList = ((ManualTest) effectivExecutionTestResult
543: .getTestFromModel()).getActionListFromModel(false);
544: pAction = (Action) actionsList.get(selectedRowIndex);
545: } catch (Exception exception) {
546: Tools.ihmExceptionView(exception);
547: return;
548: }
549:
550: if (Api.isConnected()) {
551: int transNumber = -1;
552: try {
553:
554: pManualExecutionResult.addEffectivResultInModel(
555: pAction, effectiveResultArea.getText());
556: pManualExecutionResult.addDescriptionResultInModel(
557: pAction, descriptionArea.getText());
558: pManualExecutionResult.addAwaitedResultInModel(pAction,
559: awaitedResultArea.getText());
560:
561: pManualExecutionResult.updateActionResInDB(pAction);
562:
563: Api.commitTrans(transNumber);
564:
565: actionsResultTableModel.setValueAt(descriptionArea
566: .getText(), selectedRowIndex, 1);
567: actionsResultTableModel.setValueAt(awaitedResultArea
568: .getText(), selectedRowIndex, 2);
569: actionsResultTableModel.setValueAt(effectiveResultArea
570: .getText(), selectedRowIndex, 3);
571:
572: } catch (Exception exception) {
573: Api.forceRollBackTrans(transNumber);
574: //replace model in original forme
575: pManualExecutionResult.addDescriptionResultInModel(
576: pAction, (String) actionsResultTableModel
577: .getValueAt(selectedRowIndex, 1));
578: pManualExecutionResult.addAwaitedResultInModel(pAction,
579: (String) actionsResultTableModel.getValueAt(
580: selectedRowIndex, 2));
581: pManualExecutionResult.addEffectivResultInModel(
582: pAction, (String) actionsResultTableModel
583: .getValueAt(selectedRowIndex, 3));
584:
585: Tools.ihmExceptionView(exception);
586: }
587: }
588: }
589: } // Fin de la classe ActionDetailsView
|