ParameterView.java :  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » ihm » Java Open Source

Java Open Source » Test Coverage » salome tmf 
salome tmf » org » objectweb » salome_tmf » ihm » ParameterView.java
/*
* SalomeTMF is a Test Management Framework
* Copyright (C) 2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Fayal SOUGRATI, Vincent Pautret, Marche Mikael
*
* Contact: mikael.marche@rd.francetelecom.com
*/

package org.objectweb.salome_tmf.ihm;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;

import org.objectweb.salome_tmf.api.Api;
import org.objectweb.salome_tmf.api.api2ihm.AdminProject;
import org.objectweb.salome_tmf.data.Action;
import org.objectweb.salome_tmf.data.Campaign;
import org.objectweb.salome_tmf.data.CampaignData;
import org.objectweb.salome_tmf.data.ConnectionData;
import org.objectweb.salome_tmf.data.DataConstants;
import org.objectweb.salome_tmf.data.DataSet;
import org.objectweb.salome_tmf.data.Environment;
import org.objectweb.salome_tmf.data.Execution;
import org.objectweb.salome_tmf.data.Family;
import org.objectweb.salome_tmf.data.ManualTest;
import org.objectweb.salome_tmf.data.Parameter;
import org.objectweb.salome_tmf.data.ProjectData;
import org.objectweb.salome_tmf.data.Test;
import org.objectweb.salome_tmf.data.TestList;
import org.objectweb.salome_tmf.data.TestPlanData;
import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
import org.objectweb.salome_tmf.ihm.languages.Language;
import org.objectweb.salome_tmf.ihm.models.TableSorter;
import org.objectweb.salome_tmf.ihm.plugins.PluginsTools;
import org.objectweb.salome_tmf.ihm.tools.Tools;

/**
 * @author teaml039
 * @version : 0.1
 */
public class ParameterView extends JPanel implements DataConstants, ActionListener, ListSelectionListener {
    
    JPanel paramsPanel;
    
    JButton modifyParameterButton;
    
    JButton deleteParameterButton;
    
    JButton addParameter;
    
    JButton useParameterButton;
    //  MyTableModel manualParameterTableModel = new MyTableModel();
    
    JTable parametersTable;
    
    boolean usingFonctionEnable;
    
    TableSorter  sorter;
    /******************************************************************************/
    /**               CONSTRUCTEUR                ***/
    /******************************************************************************/
    
    
    /**
     *
     * type is use for plugin UI = AUTOMATIC_TEST or MANUAL_TEST or PARAMETER or -1 for Dynamic
     */
    
