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.main;
0025:
0026: import java.awt.BorderLayout;
0027: import java.awt.Dimension;
0028: import java.awt.FontMetrics;
0029: import java.awt.GridLayout;
0030: import java.awt.Toolkit;
0031: import java.awt.datatransfer.DataFlavor;
0032: import java.awt.datatransfer.Transferable;
0033: import java.awt.datatransfer.UnsupportedFlavorException;
0034: import java.awt.event.ActionEvent;
0035: import java.awt.event.ActionListener;
0036: import java.beans.PropertyChangeEvent;
0037: import java.beans.PropertyChangeListener;
0038: import java.io.IOException;
0039: import java.util.ArrayList;
0040: import java.util.HashMap;
0041: import java.util.HashSet;
0042: import java.util.Hashtable;
0043: import java.util.Iterator;
0044: import java.util.Set;
0045: import java.util.Vector;
0046:
0047: import javax.swing.BorderFactory;
0048: import javax.swing.JButton;
0049: import javax.swing.JOptionPane;
0050: import javax.swing.JPanel;
0051: import javax.swing.JScrollPane;
0052: import javax.swing.JTable;
0053: import javax.swing.ListSelectionModel;
0054: import javax.swing.event.ListSelectionEvent;
0055: import javax.swing.event.ListSelectionListener;
0056:
0057: import org.objectweb.salome_tmf.api.Api;
0058: import org.objectweb.salome_tmf.api.ApiConstants;
0059: import org.objectweb.salome_tmf.api.Permission;
0060: import org.objectweb.salome_tmf.data.Action;
0061: import org.objectweb.salome_tmf.data.Attachment;
0062: import org.objectweb.salome_tmf.data.ManualTest;
0063: import org.objectweb.salome_tmf.data.Parameter;
0064: import org.objectweb.salome_tmf.data.Test;
0065: import org.objectweb.salome_tmf.ihm.languages.Language;
0066: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
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: import org.objectweb.salome_tmf.plugins.UICompCst;
0071:
0072: public class ManualActionView extends JPanel implements ActionListener,
0073: ListSelectionListener, PropertyChangeListener {
0074:
0075: JPanel actionsPanel;
0076:
0077: /**
0078: * Bouton pour la suppression des actions pour les tests manuels
0079: */
0080: static JButton deleteManualTestAction;
0081:
0082: /**
0083: * Table des actions des tests manuels
0084: */
0085: JTable actionTable;
0086:
0087: static JButton modifyAction;
0088: static JButton addAction;
0089: RowTransferHandler transferHandler;
0090:
0091: static JButton paste;
0092: static JButton cut;
0093: static JButton copy;
0094: static JButton orderAction;
0095:
0096: //JTabbedPane m_ParentTab;
0097:
0098: public ManualActionView() {
0099: actionsPanel = new JPanel();
0100:
0101: deleteManualTestAction = new JButton(Language.getInstance()
0102: .getText("Supprimer"));
0103: actionTable = new JTable();
0104: modifyAction = new JButton(Language.getInstance().getText(
0105: "Modifier"));
0106: copy = new JButton(Language.getInstance().getText("Copier"));
0107: paste = new JButton(Language.getInstance().getText("Coller"));
0108: cut = new JButton(Language.getInstance().getText("Couper"));
0109:
0110: addAction = new JButton(Language.getInstance().getText(
0111: "Ajouter"));
0112: addAction.setToolTipText(Language.getInstance().getText(
0113: "Ajouter_une_action"));
0114: addAction.addActionListener(this );
0115:
0116: modifyAction.setToolTipText(Language.getInstance().getText(
0117: "Modifier_une_action"));
0118: modifyAction.setEnabled(false);
0119: modifyAction.addActionListener(this );
0120:
0121: orderAction = new JButton(Language.getInstance().getText(
0122: "Ordonner"));
0123: orderAction.setToolTipText(Language.getInstance().getText(
0124: "Ordonner_les_actions"));
0125: orderAction.addActionListener(this );
0126:
0127: deleteManualTestAction.setEnabled(false);
0128: deleteManualTestAction.setToolTipText(Language.getInstance()
0129: .getText("Supprimer_une_action"));
0130: deleteManualTestAction.addActionListener(this );
0131:
0132: copy.setToolTipText(Language.getInstance().getText("Copier"));
0133: copy.setEnabled(false);
0134: copy.addActionListener(this );
0135:
0136: cut.setToolTipText(Language.getInstance().getText("Couper"));
0137: cut.setEnabled(false);
0138: cut.addActionListener(this );
0139:
0140: paste.setToolTipText(Language.getInstance().getText("Coller"));
0141: paste.setEnabled(false);
0142: paste.addActionListener(this );
0143:
0144: JPanel buttonsPanel = new JPanel(new GridLayout(1, 7));
0145: buttonsPanel.add(addAction);
0146: buttonsPanel.add(modifyAction);
0147: buttonsPanel.add(orderAction);
0148: buttonsPanel.add(deleteManualTestAction);
0149: buttonsPanel.add(copy);
0150: buttonsPanel.add(cut);
0151: buttonsPanel.add(paste);
0152: buttonsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
0153:
0154: transferHandler = new RowTransferHandler();
0155: actionTable.setModel(DataModel.getActionTableModel());
0156:
0157: //TableSorter sorter = new TableSorter(actionTable.getModel() , actionTable.getTableHeader());
0158: //actionTable.setModel(sorter);
0159:
0160: actionTable.setPreferredScrollableViewportSize(new Dimension(
0161: 600, 200));
0162: actionTable.setTransferHandler(transferHandler);
0163: actionTable
0164: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
0165: actionTable.addPropertyChangeListener(this );
0166: JScrollPane tablePane = new JScrollPane(actionTable);
0167:
0168: ListSelectionModel rowSM = actionTable.getSelectionModel();
0169: rowSM.addListSelectionListener(this );
0170:
0171: actionsPanel.setLayout(new BorderLayout());
0172: actionsPanel.add(buttonsPanel, BorderLayout.NORTH);
0173: actionsPanel.add(tablePane, BorderLayout.CENTER);
0174:
0175: this .setLayout(new BorderLayout());
0176: this .add(actionsPanel);
0177:
0178: // Mapping GUI Object for plugins//
0179: // actionsPanel
0180: SalomeTMFContext.getInstance().addToUIComponentsMap(
0181: UICompCst.MANUAL_TEST_ACTIONS_PANEL, actionsPanel);
0182: UICompCst.staticUIComps
0183: .add(UICompCst.MANUAL_TEST_ACTIONS_PANEL);
0184:
0185: // actionTable
0186: SalomeTMFContext.getInstance().addToUIComponentsMap(
0187: UICompCst.MANUAL_TEST_ACTIONS_TABLE, actionTable);
0188: UICompCst.staticUIComps
0189: .add(UICompCst.MANUAL_TEST_ACTIONS_TABLE);
0190:
0191: //buttonsPanel
0192: SalomeTMFContext.getInstance().addToUIComponentsMap(
0193: UICompCst.MANUAL_TEST_ACTIONS_BUTTONS_PANEL,
0194: buttonsPanel);
0195: UICompCst.staticUIComps
0196: .add(UICompCst.MANUAL_TEST_ACTIONS_BUTTONS_PANEL);
0197: } // Fin du constructeur ManualActionView/0
0198:
0199: public void propertyChange(PropertyChangeEvent e) {
0200: if (e.getOldValue() == null) {
0201: //System.out.println("EVENT ------> = " + e.getPropertyName() + "[" + e.getOldValue() +"->"+ e.getNewValue() +"]");
0202: setColumnSize();
0203: }
0204: }
0205:
0206: public void setColumnSize() {
0207: JTable table = actionTable;
0208: FontMetrics fm = table.getFontMetrics(table.getFont());
0209: for (int i = 0; i < table.getColumnCount(); i++) {
0210: int max = 0;
0211: for (int j = 0; j < table.getRowCount(); j++) {
0212: Object obj = table.getValueAt(j, i);
0213: String valueStr = null;
0214: if (obj instanceof String) {
0215: valueStr = (String) table.getValueAt(j, i);
0216: } else if (obj != null) {
0217: valueStr = obj.toString();
0218: }
0219: if (valueStr != null) {
0220: int taille = fm.stringWidth(valueStr);
0221: if (taille > max)
0222: max = taille;
0223: }
0224: }
0225: String nom = (String) table.getColumnModel().getColumn(i)
0226: .getIdentifier();
0227: int taille = fm.stringWidth(nom);
0228: if (taille > max)
0229: max = taille;
0230: table.getColumnModel().getColumn(i).setPreferredWidth(
0231: max + 10);
0232: }
0233: //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
0234: }
0235:
0236: /*public void setParent(JTabbedPane _ParentTab){
0237: if (m_ParentTab != null){
0238: return;
0239: } else {
0240: m_ParentTab = _ParentTab;
0241: m_ParentTab.addChangeListener(new ChangeListener() {
0242: public void stateChanged(ChangeEvent e) {
0243: if (((JTabbedPane)e.getSource()).getSelectedComponent().equals(ManualActionView.this)){
0244:
0245: }
0246: }
0247: });
0248: }
0249: }
0250: */
0251: /**
0252: *
0253: *
0254: */
0255: public static void giveAccessToIhmManualActionView() {
0256: if (!Permission.canDeleteTest()) {
0257: deleteManualTestAction.setEnabled(false);
0258: cut.setEnabled(false);
0259: }
0260: if (!Permission.canCreateTest()) {
0261: addAction.setEnabled(false);
0262: copy.setEnabled(false);
0263: paste.setEnabled(false);
0264: }
0265: if (!Permission.canUpdateTest()) {
0266: modifyAction.setEnabled(false);
0267: orderAction.setEnabled(false);
0268: }
0269:
0270: }
0271:
0272: /**
0273: * Mise a jour des numéro d'ordre des tests d'une campagne
0274: * @param campaign une campagne
0275: */
0276: private static void updateIhmActionOrder(ManualTest test) {
0277: ArrayList actionList = test.getActionListFromModel(false);
0278: for (int i = 0; i < actionList.size(); i++) {
0279: Action action = (Action) actionList.get(i);
0280: action.setOrderIndex(i);
0281: }
0282:
0283: } // Fin de la m?thode updateTestOrderInCampaignTree/1
0284:
0285: /********************** Manage events *************************/
0286:
0287: public void actionPerformed(ActionEvent e) {
0288: if (e.getSource().equals(addAction)) {
0289: addActionPerformed();
0290: setColumnSize();
0291: } else if (e.getSource().equals(modifyAction)) {
0292: modifyActionPerformed();
0293: setColumnSize();
0294: } else if (e.getSource().equals(orderAction)) {
0295: orderActionPerformed();
0296: setColumnSize();
0297: } else if (e.getSource().equals(deleteManualTestAction)) {
0298: deleteManualTestActionPerformed();
0299: setColumnSize();
0300: } else if (e.getSource().equals(copy)) {
0301: copyPerformed();
0302: } else if (e.getSource().equals(cut)) {
0303: cutPerformed();
0304: } else if (e.getSource().equals(paste)) {
0305: pastePerformed();
0306: setColumnSize();
0307: }
0308: }
0309:
0310: public void addActionPerformed() {
0311: String message = DataModel.getCurrentProject()
0312: .getCampaignWithExecResultWhereTestIsUse(
0313: DataModel.getCurrentTest());
0314: if ((!message.equals("")) && (Api.isLockExecutedTest())) {
0315: JOptionPane
0316: .showMessageDialog(
0317: ManualActionView.this ,
0318: Language
0319: .getInstance()
0320: .getText(
0321: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0322: + message
0323: + Language
0324: .getInstance()
0325: .getText(
0326: "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."),
0327: Language.getInstance().getText("Erreur_!"),
0328: JOptionPane.ERROR_MESSAGE);
0329: } else {
0330: if ((!message.equals("")) && (!Api.isLockExecutedTest())) {
0331: Object[] options = {
0332: Language.getInstance().getText("Oui"),
0333: Language.getInstance().getText("Non") };
0334: int choice = SalomeTMFContext
0335: .getInstance()
0336: .askQuestion(
0337: Language
0338: .getInstance()
0339: .getText(
0340: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0341: + message
0342: + Language
0343: .getInstance()
0344: .getText(
0345: "IntegiteCheck"),
0346: Language.getInstance().getText(
0347: "Attention_!"),
0348: JOptionPane.WARNING_MESSAGE, options);
0349: if (choice == JOptionPane.NO_OPTION) {
0350: return;
0351: }
0352: }
0353: AskNewAction addAction = new AskNewAction(
0354: ManualActionView.this , Language.getInstance()
0355: .getText("Ajout_d'une_action"));
0356: Action action = addAction.getAction();
0357: if (action != null) {
0358: if (!((ManualTest) DataModel.getCurrentTest())
0359: .hasActionNameInModel(action.getNameFromModel())) {
0360: int transNumber = -1;
0361: try {
0362: transNumber = Api.beginTransaction(101,
0363: ApiConstants.INSERT_ACTION);
0364: //action.setOrderIndex(DataModel.getActionTableModel()
0365: // .getRowCount());
0366: ((ManualTest) DataModel.getCurrentTest())
0367: .addActionInDBAndModel(action);
0368:
0369: Set keySet = action.getAttachmentMapFromModel()
0370: .keySet();
0371: for (Iterator iter = keySet.iterator(); iter
0372: .hasNext();) {
0373: Attachment attach = (Attachment) action
0374: .getAttachmentMapFromModel().get(
0375: iter.next());
0376: action.addAttachementInDB(attach);
0377: }
0378: HashSet pHashSet = new HashSet(action
0379: .getParameterHashSetFromModel()
0380: .values()); //FOR HashTable2HashSet
0381: for (Iterator iterator = pHashSet.iterator(); iterator
0382: .hasNext();) {
0383: Parameter param = (Parameter) iterator
0384: .next();
0385: action.setUseParamInDBAndModel(param);
0386: }
0387: Api.commitTrans(transNumber);
0388: transNumber = -1;
0389: ArrayList dataList = new ArrayList();
0390: dataList.add(action.getNameFromModel());
0391: dataList.add(action.getDescriptionFromModel());
0392: dataList
0393: .add(action.getAwaitedResultFromModel());
0394: dataList.add(action.getAttachmentMapFromModel()
0395: .keySet());
0396: DataModel.getActionTableModel()
0397: .addRow(dataList);
0398: //action.setOrderIndex(DataModel.getActionTableModel().getRowCount()-1);
0399: //((ManualTest) DataModel.getCurrentTest())
0400: // .addAction(action);
0401:
0402: } catch (Exception exception) {
0403: Api.forceRollBackTrans(transNumber);
0404: ((ManualTest) DataModel.getCurrentTest())
0405: .deleteActionInModel(action);
0406: Tools.ihmExceptionView(exception);
0407: }
0408:
0409: } else {
0410: JOptionPane
0411: .showMessageDialog(
0412: ManualActionView.this ,
0413: Language
0414: .getInstance()
0415: .getText(
0416: "Ce_nom_d'action_existe_déjà_pour_ce_test_!"),
0417: Language.getInstance().getText(
0418: "Erreur_!"),
0419: JOptionPane.ERROR_MESSAGE);
0420: }
0421: }
0422: }
0423: //setColumnSize(actionTable);
0424: }
0425:
0426: public void modifyActionPerformed() {
0427: int selectedRowIndex = actionTable.getSelectedRow();
0428: if (selectedRowIndex != -1) {
0429: String message = DataModel.getCurrentProject()
0430: .getCampaignWithExecResultWhereTestIsUse(
0431: DataModel.getCurrentTest());
0432: if ((!message.equals("")) && (Api.isLockExecutedTest())) {
0433: JOptionPane
0434: .showMessageDialog(
0435: ManualActionView.this ,
0436: Language
0437: .getInstance()
0438: .getText(
0439: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0440: + message
0441: + Language
0442: .getInstance()
0443: .getText(
0444: "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."),
0445: Language.getInstance().getText(
0446: "Avertissement_!"),
0447: JOptionPane.WARNING_MESSAGE);
0448: Action oldAction = ((ManualTest) DataModel
0449: .getCurrentTest())
0450: .getActionFromModel((String) DataModel
0451: .getActionTableModel().getValueAt(
0452: selectedRowIndex, 0));
0453: HashMap oldAttachMap = oldAction
0454: .getCopyOfAttachmentMapFromModel();
0455: String oldName = oldAction.getNameFromModel();
0456:
0457: AskNewAction addAction = new AskNewAction(
0458: ManualActionView.this , Language.getInstance()
0459: .getText("Modifier_une_action"),
0460: oldAction);
0461:
0462: if (addAction.getAction() != null) {
0463: int transNumber = -1;
0464: try {
0465: // BdD
0466: transNumber = Api.beginTransaction(100,
0467: ApiConstants.UPDATE_ACTION);
0468: //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());
0469: Action pAction = addAction.getAction();
0470: String newName = pAction.getNameFromModel();
0471: pAction.updateInModel(oldName, pAction
0472: .getDescriptionFromModel(), pAction
0473: .getAwaitedResultFromModel());
0474: addAction.getAction().updateInDBAndModel(
0475: newName,
0476: pAction.getDescriptionFromModel(),
0477: pAction.getAwaitedResultFromModel());
0478:
0479: // Liste des anciens fichiers attach?s
0480: addAction.getAction().updateAttachement(
0481: oldAttachMap);
0482:
0483: Api.commitTrans(transNumber);
0484: transNumber = -1;
0485: // IHM
0486: ArrayList dataList = new ArrayList();
0487: dataList.add(addAction.getAction()
0488: .getNameFromModel());
0489: dataList.add(addAction.getAction()
0490: .getDescriptionFromModel());
0491: dataList.add(addAction.getAction()
0492: .getAwaitedResultFromModel());
0493: //HashMap newMap = addAction.getAction().getAttachmentMap();
0494: dataList.add(addAction.getAction()
0495: .getAttachmentMapFromModel().keySet());
0496: DataModel.getActionTableModel().modifyData(
0497: dataList, selectedRowIndex);
0498: } catch (Exception exception) {
0499: Api.forceRollBackTrans(transNumber);
0500: addAction.getAction().setAttachmentMapInModel(
0501: oldAttachMap);
0502: Tools.ihmExceptionView(exception);
0503: }
0504:
0505: } else {
0506: oldAction.setAttachmentMapInModel(oldAttachMap);
0507: }
0508: } else {
0509: if ((!message.equals(""))
0510: && (!Api.isLockExecutedTest())) {
0511: Object[] options = {
0512: Language.getInstance().getText("Oui"),
0513: Language.getInstance().getText("Non") };
0514: int choice = SalomeTMFContext
0515: .getInstance()
0516: .askQuestion(
0517: Language
0518: .getInstance()
0519: .getText(
0520: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0521: + message
0522: + Language
0523: .getInstance()
0524: .getText(
0525: "IntegiteCheck"),
0526: Language.getInstance().getText(
0527: "Attention_!"),
0528: JOptionPane.WARNING_MESSAGE,
0529: options);
0530: if (choice == JOptionPane.NO_OPTION) {
0531: return;
0532: }
0533: }
0534: if (DataModel.getCurrentTest() instanceof ManualTest) {
0535:
0536: Action oldAction = ((ManualTest) DataModel
0537: .getCurrentTest())
0538: .getActionFromModel((String) DataModel
0539: .getActionTableModel().getValueAt(
0540: selectedRowIndex, 0));
0541: String oldActionName = oldAction.getNameFromModel();
0542: String oldDescription = oldAction
0543: .getDescriptionFromModel();
0544: String oldAwaitedResult = oldAction
0545: .getAwaitedResultFromModel();
0546:
0547: HashMap oldAttachMap = oldAction
0548: .getCopyOfAttachmentMapFromModel();
0549: Hashtable oldParameter = oldAction
0550: .getCopyOfParameterHashTableFromModel();
0551:
0552: HashSet oldParamSet = new HashSet(oldAction
0553: .getParameterHashSetFromModel().values());//FOR HashTable2HashSet
0554:
0555: AskNewAction addAction = new AskNewAction(
0556: ManualActionView.this , Language
0557: .getInstance().getText(
0558: "Modifier_une_action"),
0559: oldAction);
0560: int transNumber = -1;
0561:
0562: if (addAction.getAction() != null) {
0563: Action pAction = addAction.getAction();
0564: try {
0565: // BdD
0566: transNumber = Api.beginTransaction(101,
0567: ApiConstants.UPDATE_ACTION);
0568: pAction.updateInDBAndModel(pAction
0569: .getNameFromModel(), pAction
0570: .getDescriptionFromModel(), pAction
0571: .getAwaitedResultFromModel());
0572:
0573: /* Les attachement */
0574: pAction.updateAttachement(oldAttachMap);
0575:
0576: /* Les Paramtres */
0577: Hashtable newParameter = pAction
0578: .getParameterHashSetFromModel();
0579: Set keysSet = newParameter.keySet();
0580: for (Iterator iter = keysSet.iterator(); iter
0581: .hasNext();) {
0582: Object paramName = iter.next();
0583: Parameter param = (Parameter) oldParameter
0584: .get(paramName);
0585: Parameter pParam = (Parameter) newParameter
0586: .get(paramName);
0587: if (param == null) {
0588: pAction.setUseParamInDB(pParam
0589: .getIdBdd());
0590: } else {
0591: /* Update */
0592: }
0593: }
0594:
0595: keysSet = oldParameter.keySet();
0596: for (Iterator iter = keysSet.iterator(); iter
0597: .hasNext();) {
0598: Object paramName = iter.next();
0599: Parameter param = (Parameter) newParameter
0600: .get(paramName);
0601: Parameter pParam = (Parameter) oldParameter
0602: .get(paramName);
0603: if (param == null) {
0604: pAction.deleteUseParamInDB(pParam
0605: .getIdBdd());
0606: }
0607: }
0608:
0609: Api.commitTrans(transNumber);
0610:
0611: // IHM
0612: ArrayList dataList = new ArrayList();
0613: dataList.add(addAction.getAction()
0614: .getNameFromModel());
0615: dataList.add(addAction.getAction()
0616: .getDescriptionFromModel());
0617: dataList.add(addAction.getAction()
0618: .getAwaitedResultFromModel());
0619: //HashMap newMap = addAction.getAction().getAttachmentMap();
0620: dataList.add(addAction.getAction()
0621: .getAttachmentMapFromModel()
0622: .keySet());
0623: DataModel.getActionTableModel().modifyData(
0624: dataList, selectedRowIndex);
0625:
0626: } catch (Exception exception) {
0627: Api.forceRollBackTrans(transNumber);
0628: addAction.getAction().updateInModel(
0629: oldActionName, oldDescription,
0630: oldAwaitedResult);
0631: addAction.getAction()
0632: .setAttachmentMapInModel(
0633: oldAttachMap);
0634: addAction.getAction()
0635: .setParameterHashSetInModel(
0636: oldParamSet);
0637: Tools.ihmExceptionView(exception);
0638: }
0639: } else {
0640: // Annuler
0641: oldAction.setAttachmentMapInModel(oldAttachMap);
0642: oldAction
0643: .setParameterHashtableInModel(oldParameter);
0644: }
0645:
0646: }
0647: }
0648: }
0649:
0650: }
0651:
0652: public void orderActionPerformed() {
0653: String message = DataModel.getCurrentProject()
0654: .getCampaignWithExecResultWhereTestIsUse(
0655: DataModel.getCurrentTest());
0656: if ((!message.equals("")) && (Api.isLockExecutedTest())) {
0657: JOptionPane
0658: .showMessageDialog(
0659: ManualActionView.this ,
0660: Language
0661: .getInstance()
0662: .getText(
0663: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0664: + message
0665: + Language
0666: .getInstance()
0667: .getText(
0668: "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."),
0669: Language.getInstance().getText("Erreur_!"),
0670: JOptionPane.ERROR_MESSAGE);
0671: } else {
0672: if ((!message.equals("")) && (!Api.isLockExecutedTest())) {
0673: Object[] options = {
0674: Language.getInstance().getText("Oui"),
0675: Language.getInstance().getText("Non") };
0676: int choice = SalomeTMFContext
0677: .getInstance()
0678: .askQuestion(
0679: Language
0680: .getInstance()
0681: .getText(
0682: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0683: + message
0684: + Language
0685: .getInstance()
0686: .getText(
0687: "IntegiteCheck"),
0688: Language.getInstance().getText(
0689: "Attention_!"),
0690: JOptionPane.WARNING_MESSAGE, options);
0691: if (choice == JOptionPane.NO_OPTION) {
0692: return;
0693: }
0694: }
0695: if (DataModel.getCurrentTest() instanceof ManualTest) {
0696: new ActionOrdering(((ManualTest) DataModel
0697: .getCurrentTest())
0698: .getActionListFromModel(false));
0699: }
0700: }
0701: }
0702:
0703: public void deleteManualTestActionPerformed() {
0704: String message = DataModel.getCurrentProject()
0705: .getCampaignWithExecResultWhereTestIsUse(
0706: DataModel.getCurrentTest());
0707: if ((!message.equals("")) && (Api.isLockExecutedTest())) {
0708: JOptionPane
0709: .showMessageDialog(
0710: ManualActionView.this ,
0711: Language
0712: .getInstance()
0713: .getText(
0714: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0715: + message
0716: + Language
0717: .getInstance()
0718: .getText(
0719: "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."),
0720: Language.getInstance().getText("Erreur_!"),
0721: JOptionPane.ERROR_MESSAGE);
0722: } else {
0723: if ((!message.equals("")) && (!Api.isLockExecutedTest())) {
0724: Object[] options = {
0725: Language.getInstance().getText("Oui"),
0726: Language.getInstance().getText("Non") };
0727: int choice = SalomeTMFContext
0728: .getInstance()
0729: .askQuestion(
0730: Language
0731: .getInstance()
0732: .getText(
0733: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0734: + message
0735: + Language
0736: .getInstance()
0737: .getText(
0738: "IntegiteCheck"),
0739: Language.getInstance().getText(
0740: "Attention_!"),
0741: JOptionPane.WARNING_MESSAGE, options);
0742: if (choice == JOptionPane.NO_OPTION) {
0743: return;
0744: }
0745: }
0746: Object[] options = { Language.getInstance().getText("Oui"),
0747: Language.getInstance().getText("Non") };
0748: int choice = -1;
0749: int[] selectedRows = actionTable.getSelectedRows();
0750: String actionList = "";
0751: for (int i = selectedRows.length - 1; i >= 0; i--) {
0752: actionList = actionList
0753: + "* "
0754: + (String) DataModel.getActionTableModel()
0755: .getValueAt(selectedRows[i], 0);
0756: if (i == 0) {
0757: actionList = actionList + " ?";
0758: } else {
0759: actionList = actionList + " \n";
0760: }
0761: }
0762: choice = JOptionPane
0763: .showOptionDialog(
0764: ManualActionView.this ,
0765: Language
0766: .getInstance()
0767: .getText(
0768: "Etes_vous_sûr_de_vouloir_supprimer_les_actions_:_\n")
0769: + actionList, Language
0770: .getInstance().getText(
0771: "Attention_!"),
0772: JOptionPane.YES_NO_OPTION,
0773: JOptionPane.QUESTION_MESSAGE, null,
0774: options, options[1]);
0775: if (choice == JOptionPane.YES_OPTION) {
0776: for (int i = selectedRows.length - 1; i >= 0; i--) {
0777:
0778: try {
0779: // BdD
0780: Action action = ((ManualTest) DataModel
0781: .getCurrentTest())
0782: .getActionFromModel((String) DataModel
0783: .getActionTableModel()
0784: .getValueAt(selectedRows[i], 0));
0785: //action.deleteFromDB(true);
0786: ((ManualTest) DataModel.getCurrentTest())
0787: .deleteActionInDBModel(action);
0788: //action.deleteFromBddAndModel(true);
0789: // IHM
0790: //((ManualTest)DataModel.getCurrentTest()).deleteAction((String)DataModel.getActionTableModel().getValueAt(selectedRows[i],0));
0791: if (DataModel.getActionTableModel()
0792: .getRowCount() == 0) {
0793: deleteManualTestAction.setEnabled(false);
0794: }
0795: DataModel.getActionTableModel().removeData(
0796: selectedRows[i]);
0797: updateIhmActionOrder((ManualTest) DataModel
0798: .getCurrentTest());
0799:
0800: } catch (Exception exception) {
0801: Tools.ihmExceptionView(exception);
0802: }
0803: }
0804: }
0805: }
0806: //setColumnSize(actionTable);
0807: }
0808:
0809: public void copyPerformed() {
0810: int[] selectedRows = actionTable.getSelectedRows();
0811: ArrayList data = new ArrayList();
0812: for (int i = 0; i < selectedRows.length; i++) {
0813: data
0814: .add(((ManualTest) DataModel.getCurrentTest())
0815: .getActionListFromModel(false).get(
0816: selectedRows[i]));
0817: }
0818: try {
0819: RowTransferable rowTransferable = new RowTransferable(data);
0820: Toolkit.getDefaultToolkit().getSystemClipboard()
0821: .setContents(rowTransferable, null);
0822: } catch (IllegalStateException ise) {
0823: JOptionPane
0824: .showMessageDialog(
0825: ManualActionView.this ,
0826: Language
0827: .getInstance()
0828: .getText(
0829: "Le_presse-papier_est_déjà_utilisé_par_une_autre_application_!"),
0830: Language.getInstance().getText("Erreur_!"),
0831: JOptionPane.ERROR_MESSAGE);
0832: }
0833: paste.setEnabled(true);
0834: }
0835:
0836: public void cutPerformed() {
0837: String message = DataModel.getCurrentProject()
0838: .getCampaignWithExecResultWhereTestIsUse(
0839: DataModel.getCurrentTest());
0840: boolean error = false;
0841: if ((!message.equals("")) && (Api.isLockExecutedTest())) {
0842: JOptionPane
0843: .showMessageDialog(
0844: ManualActionView.this ,
0845: Language
0846: .getInstance()
0847: .getText(
0848: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0849: + message
0850: + Language
0851: .getInstance()
0852: .getText(
0853: "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."),
0854: Language.getInstance().getText("Erreur_!"),
0855: JOptionPane.ERROR_MESSAGE);
0856: } else {
0857: if ((!message.equals("")) && (!Api.isLockExecutedTest())) {
0858: Object[] options = {
0859: Language.getInstance().getText("Oui"),
0860: Language.getInstance().getText("Non") };
0861: int choice = SalomeTMFContext
0862: .getInstance()
0863: .askQuestion(
0864: Language
0865: .getInstance()
0866: .getText(
0867: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0868: + message
0869: + Language
0870: .getInstance()
0871: .getText(
0872: "IntegiteCheck"),
0873: Language.getInstance().getText(
0874: "Attention_!"),
0875: JOptionPane.WARNING_MESSAGE, options);
0876: if (choice == JOptionPane.NO_OPTION) {
0877: return;
0878: }
0879: }
0880: int[] selectedRows = actionTable.getSelectedRows();
0881: ArrayList data = new ArrayList();
0882: for (int i = 0; i < selectedRows.length; i++) {
0883: data.add(((ManualTest) DataModel.getCurrentTest())
0884: .getActionListFromModel(false).get(
0885: selectedRows[i]));
0886: }
0887: try {
0888: RowTransferable rowTransferable = new RowTransferable(
0889: data);
0890: Toolkit.getDefaultToolkit().getSystemClipboard()
0891: .setContents(rowTransferable, null);
0892:
0893: } catch (IllegalStateException ise) {
0894: JOptionPane
0895: .showMessageDialog(
0896: ManualActionView.this ,
0897: Language
0898: .getInstance()
0899: .getText(
0900: "Le_presse-papier_est_déjà_utilisé_par_une_autre_apllication_!"),
0901: Language.getInstance().getText(
0902: "Erreur_!"),
0903: JOptionPane.ERROR_MESSAGE);
0904: error = true;
0905: }
0906: if (!error) {
0907: for (int i = selectedRows.length - 1; i >= 0; i--) {
0908:
0909: try {
0910: //BdD
0911: Action action = ((ManualTest) DataModel
0912: .getCurrentTest())
0913: .getActionFromModel((String) DataModel
0914: .getActionTableModel()
0915: .getValueAt(selectedRows[i], 0));
0916: //action.deleteFromDB(true);
0917: //((ManualTest)DataModel.getCurrentTest()).deleteActionInModel(action);
0918: ((ManualTest) DataModel.getCurrentTest())
0919: .deleteActionInDBModel(action);
0920: //action.deleteFromBddAndModel(true);
0921: // IHM
0922: //((ManualTest)DataModel.getCurrentTest()).deleteAction((String)DataModel.getActionTableModel().getValueAt(selectedRows[i],0));
0923: DataModel.getActionTableModel().removeData(
0924: selectedRows[i]);
0925: } catch (Exception exception) {
0926: Tools.ihmExceptionView(exception);
0927: }
0928: }
0929: updateIhmActionOrder((ManualTest) DataModel
0930: .getCurrentTest());
0931: paste.setEnabled(true);
0932: }
0933: }
0934: }
0935:
0936: public void pastePerformed() {
0937: String message = DataModel.getCurrentProject()
0938: .getCampaignWithExecResultWhereTestIsUse(
0939: DataModel.getCurrentTest());
0940: if ((!message.equals("")) && (Api.isLockExecutedTest())) {
0941: JOptionPane
0942: .showMessageDialog(
0943: ManualActionView.this ,
0944: Language
0945: .getInstance()
0946: .getText(
0947: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0948: + message
0949: + Language
0950: .getInstance()
0951: .getText(
0952: "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."),
0953: Language.getInstance().getText("Erreur_!"),
0954: JOptionPane.ERROR_MESSAGE);
0955: } else {
0956: if ((!message.equals("")) && (!Api.isLockExecutedTest())) {
0957: Object[] options = {
0958: Language.getInstance().getText("Oui"),
0959: Language.getInstance().getText("Non") };
0960: int choice = SalomeTMFContext
0961: .getInstance()
0962: .askQuestion(
0963: Language
0964: .getInstance()
0965: .getText(
0966: "Ce_test_est_utilisé_dans_les_campagnes_:_\n")
0967: + message
0968: + Language
0969: .getInstance()
0970: .getText(
0971: "IntegiteCheck"),
0972: Language.getInstance().getText(
0973: "Attention_!"),
0974: JOptionPane.WARNING_MESSAGE, options);
0975: if (choice == JOptionPane.NO_OPTION) {
0976: return;
0977: }
0978: }
0979: Transferable t = Toolkit.getDefaultToolkit()
0980: .getSystemClipboard().getContents(null);
0981: try {
0982: DataFlavor dataFlavor = new DataFlavor(ArrayList.class,
0983: "ArrayList");
0984: /** V?rification que le contenu est de type texte. */
0985: if (t != null && t.isDataFlavorSupported(dataFlavor)) {
0986: ArrayList actionsList = (ArrayList) t
0987: .getTransferData(dataFlavor);
0988: Test pTest = DataModel.getCurrentTest();
0989: for (int i = 0; i < actionsList.size(); i++) {
0990: int transNumber = -1;
0991: try {
0992: //Init
0993: ArrayList data = new ArrayList();
0994: Action pActionToCopy = (Action) actionsList
0995: .get(i);
0996: Action pNewAction = new Action(
0997: pActionToCopy, pTest);
0998:
0999: if (((ManualTest) pTest)
1000: .hasActionNameInModel(pNewAction
1001: .getNameFromModel())) {
1002: String newName = Language.getInstance()
1003: .getText("Copie_de_")
1004: + pNewAction.getNameFromModel();
1005: while (((ManualTest) pTest)
1006: .hasActionNameInModel(newName)) {
1007: newName = Language.getInstance()
1008: .getText("Copie_de_")
1009: + newName;
1010: }
1011: pNewAction
1012: .updateInModel(
1013: newName,
1014: pNewAction
1015: .getDescriptionFromModel(),
1016: pNewAction
1017: .getAwaitedResultFromModel());
1018: }
1019: //BDD
1020: transNumber = Api.beginTransaction(101,
1021: ApiConstants.INSERT_ACTION);
1022:
1023: //1 Ad action
1024: pNewAction.setOrderIndex(DataModel
1025: .getActionTableModel()
1026: .getRowCount());
1027: ((ManualTest) pTest)
1028: .addActionInDB(pNewAction);
1029:
1030: // 2 Add Use Param
1031: Vector paramToAdd2Test = new Vector();
1032: HashSet paramsSet = new HashSet(
1033: pActionToCopy
1034: .getParameterHashSetFromModel()
1035: .values()); //FOR HashTable2HashSet
1036: for (Iterator iter = paramsSet.iterator(); iter
1037: .hasNext();) {
1038: Parameter param = (Parameter) iter
1039: .next();
1040: if (!pTest
1041: .hasUsedParameterNameFromModel(param
1042: .getNameFromModel())) {
1043: pTest
1044: .setUseParamInDBAndModel(param);
1045: //pTest.setUseParamInDB(param.getIdBdd());
1046: paramToAdd2Test.add(param);
1047: }
1048: //pNewAction.setUseParamInDB(param.getIdBdd());
1049: pNewAction
1050: .setUseParamInDBAndModel(param);
1051: }
1052: Api.commitTrans(transNumber);
1053: transNumber = -1;
1054: //IHM
1055: data.add(pNewAction.getNameFromModel());
1056: data.add(pNewAction
1057: .getDescriptionFromModel());
1058: data.add(pNewAction
1059: .getAwaitedResultFromModel());
1060: data.add(pNewAction
1061: .getAttachmentMapFromModel());
1062: for (int j = 0; j < paramToAdd2Test.size(); j++) {
1063: Parameter param = (Parameter) paramToAdd2Test
1064: .get(j);
1065: ArrayList dataParam = new ArrayList();
1066: dataParam.add(param.getNameFromModel());
1067: dataParam.add(param
1068: .getDescriptionFromModel());
1069: DataModel.getTestParameterTableModel()
1070: .addRow(dataParam);
1071: }
1072: paramToAdd2Test.clear();
1073: DataModel.getActionTableModel()
1074: .addRow(data);
1075: ((ManualTest) pTest)
1076: .addActionInModel(pNewAction);
1077: } catch (Exception e_copy) {
1078: Api.forceRollBackTrans(transNumber);
1079: Tools.ihmExceptionView(e_copy);
1080:
1081: }
1082: }
1083: }
1084: } catch (UnsupportedFlavorException e1) {
1085: JOptionPane
1086: .showMessageDialog(
1087: ManualActionView.this ,
1088: Language
1089: .getInstance()
1090: .getText(
1091: "Impossible_de_copier_:_il_ne_s'agit_pas_d'actions_!"),
1092: Language.getInstance().getText(
1093: "Erreur_!"),
1094: JOptionPane.ERROR_MESSAGE);
1095: } catch (IOException e2) {
1096: if (Api.isDEBUG()) {
1097: e2.printStackTrace();
1098: }
1099: JOptionPane
1100: .showMessageDialog(
1101: ManualActionView.this ,
1102: Language
1103: .getInstance()
1104: .getText(
1105: "Problème_lors_de_la_récupération_des_données_!"),
1106: Language.getInstance().getText(
1107: "Erreur_!"),
1108: JOptionPane.ERROR_MESSAGE);
1109: }
1110: }
1111: }
1112:
1113: //************** Event table *******************//
1114:
1115: public void valueChanged(ListSelectionEvent e) {
1116: if (e.getSource().equals(actionTable.getSelectionModel())) {
1117: actionTablevalueChanged(e);
1118: }
1119: //setColumnSize2(actionTable);
1120: }
1121:
1122: public void actionTablevalueChanged(ListSelectionEvent e) {
1123: if (e.getValueIsAdjusting())
1124: return;
1125:
1126: int nbOfSelectedRows = actionTable.getSelectedRowCount();
1127: int selectedRow = actionTable.getSelectedRow();
1128: if (selectedRow != -1) {
1129: if (nbOfSelectedRows != 1) {
1130: if (Permission.canDeleteTest()) {
1131: deleteManualTestAction.setEnabled(true);
1132: }
1133: modifyAction.setEnabled(false);
1134: } else {
1135: if (Permission.canUpdateTest()) {
1136: modifyAction.setEnabled(true);
1137: }
1138: if (Permission.canDeleteTest()) {
1139: deleteManualTestAction.setEnabled(true);
1140: }
1141: }
1142: if (Permission.canDeleteTest())
1143: cut.setEnabled(true);
1144: if (Permission.canCreateTest())
1145: copy.setEnabled(true);
1146:
1147: } else {
1148: deleteManualTestAction.setEnabled(false);
1149: modifyAction.setEnabled(false);
1150: cut.setEnabled(false);
1151: copy.setEnabled(false);
1152: }
1153:
1154: }
1155:
1156: } // Fin de la classe ManualActionView
|