0001: /*
0002: * SalomeTMF is a Test Management Framework
0003: * Copyright (C) 2005 France Telecom R&D
0004: *
0005: * This library is free software; you can redistribute it and/or
0006: * modify it under the terms of the GNU Lesser General Public
0007: * License as published by the Free Software Foundation; either
0008: * version 2 of the License, or (at your option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful,
0011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0013: * Lesser General Public License for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public
0016: * License along with this library; if not, write to the Free Software
0017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
0020: *
0021: * Contact: mikael.marche@rd.francetelecom.com
0022: */
0023:
0024: package org.objectweb.salome_tmf.ihm;
0025:
0026: import java.awt.BorderLayout;
0027: import java.awt.Dimension;
0028: import java.awt.GridLayout;
0029: import java.awt.Toolkit;
0030: import java.awt.datatransfer.DataFlavor;
0031: import java.awt.datatransfer.Transferable;
0032: import java.awt.datatransfer.UnsupportedFlavorException;
0033: import java.awt.event.ActionEvent;
0034: import java.awt.event.ActionListener;
0035: import java.io.IOException;
0036: import java.util.ArrayList;
0037: import java.util.Collection;
0038: import java.util.HashMap;
0039: import java.util.HashSet;
0040: import java.util.Iterator;
0041: import java.util.Set;
0042: import java.util.Vector;
0043:
0044: import javax.swing.BorderFactory;
0045: import javax.swing.JButton;
0046: import javax.swing.JOptionPane;
0047: import javax.swing.JPanel;
0048: import javax.swing.JScrollPane;
0049: import javax.swing.JTable;
0050: import javax.swing.ListSelectionModel;
0051: import javax.swing.event.ListSelectionEvent;
0052: import javax.swing.event.ListSelectionListener;
0053:
0054: import org.objectweb.salome_tmf.api.Api;
0055: import org.objectweb.salome_tmf.api.api2ihm.AdminProject;
0056: import org.objectweb.salome_tmf.data.Action;
0057: import org.objectweb.salome_tmf.data.Attachment;
0058: import org.objectweb.salome_tmf.data.CampaignData;
0059: import org.objectweb.salome_tmf.data.FileAttachment;
0060: import org.objectweb.salome_tmf.data.ManualTest;
0061: import org.objectweb.salome_tmf.data.Parameter;
0062: import org.objectweb.salome_tmf.data.ProjectData;
0063: import org.objectweb.salome_tmf.data.Test;
0064: import org.objectweb.salome_tmf.data.UrlAttachment;
0065: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
0066: import org.objectweb.salome_tmf.ihm.languages.Language;
0067: import org.objectweb.salome_tmf.ihm.models.RowTransferHandler;
0068: import org.objectweb.salome_tmf.ihm.models.RowTransferable;
0069: import org.objectweb.salome_tmf.ihm.tools.Tools;
0070:
0071: /*
0072: * ManualActionView.java
0073: * Created on Aug 2, 2004
0074: * Last modification : Aug 2, 2004
0075: * author : teaml039
0076: */
0077:
0078: /**
0079: * @author teaml039
0080: * @version : 0.1
0081: */
0082: public class ManualActionView extends JPanel implements ActionListener,
0083: ListSelectionListener {
0084:
0085: JPanel actionsPanel;
0086:
0087: /**
0088: * Bouton pour la suppression des actions pour les tests manuels
0089: */
0090: static JButton deleteManualTestAction;
0091:
0092: /**
0093: * Table des actions des tests manuels
0094: */
0095: JTable actionTable;
0096:
0097: static JButton modifyAction;
0098: static JButton addAction;
0099: RowTransferHandler transferHandler;
0100:
0101: static JButton paste;
0102: static JButton cut;
0103: static JButton copy;
0104: static JButton orderAction;
0105:
0106: public ManualActionView() {
0107: actionsPanel = new JPanel();
0108:
0109: deleteManualTestAction = new JButton(Language.getInstance()
0110: .getText("Supprimer"));
0111: actionTable = new JTable();
0112: modifyAction = new JButton(Language.getInstance().getText(
0113: "Modifier"));
0114: copy = new JButton(Language.getInstance().getText("Copier"));
0115: paste = new JButton(Language.getInstance().getText("Coller"));
0116: cut = new JButton(Language.getInstance().getText("Couper"));
0117:
0118: addAction = new JButton(Language.getInstance().getText(
0119: "Ajouter"));
0120: addAction.setToolTipText(Language.getInstance().getText(
0121: "Ajouter_une_action"));
0122: addAction.addActionListener(this );
0123:
0124: modifyAction.setToolTipText(Language.getInstance().getText(
0125: "Modifier_une_action"));
0126: modifyAction.setEnabled(false);
0127: modifyAction.addActionListener(this );
0128:
0129: orderAction = new JButton(Language.getInstance().getText(
0130: "Ordonner"));
0131: orderAction.setToolTipText(Language.getInstance().getText(
0132: "Ordonner_les_actions"));
0133: orderAction.addActionListener(this );
0134:
0135: deleteManualTestAction.setEnabled(false);
0136: deleteManualTestAction.setToolTipText(Language.getInstance()
0137: .getText("Supprimer_une_action"));
0138: deleteManualTestAction.addActionListener(this );
0139:
0140: copy.setToolTipText(Language.getInstance().getText("Copier"));
0141: copy.setEnabled(false);
0142: copy.addActionListener(this );
0143:
0144: cut.setToolTipText(Language.getInstance().getText("Couper"));
0145: cut.setEnabled(false);
0146: cut.addActionListener(this );
0147:
0148: paste.setToolTipText(Language.getInstance().getText("Coller"));
0149: paste.setEnabled(false);
0150: paste.addActionListener(this );
0151:
0152: JPanel buttonsPanel = new JPanel(new GridLayout(1, 7));
0153: buttonsPanel.add(addAction);
0154: buttonsPanel.add(modifyAction);
0155: buttonsPanel.add(orderAction);
0156: buttonsPanel.add(deleteManualTestAction);
0157: buttonsPanel.add(copy);
0158: buttonsPanel.add(cut);
0159: buttonsPanel.add(paste);
0160: buttonsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
0161:
0162: transferHandler = new RowTransferHandler();
0163: actionTable.setModel(DataModel.getActionTableModel());
0164:
0165: //TableSorter sorter = new TableSorter(actionTable.getModel() , actionTable.getTableHeader());
0166: //actionTable.setModel(sorter);
0167:
0168: actionTable.setPreferredScrollableViewportSize(new Dimension(
0169: 600, 200));
0170: actionTable.setTransferHandler(transferHandler);
0171: actionTable
0172: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0173: JScrollPane tablePane = new JScrollPane(actionTable);
0174:
0175: ListSelectionModel rowSM = actionTable.getSelectionModel();
0176: rowSM.addListSelectionListener(this );
0177:
0178: actionsPanel.setLayout(new BorderLayout());
0179: actionsPanel.add(buttonsPanel, BorderLayout.NORTH);
0180: actionsPanel.add(tablePane, BorderLayout.CENTER);
0181:
0182: this .setLayout(new BorderLayout());
0183: this .add(actionsPanel);
0184:
0185: // Mapping GUI Object for plugins//
0186: // actionsPanel
0187: SalomeTMF.addToUIComponentsMap(
0188: UICompCst.MANUAL_TEST_ACTIONS_PANEL, actionsPanel);
0189: UICompCst.staticUIComps
0190: .add(UICompCst.MANUAL_TEST_ACTIONS_PANEL);
0191:
0192: // actionTable
0193: SalomeTMF.addToUIComponentsMap(
0194: UICompCst.MANUAL_TEST_ACTIONS_TABLE, actionTable);
0195: UICompCst.staticUIComps
0196: .add(UICompCst.MANUAL_TEST_ACTIONS_TABLE);
0197:
0198: //buttonsPanel
0199: SalomeTMF.addToUIComponentsMap(
0200: UICompCst.MANUAL_TEST_ACTIONS_BUTTONS_PANEL,
0201: buttonsPanel);
0202: UICompCst.staticUIComps
0203: .add(UICompCst.MANUAL_TEST_ACTIONS_BUTTONS_PANEL);
0204:
0205: } // Fin du constructeur ManualActionView/0
0206:
0207: /**
0208: *
0209: *
0210: */
0211: public static void giveAccessToIhmManualActionView() {
0212: if (!AdminProject.canDeleteTest()) {
0213: deleteManualTestAction.setEnabled(false);
0214: cut.setEnabled(false);
0215: }
0216: if (!AdminProject.canCreateTest()) {
0217: addAction.setEnabled(false);
0218: copy.setEnabled(false);
0219: paste.setEnabled(false);
0220: }
0221: if (!AdminProject.canUpdateTest()) {
0222: modifyAction.setEnabled(false);
0223: orderAction.setEnabled(false);
0224:
0225: }
0226: }
0227:
0228: /**
0229: * Mise a jour des numéro d'ordre des tests d'une campagne
0230: * @param campaign une campagne
0231: */
0232: private static void updateIhmActionOrder(ManualTest test) {
0233: for (int i = 0; i < test.getActionList().size(); i++) {
0234: Action action = (Action) test.getActionList().get(i);
0235: action.setOrderIndex(i);
0236: }
0237:
0238: } // Fin de la m?thode updateTestOrderInCampaignTree/1
0239:
0240: /********************** Manage events *************************/
0241:
0242: public void actionPerformed(ActionEvent e) {
0243: if (e.getSource().equals(addAction)) {
0244: addActionPerformed();
0245: } else if (e.getSource().equals(modifyAction)) {
0246: modifyActionPerformed();
0247: } else if (e.getSource().equals(orderAction)) {
0248: orderActionPerformed();
0249: } else if (e.getSource().equals(deleteManualTestAction)) {
0250: deleteManualTestActionPerformed();
0251: } else if (e.getSource().equals(copy)) {
0252: copyPerformed();
0253: } else if (e.getSource().equals(cut)) {
0254: cutPerformed();
0255: } else if (e.getSource().equals(paste)) {
0256: pastePerformed();
0257: }
0258: }
0259:
0260: public void addActionPerformed() {
0261: String message = CampaignData
0262: .getCampaignWithExecResultWhereTestIsUse(DataModel
0263: .getCurrentTest());
0264: if (!message.equals("")) {
0265: JOptionPane
0266: .showMessageDialog(
0267: ManualActionView.this ,
0268: Language
0269: .getInstance()
0270: .getText(
0271: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0272: + message
0273: + Language
0274: .getInstance()
0275: .getText(
0276: "qui_possèdent_des_résultats_d'exéutions.\nAfin_de_conserver_l'intégrité_des_résultats,_vous_ne_pouvez_pas_ajouter_une_nouvelle_action."),
0277: Language.getInstance().getText("Erreur_!"),
0278: JOptionPane.ERROR_MESSAGE);
0279: } else {
0280: AskNewAction addAction = new AskNewAction(
0281: ManualActionView.this , Language.getInstance()
0282: .getText("Ajout_d'une_action"));
0283: Action action = addAction.getAction();
0284: if (action != null) {
0285: if (!((ManualTest) DataModel.getCurrentTest())
0286: .hasActionName(action.getName())) {
0287: int transNumber = -1;
0288: try {
0289: transNumber = Api
0290: .beginTransaction(Api.INSERT_ACTION);
0291: //action.setOrderIndex(DataModel.getActionTableModel()
0292: // .getRowCount());
0293: if (action.addInBddAndModel(DataModel
0294: .getCurrentTest(), DataModel
0295: .getActionTableModel().getRowCount())) {
0296: Tools.RefreshView(action.getName(),
0297: Language.getInstance().getText(
0298: "Action"));
0299: }
0300:
0301: Set keySet = action.getAttachmentMap().keySet();
0302: for (Iterator iter = keySet.iterator(); iter
0303: .hasNext();) {
0304: Attachment attach = (Attachment) action
0305: .getAttachmentMap()
0306: .get(iter.next());
0307: if (attach instanceof FileAttachment) {
0308: action
0309: .addAttachFile2DB((FileAttachment) attach);
0310: } else {
0311: action
0312: .addAttachUrl2DB((UrlAttachment) attach);
0313: }
0314: }
0315: for (Iterator iterator = action
0316: .getParameterHashSet().iterator(); iterator
0317: .hasNext();) {
0318: Parameter param = (Parameter) iterator
0319: .next();
0320: action.setUseParamInBddAndModel(param);
0321: }
0322: Api.commitTrans(transNumber);
0323:
0324: ArrayList dataList = new ArrayList();
0325: dataList.add(action.getName());
0326: dataList.add(action.getDescription());
0327: dataList.add(action.getAwaitedResult());
0328: dataList
0329: .add(action.getAttachmentMap().keySet());
0330: DataModel.getActionTableModel()
0331: .addRow(dataList);
0332: //action.setOrderIndex(DataModel.getActionTableModel().getRowCount()-1);
0333: //((ManualTest) DataModel.getCurrentTest())
0334: // .addAction(action);
0335:
0336: } catch (Exception exception) {
0337: ((ManualTest) DataModel.getCurrentTest())
0338: .deleteAction(action.getName());
0339:
0340: Api.forceRollBackTrans(transNumber);
0341: Tools.ihmExceptionView(exception.toString());
0342: }
0343:
0344: } else {
0345: JOptionPane
0346: .showMessageDialog(
0347: ManualActionView.this ,
0348: Language
0349: .getInstance()
0350: .getText(
0351: "Ce_nom_d'action_existe_déjà_pour_ce_test_!"),
0352: Language.getInstance().getText(
0353: "Erreur_!"),
0354: JOptionPane.ERROR_MESSAGE);
0355: }
0356: }
0357: }
0358:
0359: }
0360:
0361: public void modifyActionPerformed() {
0362: int selectedRowIndex = actionTable.getSelectedRow();
0363: if (selectedRowIndex != -1) {
0364: String message = CampaignData
0365: .getCampaignWithExecResultWhereTestIsUse(DataModel
0366: .getCurrentTest());
0367: if (!message.equals("")) {
0368: JOptionPane
0369: .showMessageDialog(
0370: ManualActionView.this ,
0371: Language
0372: .getInstance()
0373: .getText(
0374: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0375: + message
0376: + Language
0377: .getInstance()
0378: .getText(
0379: "qui_possèdent_des_résultats_d'exécutions.\nAfin_de_conserver_l'intégrité_des_résultats,_vous_ne_pouvez_modifier_que_les_attachements_liés_cette_action."),
0380: Language.getInstance().getText(
0381: "Avertissement_!"),
0382: JOptionPane.WARNING_MESSAGE);
0383: Action oldAction = ((ManualTest) DataModel
0384: .getCurrentTest()).getAction((String) DataModel
0385: .getActionTableModel().getValueAt(
0386: selectedRowIndex, 0));
0387: //String oldActionName = oldAction.getName();
0388: //String oldDescription = oldAction.getDescription();
0389: //String oldAwaitedResult = oldAction.getAwaitedResult();
0390:
0391: HashMap oldAttachMap = new HashMap();
0392: Set keysSet = oldAction.getAttachmentMap().keySet();
0393: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
0394: Object elem = iter.next();
0395: oldAttachMap.put(elem, oldAction.getAttachmentMap()
0396: .get(elem));
0397: }
0398: //HashSet oldParamSet = (HashSet)oldAction.getParameterHashSet().clone();
0399:
0400: AskNewAction addAction = new AskNewAction(
0401: ManualActionView.this , Language.getInstance()
0402: .getText("Modifier_une_action"),
0403: oldAction);
0404:
0405: if (addAction.getAction() != null) {
0406: int transNumber = -1;
0407: try {
0408: // BdD
0409: transNumber = Api
0410: .beginTransaction(Api.UPDATE_ACTION);
0411: //ConnectionData.getSuiteTestUpdate().updateAction(DataModel.getCurrentTest().getTestList().getFamily().getName(), DataModel.getCurrentTest().getTestList().getName(), DataModel.getCurrentTest().getName(), oldActionName, addAction.getAction().getName(), addAction.getAction().getDescription(), addAction.getAction().getAwaitedResult(), addAction.getAction().getOrderIndex());
0412: addAction.getAction().updateInBddAndModel(
0413: addAction.getAction().getName(),
0414: addAction.getAction().getDescription(),
0415: addAction.getAction()
0416: .getAwaitedResult(),
0417: addAction.getAction().getOrderIndex());
0418:
0419: // Liste des anciens fichiers attach?s
0420: Vector oldFileAttachNamesVector = addAction
0421: .getAction().getAttachFilesFromDB();
0422: // Liste des anciennes urls attach?es
0423: Vector oldUrlAttachVector = addAction
0424: .getAction().getAttachUrlsFromDB();
0425: Collection attachValues = addAction.getAction()
0426: .getAttachmentMap().values();
0427: for (Iterator iter = attachValues.iterator(); iter
0428: .hasNext();) {
0429: Attachment attach = (Attachment) iter
0430: .next();
0431: if (attach instanceof FileAttachment) {
0432: if (!oldFileAttachNamesVector
0433: .contains(attach.getName())) {
0434: addAction
0435: .getAction()
0436: .addAttachFile2DB(
0437: (FileAttachment) attach);
0438: }
0439: } else {
0440: if (!oldUrlAttachVector.contains(attach
0441: .getName())) {
0442: addAction
0443: .getAction()
0444: .addAttachUrl2DB(
0445: (UrlAttachment) attach);
0446: }
0447: }
0448: oldAttachMap.remove(attach.getName());
0449: }
0450: attachValues = oldAttachMap.values();
0451: for (Iterator iter = attachValues.iterator(); iter
0452: .hasNext();) {
0453: Attachment attach = (Attachment) iter
0454: .next();
0455:
0456: if ((oldFileAttachNamesVector
0457: .contains(attach.getName()))
0458: || (oldUrlAttachVector
0459: .contains(attach.getName()))) {
0460: addAction.getAction()
0461: .deleteAttachToBddAndModel(
0462: attach);
0463: //addAction.getAction().deleteAttachFromDB(attach.getIdBdd());
0464: }
0465: }
0466: Api.commitTrans(transNumber);
0467:
0468: // IHM
0469: ArrayList dataList = new ArrayList();
0470: dataList.add(addAction.getAction().getName());
0471: dataList.add(addAction.getAction()
0472: .getDescription());
0473: dataList.add(addAction.getAction()
0474: .getAwaitedResult());
0475: //HashMap newMap = addAction.getAction().getAttachmentMap();
0476: dataList.add(addAction.getAction()
0477: .getAttachmentMap().keySet());
0478: DataModel.getActionTableModel().modifyData(
0479: dataList, selectedRowIndex);
0480:
0481: } catch (Exception exception) {
0482: Api.forceRollBackTrans(transNumber);
0483: addAction.getAction().setAttachmentMap(
0484: oldAttachMap);
0485: Tools.ihmExceptionView(exception.toString());
0486: }
0487:
0488: }
0489: } else {
0490:
0491: if (DataModel.getCurrentTest() instanceof ManualTest) {
0492:
0493: Action oldAction = ((ManualTest) DataModel
0494: .getCurrentTest())
0495: .getAction((String) DataModel
0496: .getActionTableModel().getValueAt(
0497: selectedRowIndex, 0));
0498: String oldActionName = oldAction.getName();
0499: String oldDescription = oldAction.getDescription();
0500: String oldAwaitedResult = oldAction
0501: .getAwaitedResult();
0502:
0503: HashMap oldAttachMap = new HashMap();
0504: Set keysSet = oldAction.getAttachmentMap().keySet();
0505: for (Iterator iter = keysSet.iterator(); iter
0506: .hasNext();) {
0507: Object elem = iter.next();
0508: oldAttachMap.put(elem, oldAction
0509: .getAttachmentMap().get(elem));
0510: }
0511: HashSet oldParamSet = (HashSet) oldAction
0512: .getParameterHashSet().clone();
0513:
0514: AskNewAction addAction = new AskNewAction(
0515: ManualActionView.this , Language
0516: .getInstance().getText(
0517: "Modifier_une_action"),
0518: oldAction);
0519: if (addAction.getAction() != null) {
0520:
0521: try {
0522: // BdD
0523: int transNumber = Api
0524: .beginTransaction(Api.UPDATE_ACTION);
0525: addAction.getAction().updateInBddAndModel(
0526: addAction.getAction().getName(),
0527: addAction.getAction()
0528: .getDescription(),
0529: addAction.getAction()
0530: .getAwaitedResult(),
0531: addAction.getAction()
0532: .getOrderIndex());
0533: // Liste des anciens fichiers attach?s
0534: Vector oldFileAttachNamesVector = addAction
0535: .getAction().getAttachFilesFromDB();
0536: // Liste des anciennes urls attach?es
0537: Vector oldUrlAttachVector = addAction
0538: .getAction().getAttachUrlsFromDB();
0539: Collection attachValues = addAction
0540: .getAction().getAttachmentMap()
0541: .values();
0542: for (Iterator iter = attachValues
0543: .iterator(); iter.hasNext();) {
0544: Attachment attach = (Attachment) iter
0545: .next();
0546: if (attach instanceof FileAttachment) {
0547: if (!oldFileAttachNamesVector
0548: .contains(attach.getName())) {
0549: addAction
0550: .getAction()
0551: .addAttachFile2DB(
0552: (FileAttachment) attach);
0553: }
0554: } else {
0555: if (!oldUrlAttachVector
0556: .contains(attach.getName())) {
0557: addAction
0558: .getAction()
0559: .addAttachUrl2DB(
0560: (UrlAttachment) attach);
0561: }
0562: }
0563: oldAttachMap.remove(attach.getName());
0564: }
0565: attachValues = oldAttachMap.values();
0566: for (Iterator iter = attachValues
0567: .iterator(); iter.hasNext();) {
0568: Attachment attach = (Attachment) iter
0569: .next();
0570: if ((oldFileAttachNamesVector
0571: .contains(attach.getName()))
0572: || (oldUrlAttachVector
0573: .contains(attach
0574: .getName()))) {
0575: addAction.getAction()
0576: .deleteAttachToBddAndModel(
0577: attach);
0578: //addAction.getAction().deleteAttachFromDB(attach.getIdBdd());
0579: }
0580: }
0581: // Les Param?tres
0582: Vector oldParamVector = addAction
0583: .getAction().getParamsNamesFromDB();
0584: HashSet paramsSet = addAction.getAction()
0585: .getParameterHashSet();
0586: for (Iterator iter = paramsSet.iterator(); iter
0587: .hasNext();) {
0588: Parameter param = (Parameter) iter
0589: .next();
0590: if (!oldParamVector.contains(param
0591: .getName())) {
0592: //addAction.getAction().setUseParamInDB(param.getIdBdd());
0593: addAction.getAction()
0594: .setUseParamInBddAndModel(
0595: param);
0596: }
0597: oldParamSet.remove(param);
0598: }
0599: for (Iterator iter = oldParamSet.iterator(); iter
0600: .hasNext();) {
0601: Parameter param = (Parameter) iter
0602: .next();
0603: if (oldParamVector.contains(param
0604: .getName())) {
0605: //addAction.getAction().deleteUseParamFromDB(param.getIdBdd());
0606: addAction
0607: .getAction()
0608: .deleteUseParamToBddAndModel(
0609: param);
0610: }
0611: }
0612: Api.commitTrans(transNumber);
0613:
0614: // IHM
0615: ArrayList dataList = new ArrayList();
0616: dataList.add(addAction.getAction()
0617: .getName());
0618: dataList.add(addAction.getAction()
0619: .getDescription());
0620: dataList.add(addAction.getAction()
0621: .getAwaitedResult());
0622: //HashMap newMap = addAction.getAction().getAttachmentMap();
0623: dataList.add(addAction.getAction()
0624: .getAttachmentMap().keySet());
0625: DataModel.getActionTableModel().modifyData(
0626: dataList, selectedRowIndex);
0627:
0628: } catch (Exception exception) {
0629: addAction.getAction()
0630: .setName(oldActionName);
0631: addAction.getAction().setDescription(
0632: oldDescription);
0633: addAction.getAction().setAwaitedResult(
0634: oldAwaitedResult);
0635: addAction.getAction().setAttachmentMap(
0636: oldAttachMap);
0637: addAction.getAction().setParameterHashSet(
0638: oldParamSet);
0639: Tools
0640: .ihmExceptionView(exception
0641: .toString());
0642: }
0643: }
0644:
0645: }
0646: }
0647: }
0648: }
0649:
0650: public void orderActionPerformed() {
0651: String message = CampaignData
0652: .getCampaignWithExecResultWhereTestIsUse(DataModel
0653: .getCurrentTest());
0654: if (!message.equals("")) {
0655: JOptionPane
0656: .showMessageDialog(
0657: ManualActionView.this ,
0658: Language
0659: .getInstance()
0660: .getText(
0661: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0662: + message
0663: + Language
0664: .getInstance()
0665: .getText(
0666: "qui_possèdent_des_résultats_d'exécutions.\nAfin_de_conserver_l'intégrité_des_résultats,_vous_ne_pouvez_pas_réordonner_les_actions."),
0667: Language.getInstance().getText("Erreur_!"),
0668: JOptionPane.ERROR_MESSAGE);
0669: } else {
0670: if (DataModel.getCurrentTest() instanceof ManualTest) {
0671: new ActionOrdering(((ManualTest) DataModel
0672: .getCurrentTest()).getActionList());
0673: }
0674: }
0675: }
0676:
0677: public void deleteManualTestActionPerformed() {
0678: String message = CampaignData
0679: .getCampaignWithExecResultWhereTestIsUse(DataModel
0680: .getCurrentTest());
0681: if (!message.equals("")) {
0682: JOptionPane
0683: .showMessageDialog(
0684: ManualActionView.this ,
0685: Language
0686: .getInstance()
0687: .getText(
0688: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0689: + message
0690: + Language
0691: .getInstance()
0692: .getText(
0693: "qui_possèdent_des_résultats_d'exécutions.\nAfin_de_conserver_l'intégrité_des_résultats,_vous_ne_pouvez_pas_supprimer_cette_action."),
0694: Language.getInstance().getText("Erreur_!"),
0695: JOptionPane.ERROR_MESSAGE);
0696: } else {
0697:
0698: Object[] options = { Language.getInstance().getText("Oui"),
0699: Language.getInstance().getText("Non") };
0700: int choice = -1;
0701: int[] selectedRows = actionTable.getSelectedRows();
0702: String actionList = "";
0703: for (int i = selectedRows.length - 1; i >= 0; i--) {
0704: actionList = actionList
0705: + "* "
0706: + (String) DataModel.getActionTableModel()
0707: .getValueAt(selectedRows[i], 0);
0708: if (i == 0) {
0709: actionList = actionList + " ?";
0710: } else {
0711: actionList = actionList + " \n";
0712: }
0713: }
0714: choice = JOptionPane
0715: .showOptionDialog(
0716: ManualActionView.this ,
0717: Language
0718: .getInstance()
0719: .getText(
0720: "Etes_vous_sûr_de_vouloir_supprimer_les_actions_:_\n")
0721: + actionList, Language
0722: .getInstance().getText(
0723: "Attention_!"),
0724: JOptionPane.YES_NO_OPTION,
0725: JOptionPane.QUESTION_MESSAGE, null,
0726: options, options[1]);
0727: if (choice == JOptionPane.YES_OPTION) {
0728: for (int i = selectedRows.length - 1; i >= 0; i--) {
0729:
0730: try {
0731: // BdD
0732: Action action = ((ManualTest) DataModel
0733: .getCurrentTest())
0734: .getAction((String) DataModel
0735: .getActionTableModel()
0736: .getValueAt(selectedRows[i], 0));
0737: //action.deleteFromDB(true);
0738: action.deleteFromBddAndModel(true);
0739: // IHM
0740: //((ManualTest)DataModel.getCurrentTest()).deleteAction((String)DataModel.getActionTableModel().getValueAt(selectedRows[i],0));
0741: if (DataModel.getActionTableModel()
0742: .getRowCount() == 0) {
0743: deleteManualTestAction.setEnabled(false);
0744: }
0745: DataModel.getActionTableModel().removeData(
0746: selectedRows[i]);
0747: updateIhmActionOrder((ManualTest) DataModel
0748: .getCurrentTest());
0749:
0750: } catch (Exception exception) {
0751: Tools.ihmExceptionView(exception.toString());
0752: }
0753: }
0754: }
0755: }
0756: }
0757:
0758: public void copyPerformed() {
0759: int[] selectedRows = actionTable.getSelectedRows();
0760: ArrayList data = new ArrayList();
0761: for (int i = 0; i < selectedRows.length; i++) {
0762: data.add(((ManualTest) DataModel.getCurrentTest())
0763: .getActionList().get(selectedRows[i]));
0764: }
0765: try {
0766: RowTransferable rowTransferable = new RowTransferable(data);
0767: Toolkit.getDefaultToolkit().getSystemClipboard()
0768: .setContents(rowTransferable, null);
0769: } catch (IllegalStateException ise) {
0770: JOptionPane
0771: .showMessageDialog(
0772: ManualActionView.this ,
0773: Language
0774: .getInstance()
0775: .getText(
0776: "Le_presse-papier_est_déjà_utilisé_par_une_autre_application_!"),
0777: Language.getInstance().getText("Erreur_!"),
0778: JOptionPane.ERROR_MESSAGE);
0779: }
0780: paste.setEnabled(true);
0781: }
0782:
0783: public void cutPerformed() {
0784: String message = CampaignData
0785: .getCampaignWithExecResultWhereTestIsUse(DataModel
0786: .getCurrentTest());
0787: boolean error = false;
0788: if (!message.equals("")) {
0789: JOptionPane
0790: .showMessageDialog(
0791: ManualActionView.this ,
0792: Language
0793: .getInstance()
0794: .getText(
0795: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0796: + message
0797: + Language
0798: .getInstance()
0799: .getText(
0800: "qui_possèdent_des_résultats_d'exécutions.\nAfin_de_conserver_l'intégrité_des_résultats,_vous_ne_pouvez_pas_supprimer_cette_action."),
0801: Language.getInstance().getText("Erreur_!"),
0802: JOptionPane.ERROR_MESSAGE);
0803: } else {
0804: int[] selectedRows = actionTable.getSelectedRows();
0805: ArrayList data = new ArrayList();
0806: for (int i = 0; i < selectedRows.length; i++) {
0807: data.add(((ManualTest) DataModel.getCurrentTest())
0808: .getActionList().get(selectedRows[i]));
0809: }
0810: try {
0811: RowTransferable rowTransferable = new RowTransferable(
0812: data);
0813: Toolkit.getDefaultToolkit().getSystemClipboard()
0814: .setContents(rowTransferable, null);
0815:
0816: } catch (IllegalStateException ise) {
0817: JOptionPane
0818: .showMessageDialog(
0819: ManualActionView.this ,
0820: Language
0821: .getInstance()
0822: .getText(
0823: "Le_presse-papier_est_déjà_utilisé_par_une_autre_apllication_!"),
0824: Language.getInstance().getText(
0825: "Erreur_!"),
0826: JOptionPane.ERROR_MESSAGE);
0827: error = true;
0828: }
0829: if (!error) {
0830: for (int i = selectedRows.length - 1; i >= 0; i--) {
0831:
0832: try {
0833: //BdD
0834: Action action = ((ManualTest) DataModel
0835: .getCurrentTest())
0836: .getAction((String) DataModel
0837: .getActionTableModel()
0838: .getValueAt(selectedRows[i], 0));
0839: //action.deleteFromDB(true);
0840: action.deleteFromBddAndModel(true);
0841: // IHM
0842: //((ManualTest)DataModel.getCurrentTest()).deleteAction((String)DataModel.getActionTableModel().getValueAt(selectedRows[i],0));
0843: DataModel.getActionTableModel().removeData(
0844: selectedRows[i]);
0845: } catch (Exception exception) {
0846: Tools.ihmExceptionView(exception.toString());
0847: }
0848: }
0849: updateIhmActionOrder((ManualTest) DataModel
0850: .getCurrentTest());
0851: paste.setEnabled(true);
0852: }
0853: }
0854: }
0855:
0856: public void pastePerformed() {
0857: String message = CampaignData
0858: .getCampaignWithExecResultWhereTestIsUse(DataModel
0859: .getCurrentTest());
0860: if (!message.equals("")) {
0861: JOptionPane
0862: .showMessageDialog(
0863: ManualActionView.this ,
0864: Language
0865: .getInstance()
0866: .getText(
0867: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0868: + message
0869: + Language
0870: .getInstance()
0871: .getText(
0872: "qui_possèdent_des_résultats_d'exécutions.\nAfin_de_conserver_l'intégrité_des_résultats,_vous_ne_pouvez_pas_ajouter_une_nouvelle_action."),
0873: Language.getInstance().getText("Erreur_!"),
0874: JOptionPane.ERROR_MESSAGE);
0875: } else {
0876:
0877: Transferable t = Toolkit.getDefaultToolkit()
0878: .getSystemClipboard().getContents(null);
0879: try {
0880: DataFlavor dataFlavor = new DataFlavor(ArrayList.class,
0881: "ArrayList");
0882: /** V?rification que le contenu est de type texte. */
0883: if (t != null && t.isDataFlavorSupported(dataFlavor)) {
0884: ArrayList actionsList = (ArrayList) t
0885: .getTransferData(dataFlavor);
0886: Test pTest = DataModel.getCurrentTest();
0887: for (int i = 0; i < actionsList.size(); i++) {
0888: int transNumber = -1;
0889: try {
0890: //Init
0891: ArrayList data = new ArrayList();
0892: Action pActionToCopy = (Action) actionsList
0893: .get(i);
0894: Action pNewAction = new Action(
0895: pActionToCopy, pTest);
0896:
0897: if (((ManualTest) pTest)
0898: .hasActionName(pNewAction.getName())) {
0899: String newName = Language.getInstance()
0900: .getText("Copie_de_")
0901: + pNewAction.getName();
0902: while (((ManualTest) pTest)
0903: .hasActionName(newName)) {
0904: newName = Language.getInstance()
0905: .getText("Copie_de_")
0906: + newName;
0907: }
0908: pNewAction.setName(newName);
0909: }
0910: //BDD
0911: transNumber = Api
0912: .beginTransaction(Api.INSERT_ACTION);
0913:
0914: //1 Ad action
0915: pNewAction.setOrderIndex(DataModel
0916: .getActionTableModel()
0917: .getRowCount());
0918: if (pNewAction.add2DB(pTest, DataModel
0919: .getActionTableModel()
0920: .getRowCount())) {
0921: Tools.RefreshView(pNewAction.getName(),
0922: Language.getInstance().getText(
0923: "Action"));
0924: }
0925: // 2 Add Use Param
0926: for (Iterator iter = pActionToCopy
0927: .getParameterHashSet().iterator(); iter
0928: .hasNext();) {
0929: Parameter param = (Parameter) iter
0930: .next();
0931: if (!pTest.hasParameterName(param
0932: .getName())) {
0933: pTest
0934: .setUseParamInBddAndModel(param);
0935: //pTest.setUseParamInDB(param.getIdBdd());
0936: }
0937: //pNewAction.setUseParamInDB(param.getIdBdd());
0938: pNewAction
0939: .setUseParamInBddAndModel(param);
0940: }
0941: Api.commitTrans(transNumber);
0942:
0943: //IHM
0944: data.add(pNewAction.getName());
0945: data.add(pNewAction.getDescription());
0946: data.add(pNewAction.getAwaitedResult());
0947: data.add(pNewAction.getAttachmentMap());
0948: for (Iterator iter = pActionToCopy
0949: .getParameterHashSet().iterator(); iter
0950: .hasNext();) {
0951: Parameter param = (Parameter) iter
0952: .next();
0953: if (!pTest.hasParameterName(param
0954: .getName())) {
0955: //pTest.addParameter(param);
0956: //pTest.addParameter(ProjectData.getCurrentProject().getParameter(param.getName()));
0957: ArrayList dataParam = new ArrayList();
0958: dataParam.add(param.getName());
0959: dataParam.add(param
0960: .getDescription());
0961: DataModel
0962: .getTestParameterTableModel()
0963: .addRow(dataParam);
0964: }
0965: // pNewAction.addParameter(pTest.getParameter(param.getName()));
0966: pNewAction.addParameter(ProjectData
0967: .getCurrentProject()
0968: .getParameter(param.getName()));
0969: }
0970: DataModel.getActionTableModel()
0971: .addRow(data);
0972: ((ManualTest) pTest).addAction(pNewAction);
0973: } catch (Exception e_copy) {
0974: Api.forceRollBackTrans(transNumber);
0975: Tools.ihmExceptionView(e_copy.toString());
0976:
0977: }
0978: }
0979: }
0980: } catch (UnsupportedFlavorException e1) {
0981: JOptionPane
0982: .showMessageDialog(
0983: ManualActionView.this ,
0984: Language
0985: .getInstance()
0986: .getText(
0987: "Impossible_de_copier_:_il_ne_s'agit_pas_d'actions_!"),
0988: Language.getInstance().getText(
0989: "Erreur_!"),
0990: JOptionPane.ERROR_MESSAGE);
0991: } catch (IOException e2) {
0992: JOptionPane
0993: .showMessageDialog(
0994: ManualActionView.this ,
0995: Language
0996: .getInstance()
0997: .getText(
0998: "Problème_lors_de_la_récupération_des_données_!"),
0999: Language.getInstance().getText(
1000: "Erreur_!"),
1001: JOptionPane.ERROR_MESSAGE);
1002: }
1003: }
1004: }
1005:
1006: //************** Event table *******************//
1007:
1008: public void valueChanged(ListSelectionEvent e) {
1009: if (e.getSource().equals(actionTable.getSelectionModel())) {
1010: actionTablevalueChanged(e);
1011: }
1012: }
1013:
1014: public void actionTablevalueChanged(ListSelectionEvent e) {
1015: if (e.getValueIsAdjusting())
1016: return;
1017:
1018: int nbOfSelectedRows = actionTable.getSelectedRowCount();
1019: int selectedRow = actionTable.getSelectedRow();
1020: if (selectedRow != -1) {
1021: if (nbOfSelectedRows != 1) {
1022: if (AdminProject.canDeleteTest()) {
1023: deleteManualTestAction.setEnabled(true);
1024: }
1025: modifyAction.setEnabled(false);
1026: } else {
1027: if (AdminProject.canUpdateTest()) {
1028: modifyAction.setEnabled(true);
1029: }
1030: if (AdminProject.canDeleteTest()) {
1031: deleteManualTestAction.setEnabled(true);
1032: }
1033: }
1034: if (AdminProject.canDeleteTest())
1035: cut.setEnabled(true);
1036: if (AdminProject.canCreateTest())
1037: copy.setEnabled(true);
1038:
1039: } else {
1040: deleteManualTestAction.setEnabled(false);
1041: modifyAction.setEnabled(false);
1042: cut.setEnabled(false);
1043: copy.setEnabled(false);
1044: }
1045:
1046: }
1047:
1048: } // Fin de la classe ManualActionView
|