    public ParameterView(boolean use, int type) {
        paramsPanel = new JPanel();
        
        modifyParameterButton = new JButton(Language.getInstance().getText("Modifier"));
        deleteParameterButton = new JButton(Language.getInstance().getText("Supprimer"));
        parametersTable = new JTable();
        
        addParameter = new JButton(Language.getInstance().getText("Nouveau"));
        addParameter.setToolTipText(Language.getInstance().getText("Ajouter_un_nouveau_paramtre"));
        addParameter.addActionListener(this);
        
        useParameterButton = new JButton(Language.getInstance().getText("Utiliser"));
        useParameterButton.setToolTipText(Language.getInstance().getText("Utiliser_des_paramtres_existants"));
        useParameterButton.addActionListener(this);
        
        modifyParameterButton.setEnabled(false);
        modifyParameterButton.setToolTipText(Language.getInstance().getText("Modifier_un_paramtre"));
        modifyParameterButton.addActionListener(this);
        
        deleteParameterButton.setToolTipText(Language.getInstance().getText("Supprimer_un_paramtre"));
        deleteParameterButton.setEnabled(false);
        deleteParameterButton.addActionListener(this);
        
        JPanel buttonsPanel = new JPanel(new GridLayout(1,3));
        buttonsPanel.add(addParameter);
        
        if (use) {
            buttonsPanel.add(useParameterButton);
        }
        
        buttonsPanel.add(modifyParameterButton);
        buttonsPanel.add(deleteParameterButton);
        buttonsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
        
        ListSelectionModel rowSM = parametersTable.getSelectionModel();
        rowSM.addListSelectionListener(this);
        
        //sorter = new TableSorter();
        if (use) {
            sorter = new TableSorter(DataModel.getTestParameterTableModel());
            //parametersTable.setModel(DataModel.getTestParameterTableModel());
        } else {
            sorter = new TableSorter(DataModel.getParameterTableModel());
            //parametersTable.setModel(DataModel.getParameterTableModel());
        }
        parametersTable.setModel(sorter);
        sorter.setTableHeader(parametersTable.getTableHeader());
        
        parametersTable.setPreferredScrollableViewportSize(new Dimension(600, 200));
        parametersTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        
        
        JScrollPane tablePane = new JScrollPane(parametersTable);
        tablePane.setBorder(BorderFactory.createRaisedBevelBorder());
        
        initData(use);
        
        paramsPanel.setLayout(new BorderLayout());
        paramsPanel.add(buttonsPanel, BorderLayout.NORTH);
        paramsPanel.add(tablePane, BorderLayout.CENTER);
        
        
        this.setLayout(new BorderLayout());
        this.add(paramsPanel);
        
        mapUIComponents(paramsPanel, parametersTable, buttonsPanel, type);
             
    } // Fin du constructeur ManualParameterView/0
    
    
    void mapUIComponents(JPanel paramsPanel, JTable parametersTable, JPanel buttonsPanel, int type){
      switch (type) {
      case MANUAL_TEST : {
        SalomeTMF.addToUIComponentsMap(UICompCst.MANUAL_TEST_PARAMS_PANEL,paramsPanel);
        UICompCst.staticUIComps.add(UICompCst.MANUAL_TEST_PARAMS_PANEL);
        
        SalomeTMF.addToUIComponentsMap(UICompCst.MANUAL_TEST_PARAMS_TABLE,parametersTable);
        UICompCst.staticUIComps.add(UICompCst.MANUAL_TEST_PARAMS_TABLE);
        
        SalomeTMF.addToUIComponentsMap(UICompCst.MANUAL_TEST_PARAMS_BUTTONS_PANEL,buttonsPanel);
        UICompCst.staticUIComps.add(UICompCst.MANUAL_TEST_PARAMS_BUTTONS_PANEL);
        break;
      }
      case AUTOMATIC_TEST : {
        SalomeTMF.addToUIComponentsMap(UICompCst.AUTOMATED_TEST_PARAMS_PANEL,paramsPanel);
        UICompCst.staticUIComps.add(UICompCst.AUTOMATED_TEST_PARAMS_PANEL);
        
        SalomeTMF.addToUIComponentsMap(UICompCst.AUTOMATED_TEST_PARAMS_TABLE,parametersTable);
        UICompCst.staticUIComps.add(UICompCst.AUTOMATED_TEST_PARAMS_TABLE);
        
        SalomeTMF.addToUIComponentsMap(UICompCst.AUTOMATED_TEST_PARAMS_BUTTONS_PANEL,buttonsPanel);
        UICompCst.staticUIComps.add(UICompCst.AUTOMATED_TEST_PARAMS_BUTTONS_PANEL);
        break;
      }
      case PARAMETER : {
        SalomeTMF.addToUIComponentsMap(UICompCst.DATA_PARAMS_PANEL,paramsPanel);
        UICompCst.staticUIComps.add(UICompCst.DATA_PARAMS_PANEL);
        
        SalomeTMF.addToUIComponentsMap(UICompCst.DATA_PARAMS_TABLE,parametersTable);
        UICompCst.staticUIComps.add(UICompCst.DATA_PARAMS_TABLE);
        
        SalomeTMF.addToUIComponentsMap(UICompCst.DATA_PARAMS_BUTTONS_PANEL,buttonsPanel);
        UICompCst.staticUIComps.add(UICompCst.DATA_PARAMS_BUTTONS_PANEL);
        break;
      }
      
      default: {
        SalomeTMF.addToUIComponentsMap(UICompCst.PARAMS_PANEL,paramsPanel);
          PluginsTools.activateAssociatedPlgs(UICompCst.PARAMS_PANEL);
          
          SalomeTMF.addToUIComponentsMap(UICompCst.PARAMS_TABLE,parametersTable);
          PluginsTools.activateAssociatedPlgs(UICompCst.PARAMS_TABLE);
          
          SalomeTMF.addToUIComponentsMap(UICompCst.PARAMS_BUTTONS_PANEL,buttonsPanel);
          PluginsTools.activateAssociatedPlgs(UICompCst.PARAMS_BUTTONS_PANEL);   
      }
      }
    }
    /**
     *
     * @param use
     */
    private void initData(boolean use) {
        usingFonctionEnable = use;
    }
    
