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.Cursor;
0028: import java.awt.Dimension;
0029: import java.awt.GridLayout;
0030: import java.awt.event.ActionEvent;
0031: import java.awt.event.ActionListener;
0032: import java.awt.event.MouseAdapter;
0033: import java.awt.event.MouseEvent;
0034: import java.io.File;
0035: import java.io.FileNotFoundException;
0036: import java.sql.Date;
0037: import java.util.ArrayList;
0038: import java.util.Collection;
0039: import java.util.HashMap;
0040: import java.util.Hashtable;
0041: import java.util.Iterator;
0042: import java.util.Set;
0043: import java.util.Vector;
0044:
0045: import javax.swing.BorderFactory;
0046: import javax.swing.JButton;
0047: import javax.swing.JMenu;
0048: import javax.swing.JMenuBar;
0049: import javax.swing.JMenuItem;
0050: import javax.swing.JOptionPane;
0051: import javax.swing.JPanel;
0052: import javax.swing.JScrollPane;
0053: import javax.swing.JTable;
0054: import javax.swing.ListSelectionModel;
0055: import javax.swing.event.ListSelectionEvent;
0056: import javax.swing.event.ListSelectionListener;
0057:
0058: import org.java.plugin.Extension;
0059: import org.objectweb.salome_tmf.api.Api;
0060: import org.objectweb.salome_tmf.api.api2ihm.AdminProject;
0061: import org.objectweb.salome_tmf.data.Attachment;
0062: import org.objectweb.salome_tmf.data.Campaign;
0063: import org.objectweb.salome_tmf.data.CampaignData;
0064: import org.objectweb.salome_tmf.data.ConnectionData;
0065: import org.objectweb.salome_tmf.data.Environment;
0066: import org.objectweb.salome_tmf.data.Execution;
0067: import org.objectweb.salome_tmf.data.FileAttachment;
0068: import org.objectweb.salome_tmf.data.Parameter;
0069: import org.objectweb.salome_tmf.data.ProjectData;
0070: import org.objectweb.salome_tmf.data.Script;
0071: import org.objectweb.salome_tmf.data.UrlAttachment;
0072: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
0073: import org.objectweb.salome_tmf.ihm.languages.Language;
0074: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
0075: import org.objectweb.salome_tmf.ihm.models.TableSorter;
0076: import org.objectweb.salome_tmf.ihm.tools.Tools;
0077: import org.objectweb.salome_tmf.plugins.core.ScriptEngine;
0078:
0079: /**
0080: * Classe qui d?finit la vue pour g?rer les environnements
0081: * @author teaml039
0082: * @version : 0.1
0083: */
0084: public class EnvironmentView extends JPanel implements IHMConstants,
0085: ActionListener {
0086:
0087: /**
0088: * Bouton pour ajouter un environnement
0089: */
0090: static JButton addButton;
0091:
0092: /**
0093: * Bouton pour supprimer un environnement
0094: */
0095: static JButton deleteButton;
0096:
0097: /**
0098: * Bouton pour modifier un environnement
0099: */
0100: static JButton modifyButton;
0101:
0102: /**
0103: * Bouton pour visualiser des bugs
0104: */
0105: //JButton showBugButton;
0106: /**
0107: * Mod?le de la table des environnement
0108: */
0109: MyTableModel environmentTableModel;
0110: TableSorter sorter;
0111: /**
0112: * Table des environnements
0113: */
0114: JTable environmentTable;
0115:
0116: /**
0117: * Mod?le de s?lection pour la table des environnements
0118: */
0119: ListSelectionModel rowSM;
0120:
0121: //static JButton modifyScriptButton;
0122: //static JButton commitButton;
0123:
0124: static JMenuBar scriptMenuBar;
0125: static JMenu scriptMenu;
0126: static JMenuItem modifyScriptItem;
0127: static JMenuItem actualItem;
0128: static JMenuItem setUpEngineItem;
0129:
0130: File importFile;
0131:
0132: HashMap modifyScriptList;
0133:
0134: /**************************************************************************/
0135: /** CONSTRUCTEUR ***/
0136: /**************************************************************************/
0137:
0138: /**
0139: * Constructeur de la vue
0140: */
0141: public EnvironmentView() {
0142: addButton = new JButton(Language.getInstance().getText(
0143: "Ajouter"));
0144: deleteButton = new JButton(Language.getInstance().getText(
0145: "Supprimer"));
0146: modifyButton = new JButton(Language.getInstance().getText(
0147: "Modifier"));
0148:
0149: environmentTable = new JTable();
0150: environmentTableModel = new MyTableModel();
0151: DataModel.setEnvironmentTableModel(environmentTableModel);
0152:
0153: addButton.setToolTipText(Language.getInstance().getText(
0154: "Ajouter_un_nouvel_environnement"));
0155: addButton.addActionListener(this );
0156:
0157: modifyButton.setToolTipText(Language.getInstance().getText(
0158: "Modifier_un_environnement"));
0159: modifyButton.setEnabled(false);
0160: modifyButton.addActionListener(this );
0161:
0162: deleteButton.setToolTipText(Language.getInstance().getText(
0163: "Supprimer_un_environnement"));
0164: deleteButton.setEnabled(false);
0165: deleteButton.addActionListener(this );
0166:
0167: scriptMenu = new JMenu(Language.getInstance().getText("Script"));
0168: modifyScriptItem = new JMenuItem(Language.getInstance()
0169: .getText("Modifier_le_Script"));
0170: modifyScriptItem.addActionListener(this );
0171: modifyScriptItem.setEnabled(false);
0172:
0173: actualItem = new JMenuItem(Language.getInstance().getText(
0174: "Actualiser_le_Script"));
0175: actualItem.addActionListener(this );
0176: actualItem.setEnabled(false);
0177:
0178: setUpEngineItem = new JMenuItem("SetUp Script Engine");
0179: setUpEngineItem.addActionListener(this );
0180: setUpEngineItem.setEnabled(false);
0181:
0182: scriptMenu.add(modifyScriptItem);
0183: scriptMenu.add(actualItem);
0184: scriptMenu.add(setUpEngineItem);
0185: scriptMenuBar = new JMenuBar();
0186: scriptMenuBar.add(scriptMenu);
0187:
0188: // Construction de la table
0189: environmentTableModel.addColumnNameAndColumn(Language
0190: .getInstance().getText("Nom"));
0191: environmentTableModel.addColumnNameAndColumn(Language
0192: .getInstance().getText("Script"));
0193: environmentTableModel.addColumnNameAndColumn(Language
0194: .getInstance().getText("Paramètres"));
0195: environmentTableModel.addColumnNameAndColumn(Language
0196: .getInstance().getText("Description"));
0197:
0198: sorter = new TableSorter(environmentTableModel);
0199: environmentTable.setModel(sorter);
0200: sorter.setTableHeader(environmentTable.getTableHeader());
0201:
0202: environmentTable
0203: .setPreferredScrollableViewportSize(new Dimension(700,
0204: 350));
0205: environmentTable
0206: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0207:
0208: // Gestion des s?lection dans la table
0209: rowSM = environmentTable.getSelectionModel();
0210: rowSM.addListSelectionListener(new ListSelectionListener() {
0211: public void valueChanged(ListSelectionEvent e) {
0212: if (e.getValueIsAdjusting())
0213: return;
0214:
0215: int nbOfSelectedRows = environmentTable
0216: .getSelectedRowCount();
0217: int selectedRow = environmentTable.getSelectedRow();
0218: if (selectedRow != -1) {
0219: if (nbOfSelectedRows != 1) {
0220: if (AdminProject.canExecutCamp())
0221: deleteButton.setEnabled(true);
0222: modifyButton.setEnabled(false);
0223: /*
0224: modifyScriptButton.setEnabled(false);
0225: commitButton.setEnabled(false);
0226: */
0227: actualItem.setEnabled(false);
0228: modifyScriptItem.setEnabled(false);
0229: setUpEngineItem.setEnabled(false);
0230: } else {
0231: //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0232: Environment env = ProjectData
0233: .getCurrentProject().getEnvironment(
0234: (String) sorter.getValueAt(
0235: selectedRow, 0));
0236: if (AdminProject.canUpdateCamp()
0237: || AdminProject.canExecutCamp())
0238: modifyButton.setEnabled(true);
0239: if (AdminProject.canExecutCamp())
0240: deleteButton.setEnabled(true);
0241: if ((AdminProject.canUpdateCamp() || AdminProject
0242: .canExecutCamp())
0243: && env.getInitScript() != null) {
0244: //modifyScriptButton.setEnabled(true);
0245: modifyScriptItem.setEnabled(true);
0246: setUpEngineItem.setEnabled(true);
0247: } else {
0248: //modifyScriptButton.setEnabled(false);
0249: modifyScriptItem.setEnabled(false);
0250: setUpEngineItem.setEnabled(false);
0251: }
0252:
0253: if (ConnectionData.isConnected()
0254: && AdminProject.canUpdateCamp()
0255: && isCommitable((String) sorter
0256: .getValueAt(selectedRow, 0))) {
0257: //commitButton.setEnabled(true);
0258: actualItem.setEnabled(true);
0259:
0260: } else {
0261: //commitButton.setEnabled(false);
0262: actualItem.setEnabled(false);
0263:
0264: }
0265: }
0266:
0267: } else {
0268: //showBugButton.setEnabled(false);
0269: deleteButton.setEnabled(false);
0270: modifyButton.setEnabled(false);
0271: //modifyScriptButton.setEnabled(false);
0272: //commitButton.setEnabled(false);
0273:
0274: actualItem.setEnabled(false);
0275: modifyScriptItem.setEnabled(false);
0276: setUpEngineItem.setEnabled(false);
0277: }
0278: scriptMenu.setEnabled(actualItem.isEnabled()
0279: || setUpEngineItem.isEnabled()
0280: || modifyScriptItem.isEnabled());
0281: }
0282: });
0283:
0284: // Mapping entre objets graphiques et constantes
0285: SalomeTMF.addToUIComponentsMap(
0286: UICompCst.DATA_MANAGEMENT_ENV_TABLE, environmentTable);
0287: // Add this component as static component
0288: UICompCst.staticUIComps
0289: .add(UICompCst.DATA_MANAGEMENT_ENV_TABLE);
0290:
0291: JScrollPane environmentTableScrollPane = new JScrollPane(
0292: environmentTable);
0293:
0294: //JPanel buttonsPanel = new JPanel();
0295: JPanel buttonsPanel = new JPanel(new GridLayout(1, 4));
0296: buttonsPanel.add(addButton);
0297: buttonsPanel.add(modifyButton);
0298: buttonsPanel.add(deleteButton);
0299:
0300: buttonsPanel.add(scriptMenuBar);
0301: //buttonsPanel.add(modifyScriptButton);
0302: //buttonsPanel.add(commitButton);
0303: //buttonsPanel.add(showBugButton);
0304:
0305: // Mapping entre objets graphiques et constantes
0306: SalomeTMF.addToUIComponentsMap(
0307: UICompCst.DATA_MANAGEMENT_ENV_BUTTONS_PANEL,
0308: buttonsPanel);
0309: // Add this component as static component
0310: UICompCst.staticUIComps
0311: .add(UICompCst.DATA_MANAGEMENT_ENV_BUTTONS_PANEL);
0312:
0313: buttonsPanel.setBorder(BorderFactory.createRaisedBevelBorder());
0314:
0315: environmentTable.addMouseListener(new MouseAdapter() {
0316: public void mousePressed(MouseEvent e) {
0317: if (e.getClickCount() > 1) {
0318: if (AdminProject.canCreateCamp()
0319: || AdminProject.canExecutCamp())
0320: modifyEnvironment();
0321: }
0322: }
0323: });
0324:
0325: initData();
0326:
0327: this .setLayout(new BorderLayout());
0328: this .add(BorderLayout.NORTH, buttonsPanel);
0329: this .add(BorderLayout.CENTER, environmentTableScrollPane);
0330:
0331: } // Fin du constructeur EnvironmentView/0
0332:
0333: /**************************************************************************/
0334: /** METHODES PUBLIQUES ***/
0335: /**************************************************************************/
0336:
0337: /**
0338: * M?thode permettant de modifier les environnements
0339: */
0340: private void modifyEnvironment() {
0341: int selectedRow = environmentTable.getSelectedRow();
0342: if (selectedRow != -1) {
0343: //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0344: Environment env = ProjectData.getCurrentProject()
0345: .getEnvironment(
0346: (String) sorter.getValueAt(selectedRow, 0));
0347: String oldEnvName = env.getName();
0348: Script oldInitScript = env.getInitScript();
0349: Hashtable oldParamTable = (Hashtable) env
0350: .getParametersHashTable().clone();
0351: String oldDescription = env.getDescription();
0352: HashMap oldAttachMap = new HashMap();
0353: Set keySet = env.getAttachmentMap().keySet();
0354: for (Iterator iter = keySet.iterator(); iter.hasNext();) {
0355: Object elem = iter.next();
0356: oldAttachMap
0357: .put(elem, env.getAttachmentMap().get(elem));
0358: }
0359:
0360: AskNewEnvironment askNewEnvironment = new AskNewEnvironment(
0361: env);
0362: if (askNewEnvironment.getEnvironment() != null) {
0363: int transNumber = -1;
0364: try {
0365: transNumber = Api
0366: .beginTransaction(Api.UPDATE_ENVIRONMENT);
0367: Environment environment = askNewEnvironment
0368: .getEnvironment();
0369: environment.updateInBddAndModel(environment
0370: .getName(), environment.getDescription());
0371: if (askNewEnvironment.getEnvironment()
0372: .getInitScript() != null) {
0373: if (!askNewEnvironment.getEnvironment()
0374: .getInitScript().equals(oldInitScript)) {
0375: if (oldInitScript != null) {
0376: askNewEnvironment
0377: .getEnvironment()
0378: .deleteScriptFromDB(
0379: oldInitScript.getName());
0380: }
0381: Script script = environment.getInitScript();
0382: //environment.addScript2DB(script, askNewEnvironment.getScriptFile());
0383: environment.addScript2BddAndModel(script,
0384: askNewEnvironment.getScriptFile());
0385: }
0386: } else if (oldInitScript != null) {
0387: askNewEnvironment.getEnvironment()
0388: .deleteScriptFromDB(
0389: oldInitScript.getName());
0390: }
0391: Set keysSet = askNewEnvironment.getEnvironment()
0392: .getParametersHashTable().keySet();
0393: for (Iterator iter = keysSet.iterator(); iter
0394: .hasNext();) {
0395: Parameter param = (Parameter) iter.next();
0396: //askNewEnvironment.getEnvironment().updateParamValueInDB(param);
0397: askNewEnvironment
0398: .getEnvironment()
0399: .updateParamValueInBddAndModel(
0400: param,
0401: (String) askNewEnvironment
0402: .getEnvironment()
0403: .getParametersHashTable()
0404: .get(param));
0405: }
0406: // PARAMETRES
0407:
0408: Vector oldParamsVector = ConnectionData
0409: .getAdminProjectSelect().getEnvParamsName(
0410: askNewEnvironment.getEnvironment()
0411: .getName());
0412: Set attachValues = askNewEnvironment
0413: .getEnvironment().getParametersHashTable()
0414: .keySet();
0415: for (Iterator iter = attachValues.iterator(); iter
0416: .hasNext();) {
0417: Parameter param = (Parameter) iter.next();
0418: if (!oldParamsVector.contains(param.getName())) {
0419: //environment.addParamValue2DB(param);
0420: environment.addParamValueInBddAndModel(
0421: param, environment
0422: .getParameterValue(param));
0423: }
0424: oldParamTable.remove(param);
0425: }
0426: attachValues = oldParamTable.keySet();
0427: for (Iterator iter = attachValues.iterator(); iter
0428: .hasNext();) {
0429: Parameter param = (Parameter) iter.next();
0430: if (oldParamsVector.contains(param.getName())) {
0431: askNewEnvironment.getEnvironment()
0432: .deleteParamFromEnvInDB(
0433: param.getIdBdd());
0434: }
0435: }
0436:
0437: // ATTACHEMENTS
0438: // Liste des anciens fichiers attach?s
0439: Vector oldFileAttachNamesVector = environment
0440: .getAttachFilesFromDB();
0441: // Liste des anciennes urls attach?es
0442: Vector oldUrlAttachVector = environment
0443: .getAttachUrlsFromDB();
0444: Collection attachedValues = environment
0445: .getAttachmentMap().values();
0446: for (Iterator iter = attachedValues.iterator(); iter
0447: .hasNext();) {
0448: Attachment attach = (Attachment) iter.next();
0449: //environment.addAttachInBddAndModel(attach);
0450: if (attach instanceof FileAttachment) {
0451: if (!oldFileAttachNamesVector
0452: .contains(attach.getName())) {
0453: environment
0454: .addAttachFile2DB((FileAttachment) attach);
0455: }
0456: } else {
0457: if (!oldUrlAttachVector.contains(attach
0458: .getName())) {
0459: environment
0460: .addAttachUrl2DB((UrlAttachment) attach);
0461:
0462: }
0463: }
0464: oldAttachMap.remove(attach.getName());
0465: }
0466: attachedValues = oldAttachMap.values();
0467: for (Iterator iter = attachedValues.iterator(); iter
0468: .hasNext();) {
0469: Attachment attach = (Attachment) iter.next();
0470: if ((oldFileAttachNamesVector.contains(attach
0471: .getName()))
0472: || (oldUrlAttachVector.contains(attach
0473: .getName())))
0474: environment.deleteAttachFromEnvInDB(attach
0475: .getIdBdd());
0476:
0477: }
0478:
0479: Api.commitTrans(transNumber);
0480:
0481: } catch (Exception exception) {
0482: Api.forceRollBackTrans(transNumber);
0483: env.setInitScript(oldInitScript);
0484: env.setParametersHashTable(oldParamTable);
0485: env.setName(oldEnvName);
0486: env.setDescription(oldDescription);
0487: env.setAttachmentMap(oldAttachMap);
0488: Tools.ihmExceptionView(exception.toString());
0489: }
0490:
0491: } else {
0492: env.setInitScript(oldInitScript);
0493: env.setParametersHashTable(oldParamTable);
0494: env.setName(oldEnvName);
0495: env.setDescription(oldDescription);
0496: env.setAttachmentMap(oldAttachMap);
0497: }
0498: //environmentTableModel.setValueAt(env.getName(), selectedRow, 0);
0499: sorter.setValueAt(env.getName(), selectedRow, 0);
0500: if (env.getInitScript() == null) {
0501: //environmentTableModel.setValueAt("", selectedRow, 1);
0502: sorter.setValueAt("", selectedRow, 1);
0503: } else {
0504: sorter.setValueAt(env.getInitScript().getName(),
0505: selectedRow, 1);
0506: modifyScriptItem.setEnabled(true);
0507: setUpEngineItem.setEnabled(true);
0508: modifyScriptList.put(env, new Boolean(true));
0509:
0510: }
0511: sorter.setValueAt(env.getParametersHashTable(),
0512: selectedRow, 2);
0513: sorter.setValueAt(env.getDescription(), selectedRow, 3);
0514:
0515: }
0516: scriptMenu.setEnabled(actualItem.isEnabled()
0517: || setUpEngineItem.isEnabled()
0518: || modifyScriptItem.isEnabled());
0519: } // Fin de la m?thode
0520:
0521: private void initData() {
0522: modifyScriptList = new HashMap();
0523: for (int i = 0; i < environmentTableModel.getRowCount(); i++) {
0524: //modifyScriptList.put(environmentTableModel.getValueAt(i,0), new Boolean(false));
0525: modifyScriptList.put(sorter.getValueAt(i, 0), new Boolean(
0526: false));
0527: }
0528: }
0529:
0530: private boolean isCommitable(String envName) {
0531: Environment env = ProjectData.getCurrentProject()
0532: .getEnvironment(envName);
0533: Boolean bool = (Boolean) modifyScriptList.get(env);
0534: if (bool == null) {
0535: return false;
0536: }
0537: return bool.booleanValue();
0538: }
0539:
0540: /**
0541: * M?thode qui g?re les permissions sur la vue
0542: */
0543: public static void giveAccessToIhmEnvironmentView() {
0544: if (!AdminProject.canExecutCamp()) {
0545: deleteButton.setEnabled(false);
0546: }
0547: if (!AdminProject.canCreateCamp()
0548: && !AdminProject.canExecutCamp()) {
0549: addButton.setEnabled(false);
0550: }
0551: if (!AdminProject.canUpdateCamp()
0552: && !AdminProject.canExecutCamp()) {
0553: modifyButton.setEnabled(false);
0554: //modifyScriptButton.setEnabled(false);
0555: //commitButton.setEnabled(false);
0556:
0557: actualItem.setEnabled(false);
0558: modifyScriptItem.setEnabled(false);
0559: setUpEngineItem.setEnabled(true);
0560: }
0561: scriptMenu.setEnabled(actualItem.isEnabled()
0562: || setUpEngineItem.isEnabled()
0563: || modifyScriptItem.isEnabled());
0564: } // Fin de la m?thode giveAccessToIhmEnvironmentView/0
0565:
0566: public void actionPerformed(ActionEvent e) {
0567: Object source = e.getSource();
0568: if (source.equals(addButton)) {
0569: addPerformed(e);
0570: } else if (source.equals(modifyButton)) {
0571: modifyPerformed(e);
0572: } else if (source.equals(deleteButton)) {
0573: deletePerformed(e);
0574: } else if (source.equals(actualItem)) {
0575: commitScriptPerformed(e);
0576: } else if (source.equals(modifyScriptItem)) {
0577: modifyScriptPerformed(e);
0578: } else if (source.equals(setUpEngineItem)) {
0579: setUpEnginePerformed(e);
0580: }
0581: }
0582:
0583: public void setUpEnginePerformed(ActionEvent e) {
0584: int selectedRow = environmentTable.getSelectedRow();
0585: if (selectedRow != -1) {
0586: //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0587: Environment env = ProjectData.getCurrentProject()
0588: .getEnvironment(
0589: (String) sorter.getValueAt(selectedRow, 0));
0590: if (env == null) {
0591: JOptionPane
0592: .showMessageDialog(
0593: EnvironmentView.this ,
0594: Language
0595: .getInstance()
0596: .getText(
0597: "Impossible_de_récupérer_l'environement_sélectionné."),
0598: Language.getInstance().getText(
0599: "Erreur_!"),
0600: JOptionPane.ERROR_MESSAGE);
0601: return;
0602: }
0603:
0604: try {
0605: Script pScript = null;
0606: //int plugScriptType;
0607: pScript = env.getInitScript();
0608: if (pScript == null) {
0609: JOptionPane
0610: .showMessageDialog(
0611: EnvironmentView.this ,
0612: Language
0613: .getInstance()
0614: .getText(
0615: "Impossible_de_récupérer_le_fichier_depuis_la_base."),
0616: Language.getInstance().getText(
0617: "Erreur_!"),
0618: JOptionPane.ERROR_MESSAGE);
0619: return;
0620: }
0621: //plugScriptType = ScriptEngine.ENV_SCRIPT;
0622: ScriptEngine pEngine = pScript.getScriptEngine(
0623: (Extension) SalomeTMF.associatedExtension
0624: .get(pScript.getScriptExtension()),
0625: SalomeTMF.urlSalome, SalomeTMF.jpf);
0626: if (pEngine != null) {
0627: String oldplugArg = pScript.getPlugArg();
0628: String plugArg = pEngine
0629: .modifyEngineAgument(oldplugArg);
0630:
0631: try {
0632: pScript.updatePlugArgInDB(plugArg);
0633: pScript.setPlugArg(plugArg);
0634: JOptionPane
0635: .showMessageDialog(
0636: EnvironmentView.this ,
0637: Language
0638: .getInstance()
0639: .getText(
0640: "Le_fichier_a_été_correctement_archivé."),
0641: Language.getInstance().getText(
0642: "Info..."),
0643: JOptionPane.INFORMATION_MESSAGE);
0644: } catch (Exception exception) {
0645: pScript.setPlugArg(oldplugArg);
0646: Tools.ihmExceptionView(exception.toString());
0647: }
0648:
0649: } else {
0650: JOptionPane
0651: .showMessageDialog(
0652: EnvironmentView.this ,
0653: Language
0654: .getInstance()
0655: .getText(
0656: "Impossible_d'initialiser_le_plugin_du_scrit"),
0657: Language.getInstance().getText(
0658: "Erreur_!"),
0659: JOptionPane.ERROR_MESSAGE);
0660: return;
0661: }
0662: } catch (Exception e1) {
0663: Tools.ihmExceptionView(e1.toString());
0664: }
0665: }
0666: }
0667:
0668: public void commitScriptPerformed(ActionEvent e) {
0669: if (ConnectionData.isConnected()) {
0670: int selectedRow = environmentTable.getSelectedRow();
0671: if (selectedRow != -1) {
0672: //Environment env = DataModel.getCurrentProject().getEnvironment((String)environmentTableModel.getValueAt(selectedRow,0));
0673: Environment env = ProjectData.getCurrentProject()
0674: .getEnvironment(
0675: (String) sorter.getValueAt(selectedRow,
0676: 0));
0677: int transNumber = -1;
0678: try {
0679: transNumber = Api
0680: .beginTransaction(Api.UPDATE_ATTACHMENT);
0681: Date date = new Date(importFile.lastModified());
0682: Script script = env.getInitScript();
0683: script.updateContentInDB(importFile
0684: .getAbsolutePath());
0685: script.updateDateInDB(date);
0686: script.updateLengthInDB(importFile.length());
0687:
0688: Api.commitTrans(transNumber);
0689: //if (Api.getException() == null || Api.getException().size() == 0) {
0690: modifyScriptList.put(env, new Boolean(false));
0691: //commitButton.setEnabled(false);
0692: actualItem.setEnabled(false);
0693: JOptionPane
0694: .showMessageDialog(
0695: EnvironmentView.this ,
0696: Language
0697: .getInstance()
0698: .getText(
0699: "Le_fichier_a_été_correctement_archivé."),
0700: Language.getInstance().getText(
0701: "Info..."),
0702: JOptionPane.INFORMATION_MESSAGE);
0703: //}
0704: } catch (FileNotFoundException fe) {
0705: Api.forceRollBackTrans(transNumber);
0706: JOptionPane
0707: .showMessageDialog(
0708: EnvironmentView.this ,
0709: Language
0710: .getInstance()
0711: .getText(
0712: "Impossible_de_trouver_le_fichier!\n_Vous_pouvez_l'importer_en_cliquant_sur_le_bouton_\"Modifier\""),
0713: Language.getInstance().getText(
0714: "Erreur_!"),
0715: JOptionPane.ERROR_MESSAGE);
0716: } catch (Exception exception) {
0717: Api.forceRollBackTrans(transNumber);
0718: Tools.ihmExceptionView(exception.toString());
0719: }
0720:
0721: }
0722: } else {
0723: JOptionPane
0724: .showMessageDialog(
0725: EnvironmentView.this ,
0726: Language
0727: .getInstance()
0728: .getText(
0729: "Impossible_!\nVous_n'êtes_pas_connecté_à_la_base."),
0730: Language.getInstance().getText("Erreur_!"),
0731: JOptionPane.ERROR_MESSAGE);
0732: }
0733: }
0734:
0735: public void modifyScriptPerformed(ActionEvent e) {
0736: int selectedRow = environmentTable.getSelectedRow();
0737: if (selectedRow != -1) {
0738: Environment env = ProjectData.getCurrentProject()
0739: .getEnvironment(
0740: (String) sorter.getValueAt(selectedRow, 0));
0741: if (env == null) {
0742: JOptionPane
0743: .showMessageDialog(
0744: EnvironmentView.this ,
0745: Language
0746: .getInstance()
0747: .getText(
0748: "Impossible_de_récupérer_l'environement_sélectionné."),
0749: Language.getInstance().getText(
0750: "Erreur_!"),
0751: JOptionPane.ERROR_MESSAGE);
0752: return;
0753: }
0754: try {
0755: Cursor c = new Cursor(Cursor.WAIT_CURSOR);
0756: EnvironmentView.this .setCursor(c);
0757: } catch (Exception ex) {
0758: ex.printStackTrace();
0759: }
0760: try {
0761: Script pScript = null;
0762: String plugSeting = "";
0763: Hashtable param = new Hashtable();
0764: param.put("salome_projectName", ProjectData
0765: .getCurrentProject().getName());
0766: param.put("salome_ProjectObject", ProjectData
0767: .getCurrentProject());
0768: param.put("salome_debug", new Boolean(true));
0769: param.put("salome_CampagneName", "");
0770: param.put("salome_ExecName", ""); // Add MM
0771: param.put("salome_environmentName", env.getName());
0772: param.put("salome_TestName", "");
0773: param.put("salome_SuiteTestName", "");
0774: param.put(Language.getInstance().getText(
0775: "salome_FamilyName"), "");
0776: param.put("testLog", "");
0777: param.put("Verdict", "");
0778: int plugScriptType;
0779: String fileScript = null;
0780: pScript = env.getInitScript();
0781: if (pScript == null) {
0782: JOptionPane
0783: .showMessageDialog(
0784: EnvironmentView.this ,
0785: Language
0786: .getInstance()
0787: .getText(
0788: "Impossible_de_récupérer_le_fichier_depuis_la_base."),
0789: Language.getInstance().getText(
0790: "Erreur_!"),
0791: JOptionPane.ERROR_MESSAGE);
0792: return;
0793: }
0794: plugScriptType = ScriptEngine.ENV_SCRIPT;
0795: plugSeting = pScript.getPlugArg();
0796: if (ConnectionData.isConnected()) {
0797: importFile = env.getEnvScriptFromDB(pScript
0798: .getName());
0799: fileScript = Tools.speedpurge(importFile
0800: .getAbsolutePath());
0801: } else {
0802: fileScript = Tools.speedpurge(pScript.getName());
0803: }
0804:
0805: if (fileScript != null) {
0806: ScriptEngine pEngine = pScript.getScriptEngine(
0807: (Extension) SalomeTMF.associatedExtension
0808: .get(pScript.getScriptExtension()),
0809: SalomeTMF.urlSalome, SalomeTMF.jpf);
0810: if (pEngine != null) {
0811: pEngine.editScript(fileScript, plugScriptType,
0812: pScript, param, plugSeting);
0813: } else {
0814: JOptionPane
0815: .showMessageDialog(
0816: EnvironmentView.this ,
0817: Language
0818: .getInstance()
0819: .getText(
0820: "Impossible_d'initialiser_le_plugin_du_scrit"),
0821: Language.getInstance().getText(
0822: "Erreur_!"),
0823: JOptionPane.ERROR_MESSAGE);
0824: }
0825: } else {
0826: JOptionPane
0827: .showMessageDialog(
0828: EnvironmentView.this ,
0829: Language
0830: .getInstance()
0831: .getText(
0832: "Impossible_de_récupérer_le_fichier_depuis_la_base."),
0833: Language.getInstance().getText(
0834: "Erreur_!"),
0835: JOptionPane.ERROR_MESSAGE);
0836: }
0837:
0838: } catch (Exception ex) {
0839: JOptionPane
0840: .showMessageDialog(
0841: EnvironmentView.this ,
0842: Language
0843: .getInstance()
0844: .getText(
0845: "Erreur_pour_lancer_l'éditeur_de_script_:_\n")
0846: + ex.getMessage(), Language
0847: .getInstance().getText(
0848: "Erreur_!"),
0849: JOptionPane.ERROR_MESSAGE);
0850: }
0851:
0852: try {
0853: Cursor c = new Cursor(Cursor.DEFAULT_CURSOR);
0854: EnvironmentView.this .setCursor(c);
0855: } catch (Exception ee) {
0856: ee.printStackTrace();
0857: }
0858: //commitButton.setEnabled(true);
0859: actualItem.setEnabled(true);
0860: modifyScriptList.put(env, new Boolean(true));
0861: }
0862: }
0863:
0864: public void deletePerformed(ActionEvent e) {
0865: int selectedRow = environmentTable.getSelectedRow();
0866: String message = "";
0867: String text = "";
0868: ArrayList concernedExecutions = CampaignData
0869: .getExecutionOfEnvironment((String) sorter.getValueAt(
0870: selectedRow, 0));
0871: if (concernedExecutions.size() > 0) {
0872: for (int i = 0; i < concernedExecutions.size(); i++) {
0873: message = message
0874: + "* "
0875: + ((Execution) concernedExecutions.get(i))
0876: .getCampagne().getName()
0877: + "/"
0878: + ((Execution) concernedExecutions.get(i))
0879: .getName() + "\n";
0880: }
0881:
0882: text = Language.getInstance().getText("L'environnement_<")
0883: + (String) sorter.getValueAt(selectedRow, 0)
0884: + Language.getInstance().getText(
0885: ">_est_utilisé_pour_les_exécutions_:\n")
0886: + message;
0887: text = text
0888: + Language
0889: .getInstance()
0890: .getText(
0891: "Sa_supression_entrainera_la_suppression_de_toutes_ces_exécutions.\n");
0892: }
0893: Object[] options = { Language.getInstance().getText("Oui"),
0894: Language.getInstance().getText("Non") };
0895: int choice = -1;
0896: //int actionCase = -1;
0897: choice = JOptionPane
0898: .showOptionDialog(
0899: EnvironmentView.this ,
0900: //text + "Etes vous s?r de vouloir supprimer l'environnement <" + (String)environmentTableModel.getValueAt(selectedRow,0) + "> ?",
0901: text
0902: + Language
0903: .getInstance()
0904: .getText(
0905: "Etes_vous_sûr_de_vouloir_supprimer_l'environnement_<")
0906: + (String) sorter.getValueAt(
0907: selectedRow, 0) + "> ?",
0908: Language.getInstance().getText("Attention_!"),
0909: JOptionPane.YES_NO_OPTION,
0910: JOptionPane.QUESTION_MESSAGE, null, options,
0911: options[1]);
0912: if (choice == JOptionPane.YES_OPTION) {
0913:
0914: try {
0915: // BdD
0916: Environment env = ProjectData.getCurrentProject()
0917: .getEnvironment(
0918: (String) sorter.getValueAt(selectedRow,
0919: 0));
0920: //env.deleteFromDB();
0921: ProjectData.getCurrentProject()
0922: .removeEnvironmentInBddandModel(env);
0923: // IHM
0924: //ProjectData.getCurrentProject().removeEnvironment((String)sorter.getValueAt(selectedRow,0));
0925: environmentTableModel.removeData(sorter
0926: .modelIndex(selectedRow));
0927: for (int i = 0; i < concernedExecutions.size(); i++) {
0928: Campaign camp = ((Execution) concernedExecutions
0929: .get(i)).getCampagne();
0930: camp
0931: .removeExecution((Execution) concernedExecutions
0932: .get(i));
0933: if (DataModel.getCurrentCampaign() != null
0934: && DataModel.getCurrentCampaign().equals(
0935: camp)) {
0936:
0937: DataModel
0938: .getExecutionTableModel()
0939: .removeRow(
0940: ((Execution) concernedExecutions
0941: .get(i)).getName());
0942:
0943: }
0944: }
0945:
0946: } catch (Exception exception) {
0947: Tools.ihmExceptionView(exception.toString());
0948: }
0949: }
0950: }
0951:
0952: public void modifyPerformed(ActionEvent e) {
0953: modifyEnvironment();
0954: }
0955:
0956: public void addPerformed(ActionEvent e) {
0957: // Ouverture de la fen?tre d'ajout
0958: AskNewEnvironment askNewEnvironment = new AskNewEnvironment();
0959: Environment env = askNewEnvironment.getEnvironment();
0960: // Si environnement est null = annuler
0961: if (env != null) {
0962: int transNumber = -1;
0963: try {
0964: // BdD
0965: transNumber = Api
0966: .beginTransaction(Api.INSERT_ENVIRONMENT);
0967: //env.add2DB();
0968: ProjectData.getCurrentProject()
0969: .addEnvironmentInBddAndModel(env);
0970:
0971: Set keysSet = env.getParametersHashTable().keySet();
0972: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
0973: Parameter param = (Parameter) iter.next();
0974: //env.addParamValue2DB(param);
0975: env.addParamValueInBddAndModel(param, env
0976: .getParameterValue(param));
0977: }
0978: if (askNewEnvironment.getScriptFile() != null) {
0979: //env.addScript2DB(env.getInitScript(),askNewEnvironment.getScriptFile());
0980: env.addScript2BddAndModel(env.getInitScript(),
0981: askNewEnvironment.getScriptFile());
0982: }
0983: Set keySet = env.getAttachmentMap().keySet();
0984: for (Iterator iter = keySet.iterator(); iter.hasNext();) {
0985: Attachment attach = (Attachment) env
0986: .getAttachmentMap().get(iter.next());
0987: //env.addAttachInBddAndModel(attach);
0988: if (attach instanceof FileAttachment) {
0989: env.addAttachFile2DB((FileAttachment) attach);
0990: } else {
0991: env.addAttachUrl2DB((UrlAttachment) attach);
0992: }
0993: }
0994: Api.commitTrans(transNumber);
0995:
0996: // IHM
0997: ArrayList data = new ArrayList();
0998: data.add(askNewEnvironment.getEnvironment().getName());
0999: String initScriptName = "";
1000: if (askNewEnvironment.getEnvironment().getInitScript() != null) {
1001: initScriptName = askNewEnvironment.getEnvironment()
1002: .getInitScript().getName();
1003: }
1004: data.add(initScriptName);
1005: data.add(askNewEnvironment.getEnvironment()
1006: .getParametersHashTable());
1007: data.add(askNewEnvironment.getEnvironment()
1008: .getDescription());
1009: environmentTableModel.addRow(data);
1010: //ProjectData.getCurrentProject().addEnvironment(askNewEnvironment.getEnvironment());
1011:
1012: } catch (Exception exception) {
1013: Api.forceRollBackTrans(transNumber);
1014: Tools.ihmExceptionView(exception.toString());
1015: }
1016: }
1017: }
1018:
1019: } // Fin de la classe EnvironmentView
|