    /**
     *
     * @param use
     */
    public static void addNewParameter(boolean use) {
        AskNewParameter askNewParameter = new AskNewParameter(null);
        Parameter param = askNewParameter.getParameter();
        if (param != null && param.getName() != null && param.getName() != "") {
            if (!ProjectData.getCurrentProject().containsParameter(param.getName().trim())) {
                
                try {
                    //param.add2DB();
                    ProjectData.getCurrentProject().addParameterToBddAndModel(param);
                    ArrayList dataList = new ArrayList();
                    dataList.add(param.getName());
                    dataList.add(param.getDescription());
                    //ProjectData.getCurrentProject().addParameter(param);
                    DataModel.getParameterTableModel().addRow(dataList);
                    if (use) {
                        if (ConnectionData.isConnected()) {
                            try {
                                DataModel.getCurrentTest().setUseParamInBddAndModel(param);
                            } catch (Exception exception) {
                                Tools.ihmExceptionView(exception.toString());
                            }
                        }
                        if (Api.getException() == null || Api.getException().size() == 0) {
                            DataModel.getTestParameterTableModel().addRow(dataList);
                            //DataModel.getCurrentTest().addParameter(param);
                        }
                    }
                    
                } catch (Exception exception) {
                    Tools.ihmExceptionView(exception.toString());
                }
                
            } else {
                JOptionPane.showMessageDialog(null,
                Language.getInstance().getText("Ce_nom_de_paramtre_existe_dj_!"),
                Language.getInstance().getText("Erreur_!"),
                JOptionPane.ERROR_MESSAGE);
            }
        }
    }
    
    /**
     *
     *
     */
    public static void usingParameter() {
        UsingDefinedParameterView usingDefinedParameterView = new UsingDefinedParameterView(false, false);
        if (usingDefinedParameterView.getParameterList() != null) {
            for (int i =0; i < usingDefinedParameterView.getParameterList().size(); i++) {
                Parameter param = (Parameter)usingDefinedParameterView.getParameterList().get(i);
                if (!DataModel.getCurrentTest().hasParameterName(param.getName())) {
                    
                    try {
                        DataModel.getCurrentTest().setUseParamInBddAndModel(param);
                        ArrayList dataList = new ArrayList();
                        dataList.add(param.getName());
                        dataList.add(param.getDescription());
                        DataModel.getTestParameterTableModel().addRow(dataList);
                        //DataModel.getCurrentTest().addParameter(param);
                    } catch (Exception exception) {
                        Tools.ihmExceptionView(exception.toString());
                    }
                    
                } else {
                    JOptionPane.showMessageDialog(null,
                    Language.getInstance().getText("Le_paramtre_")+ param.getName() +Language.getInstance().getText("_existe_dj_pour_ce_test_!"),
                    Language.getInstance().getText("Erreur_!"),
                    JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    
    /**
     *
     * @param currentTest
     * @param paramName
     */
    /*private static void cleanActionOfParameter(Test currentTest, String paramName) {
        if (currentTest instanceof ManualTest) {
            for (int i = 0; i < ((ManualTest)currentTest).getActionList().size(); i++) {
                
                //Action action = (Action)((ManualTest)DataModel.getCurrentTest()).getActionList().get(i);
              Action action = (Action)((ManualTest)currentTest).getActionList().get(i);
                
                try {
                  String newDesc = Tools.clearStringOfParameter(action.getDescription(), paramName);
                    String newResult = Tools.clearStringOfParameter(action.getAwaitedResult(), paramName);
                    
                  // DB
                  action.updateInDB(action.getName(), newDesc, newResult, action.getOrderIndex());
                    
                    // Data
                  
                    action.getParameterHashSet().remove(DataModel.getCurrentProject().getParameter(paramName));
                    
                    if (DataModel.getCurrentTest() != null) {
                    if (DataModel.getCurrentTest().equals(currentTest)) {
                        int row = DataModel.getActionTableModel().findRow(action.getName());
                        DataModel.getActionTableModel().setValueAt(newDesc, row, 1);
                        DataModel.getActionTableModel().setValueAt(newResult, row, 2);
                    }
                    }
                } catch (Exception exception) {
                    Tools.ihmExceptionView(exception.toString());
                }
            }
        }
    } // Fin de la m?thode cleanActionOfParameter/2
    */
    
    private static void upadateActionOfParameterView(Test currentTest, String paramName) {
        if (currentTest instanceof ManualTest) {
            for (int i = 0; i < ((ManualTest)currentTest).getActionList().size(); i++) {
               Action action = (Action)((ManualTest)currentTest).getActionList().get(i); 
                try {
                    if (DataModel.getCurrentTest() != null && DataModel.getCurrentTest().equals(currentTest)) {
                        int row = DataModel.getActionTableModel().findRow(action.getName());
                        DataModel.getActionTableModel().setValueAt(action.getDescription(), row, 1);
                        DataModel.getActionTableModel().setValueAt(action.getAwaitedResult(), row, 2);
                    }
                } catch (Exception exception) {
                    Tools.ihmExceptionView(exception.toString());
                }
            }
        }
    } // Fin de la m?thode cleanActionOfParameter/2
    
    /**
     *
     *
     */
    public void giveAccessToIhmParameterView() {
        if (usingFonctionEnable) {
            if (!AdminProject.canDeleteTest()) {
                deleteParameterButton.setEnabled(false);
                
            }
            if (!AdminProject.canCreateTest()) {
                addParameter.setEnabled(false);
                useParameterButton.setEnabled(false);
                
            }
            if (!AdminProject.canUpdateTest()) {
                modifyParameterButton.setEnabled(false);
                
            }
            
        } else {
            if (!AdminProject.canDeleteCamp()) {
                deleteParameterButton.setEnabled(false);
            }
            if (!AdminProject.canCreateCamp() && !AdminProject.canExecutCamp()) {
                addParameter.setEnabled(false);
                useParameterButton.setEnabled(false);
            }
            if (!AdminProject.canUpdateCamp() && !AdminProject.canExecutCamp()) {
                modifyParameterButton.setEnabled(false);
            }
        }
        
    }
    /***************** Event Managment ************************/
    public void actionPerformed(ActionEvent e) {
      if (e.getSource().equals(addParameter)){
        addParameterPerformed();
      } else if (e.getSource().equals(useParameterButton)) {
        useParameterButtonPerformed();
      } else if (e.getSource().equals(modifyParameterButton)) {
        modifyParameterButtonPerformed();
      } else if (e.getSource().equals(deleteParameterButton)){
        deleteParameterButtonPerformed();
      }
    }
    
    public void valueChanged(ListSelectionEvent e) {
      if (e.getSource().equals(parametersTable.getSelectionModel())){
         parametersTablevalueChanged(e);
      }
    }
    
    
    public void addParameterPerformed() {
      String message = CampaignData.getCampaignWithExecResultWhereTestIsUse(DataModel.getCurrentTest());
      if (!message.equals("") && usingFonctionEnable) {
        JOptionPane.showMessageDialog(ParameterView.this,
            Language.getInstance().getText("Ce_test_est_utilis_dans_les_campagnes_:_\n") + message + Language.getInstance().getText("qui_possdent_des_rsultats_d'excutions.\nAfin_de_conserver_l'intgrit_des_rsultats,_vous_ne_pouvez_pas_ajouter_un_nouveau_paramtre."),
            Language.getInstance().getText("Erreur_!"),
            JOptionPane.ERROR_MESSAGE);
      } else {
        addNewParameter(usingFonctionEnable);
      }
    }
   
    
    public void useParameterButtonPerformed() {
      String message = CampaignData.getCampaignWithExecResultWhereTestIsUse(DataModel.getCurrentTest());
      if (!message.equals("") && usingFonctionEnable) {
        JOptionPane.showMessageDialog(ParameterView.this,
            Language.getInstance().getText("Ce_test_est_utilis_dans_les_campagnes_:_\n") + message + Language.getInstance().getText("qui_possdent_des_rsultats_d'excutions.\nAfin_de_conserver_l'intgrit_des_rsultats,_vous_ne_pouvez_pas_ajouter_un_paramtre_dj_dfini."),
            Language.getInstance().getText("Erreur_!"),
            JOptionPane.ERROR_MESSAGE);
      } else {
        
        usingParameter();
      }
    }
    
    public void modifyParameterButtonPerformed() {
      int selectedRowIndex = parametersTable.getSelectedRow();
      if (selectedRowIndex != -1) {
        String message = CampaignData.getCampaignWithExecResultWhereTestIsUse(DataModel.getCurrentTest());
        if (!message.equals("") && usingFonctionEnable) {
          JOptionPane.showMessageDialog(ParameterView.this,
              Language.getInstance().getText("Ce_test_est_utilis_dans_les_campagnes_:_\n") + message + Language.getInstance().getText("qui_possdent_des_rsultats_d'excutions.\nAfin_de_conserver_l'intgrit_des_rsultats,_vous_ne_pouvez_pas_modifier_ce_paramtre."),
              Language.getInstance().getText("Erreur_!"),
              JOptionPane.ERROR_MESSAGE);
        } else {
          
          ArrayList paramList;
          if (usingFonctionEnable) {
            //paramList = DataModel.getTestParameterTableModel().getData(selectedRowIndex);
            paramList = DataModel.getTestParameterTableModel().getData(sorter.modelIndex(selectedRowIndex));
            
          } else {
            //paramList = DataModel.getParameterTableModel().getData(selectedRowIndex);
            paramList = DataModel.getParameterTableModel().getData(sorter.modelIndex(selectedRowIndex));
          }
          AskNameAndDescription askNewParameter = null;
          if (paramList != null && paramList.size() == parametersTable.getColumnCount()) {
            askNewParameter = new AskNameAndDescription(PARAMETER, Language.getInstance().getText("Modifier_un_paramtre"), Language.getInstance().getText("Nom_du_paramtre_:_"), ProjectData.getCurrentProject().getParameter((String)paramList.get(0)),SalomeTMF.ptrFrame);
          }
          if (askNewParameter != null) {
            Parameter param = askNewParameter.getNewParameter();
            if (param != null) {
              
              
              try {
                // BdD
                param.updateDescriptionInBddAndModel(param.getDescription());
                
                // IHM
                ArrayList dataList = new ArrayList();
                dataList.add(param.getName());
                dataList.add(param.getDescription());
                if (usingFonctionEnable) {
                  DataModel.getTestParameterTableModel().modifyData(dataList,sorter.modelIndex(selectedRowIndex));
                  Parameter oldParam = ((ManualTest)DataModel.getCurrentTest()).getParameter((String)paramList.get(0));
                  oldParam.setName(param.getName());
                  oldParam.setDescription(param.getDescription());
                } else {
                  DataModel.getParameterTableModel().modifyData(dataList, sorter.modelIndex(selectedRowIndex));
                }
              } catch(Exception exception) {
                Tools.ihmExceptionView(exception.toString());
              }
            }
          }
        }
      }
    }   
    
    
    
    
    public void deleteParameterButtonPerformed() {
      int selectedRowIndex = parametersTable.getSelectedRow();
      String paramName;
      if (usingFonctionEnable) {
        String message = CampaignData.getCampaignWithExecResultWhereTestIsUse(DataModel.getCurrentTest());
        if (!message.equals("") && usingFonctionEnable) {
          JOptionPane.showMessageDialog(ParameterView.this,
              Language.getInstance().getText("Ce_test_est_utilis_dans_les_campagnes_:_\n") + message + Language.getInstance().getText("qui_possdent_des_rsultats_d'excutions.\nAfin_de_conserver_l'intgrit_des_rsultats,_vous_ne_pouvez_pas_supprimer_ce_paramtre."),
              Language.getInstance().getText("Erreur_!"),
              JOptionPane.ERROR_MESSAGE);
        } else {
          
          Object[] options = {Language.getInstance().getText("Oui"), Language.getInstance().getText("Non")};
          int choice = -1;
          choice = JOptionPane.showOptionDialog(ParameterView.this,
              //"Etes vous s?r de vouloir supprimer le param?tre <" +(String)DataModel.getTestParameterTableModel().getValueAt(selectedRowIndex, 0) + "> du test <" + DataModel.getCurrentTest() + "> ?",
              Language.getInstance().getText("Etes_vous_sr_de_vouloir_supprimer_le_paramtre_<") +(String)sorter.getValueAt(selectedRowIndex, 0) + Language.getInstance().getText(">_du_test_<") + DataModel.getCurrentTest() + "> ?",
              Language.getInstance().getText("Attention_!"),
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              options[1]);
          if (choice == JOptionPane.YES_OPTION) {
            //paramName = (String)DataModel.getTestParameterTableModel().getValueAt(selectedRowIndex, 0);
            paramName = (String)sorter.getValueAt(selectedRowIndex, 0);
            
            
            try {
              Test test = DataModel.getCurrentTest();
              Parameter param = test.getParameter(paramName);
              
              // BdD & Model
              //test.deleteUseParamFromDB(param);
              test.deleteUseParamInBddAndModel(param);
              // DataModel.getCurrentTest().deleteParameter(paramName);
              // IHM
              DataModel.getTestParameterTableModel().removeData(sorter.modelIndex(selectedRowIndex));
              if (DataModel.getTestParameterTableModel().getRowCount() == 0) {
                deleteParameterButton.setEnabled(false);
              }
              upadateActionOfParameterView(test, paramName);
              
            } catch (Exception exception) {
              Tools.ihmExceptionView(exception.toString());
            }
          }
        }
      } else {
        //paramName = (String)DataModel.getParameterTableModel().getValueAt(selectedRowIndex, 0);
        paramName = (String)sorter.getValueAt(selectedRowIndex, 0);
        ArrayList testsOfParam = TestPlanData.getTestOfParameter(paramName);
        ArrayList envOfParam = ProjectData.getEnvironmentOfParameter(paramName);
        if (testsOfParam.size() > 0 || envOfParam.size() > 0) {
          Object[] options = {Language.getInstance().getText("Oui"), Language.getInstance().getText("Non")};
          int choice = -1;
          //int actionCase = -1;
          String message = Language.getInstance().getText("Le_paramtre_<") + paramName + Language.getInstance().getText(">_est_utilis_dans_les_tests_:\n");
          String campaignMessage = "";
          ArrayList concernedCampaign = new ArrayList();
          String testsMessage = "";
          String envMessage = "";
          //String toBeDelete = "";
          for (int i = 0; i < testsOfParam.size(); i++) {
            testsMessage = testsMessage + "* " + ((Test)testsOfParam.get(i)).getTestList().getFamily().getName() + "/" + ((Test)testsOfParam.get(i)).getTestList().getName() + "/" + ((Test)testsOfParam.get(i)).getName()+"\n";
            ArrayList campaignOfTest = CampaignData.getCampaignOfTest((Test)testsOfParam.get(i));
            if (campaignOfTest.size() > 0) {
              for (int j = 0; j < campaignOfTest.size(); j++) {
                if (!concernedCampaign.contains(campaignOfTest.get(j))) {
                  campaignMessage = campaignMessage + "* " + ((Campaign)campaignOfTest.get(j)).getName() + "\n";
                  concernedCampaign.add(campaignOfTest.get(j));
                }
              }
            }
          }
          for (int k = 0; k < envOfParam.size(); k++) {
            if (((Environment)envOfParam.get(k)).containsParameter(paramName)) {
              envMessage = envMessage + "* " + ((Environment)envOfParam.get(k)).getName() + "\n";
            }
          }
          
          message = message + testsMessage + Language.getInstance().getText("dans_les_campagnes_:_\n") +campaignMessage + Language.getInstance().getText("dans_les_environnements_:\n") + envMessage;
          message = message + Language.getInstance().getText("Le_paramtre_sera_supprim_des_tests_et_des_environnements_et_des_jeux_de_donnes_concerns.\nLes_rsultats_d'excutions_des_campagnes_seront_perdus.\n");
          choice = JOptionPane.showOptionDialog(ParameterView.this,
              message + Language.getInstance().getText("Etes_vous_sr_de_vouloir_supprimer_le_paramtre_<_") + paramName + " > ?",
              Language.getInstance().getText("Attention_!"),
              JOptionPane.YES_NO_OPTION,
              JOptionPane.WARNING_MESSAGE,
              null,
              options,
              options[1]);
          if (choice == JOptionPane.YES_OPTION) {
            
            try {
              // BdD and Model
              Parameter pParam = ProjectData.getCurrentProject().getParameter(paramName);
              ProjectData.delParamInBddAndModel(pParam);
                   
              // IHM
              //Suppression du param?tre des tests et action de tests (si manuel)
              for (int j = 0; j < testsOfParam.size(); j++) {
                Test pTest = (Test)testsOfParam.get(j);
                // Si le test courant est trait?, on nettoie la table des param?tres
                if (DataModel.getCurrentTest() != null && DataModel.getCurrentTest().equals(pTest)) {
                    int rowIndex = DataModel.getTestParameterTableModel().findRow(paramName);
                    if (rowIndex != -1) {
                      DataModel.getTestParameterTableModel().removeData(sorter.modelIndex(rowIndex));
                    }
                }
 
                upadateActionOfParameterView(pTest, paramName);
                //Suppression en cascade dans l'arbre des campagnes
                for (int k = 0; k < concernedCampaign.size(); k++) {
                  Campaign campaign = (Campaign)concernedCampaign.get(k);
                  
                  DefaultMutableTreeNode testNodeInCampaignTree = SalomeTMF.getCampaignDynamicTree().findRemoveTestNodeInCampagneTree(pTest.getName(), pTest.getTestList().getName(),pTest.getTestList().getFamily().getName(),campaign.getName() ,false);
                  DefaultMutableTreeNode testListParent = (DefaultMutableTreeNode)testNodeInCampaignTree.getParent();
                  SalomeTMF.getCampaignDynamicTree().removeNode(testNodeInCampaignTree);
                  if (testListParent.getChildCount() == 0) {
                    DefaultMutableTreeNode familyParent = (DefaultMutableTreeNode)testListParent.getParent();
                    SalomeTMF.getCampaignDynamicTree().removeNode(testListParent);
                    //DataModel.deleteTestListFromCampaign((TestList)testListParent.getUserObject(),campaign);
                    if (familyParent.getChildCount() == 0) {
                      SalomeTMF.getCampaignDynamicTree().removeNode(familyParent);
                      //DataModel.deleteFamilyFromCampaign((Family)familyParent.getUserObject(), campaign);
                    }
                  }
                  //Si la campagne traite est la campagne courant, nettoyage de la table des r?sultats d'ex?cutions
                    if (DataModel.getCurrentCampaign() != null && DataModel.getCurrentCampaign().equals(campaign) ) {  
                        DataModel.getExecutionResultTableModel().clearTable();
                    }
                }
              }
              //DataModel.getParameterTableModel().removeData(selectedRowIndex);
              DataModel.getParameterTableModel().removeData(sorter.modelIndex(selectedRowIndex));
              
              
            } catch (Exception exception) {
              Tools.ihmExceptionView(exception.toString());
            }
          }
          
          
        } else {
          Object[] options = {Language.getInstance().getText("Oui"), Language.getInstance().getText("Non")};
          int choice = -1;
          choice = JOptionPane.showOptionDialog(ParameterView.this,
              //"Etes vous s?r de vouloir supprimer le param?tre <" +(String)DataModel.getParameterTableModel().getValueAt(selectedRowIndex, 0) + "> du projet ?",
              Language.getInstance().getText("Etes_vous_sr_de_vouloir_supprimer_le_paramtre_<") +(String)sorter.getValueAt(selectedRowIndex, 0) + Language.getInstance().getText(">_du_projet_?"),
              Language.getInstance().getText("Attention_!"),
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              options[1]);
          if (choice == JOptionPane.YES_OPTION) {
            
            try {
              // BdD
              Parameter pParam = ProjectData.getCurrentProject().getParameter(paramName);
              ProjectData.delParamInBddAndModel(pParam);
              //DataModel.getCurrentProject().getParameter(paramName).deleteFromDB();
              
              // IHM
              DataModel.getParameterTableModel().removeData(sorter.modelIndex(selectedRowIndex));
              //DataModel.getCurrentProject().removeParameter(paramName);
              
            } catch (Exception exception) {
              Tools.ihmExceptionView(exception.toString());
            }
          }
        }
      }
    }
    
    
    
    public void parametersTablevalueChanged(ListSelectionEvent e) {
      
      if (e.getValueIsAdjusting())
        return;
      
      int nbOfSelectedRows = parametersTable.getSelectedRowCount();
      int selectedRow = parametersTable.getSelectedRow();
      if (selectedRow != -1) {
        if (nbOfSelectedRows != 1) {
          if (usingFonctionEnable) {
            if (AdminProject.canDeleteTest()) deleteParameterButton.setEnabled(true);
          } else {
            if (AdminProject.canDeleteCamp()) deleteParameterButton.setEnabled(true);
          }
          modifyParameterButton.setEnabled(false);
          
        } else {
          if (usingFonctionEnable) {
            if (AdminProject.canUpdateTest()) modifyParameterButton.setEnabled(true);
            if (AdminProject.canDeleteTest()) deleteParameterButton.setEnabled(true);
          } else {
            if (AdminProject.canUpdateCamp() || AdminProject.canExecutCamp()) modifyParameterButton.setEnabled(true);
            if (AdminProject.canDeleteCamp()) deleteParameterButton.setEnabled(true);
          }
        }
      } else {
        deleteParameterButton.setEnabled(false);
        modifyParameterButton.setEnabled(false);
      }
      
    }
    
} // Fin de la classe ManualParameterView
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.