001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.main;
025:
026: import java.awt.Color;
027: import java.awt.Container;
028: import java.awt.Dimension;
029: import java.awt.FlowLayout;
030: import java.awt.GraphicsConfiguration;
031: import java.awt.GraphicsDevice;
032: import java.awt.GraphicsEnvironment;
033: import java.awt.GridLayout;
034: import java.awt.Rectangle;
035: import java.awt.event.ActionEvent;
036: import java.awt.event.ActionListener;
037: import java.awt.event.WindowEvent;
038: import java.awt.event.WindowListener;
039: import java.io.File;
040: import java.util.ArrayList;
041: import java.util.Collection;
042: import java.util.Enumeration;
043: import java.util.Iterator;
044: import java.util.Set;
045: import java.util.StringTokenizer;
046:
047: import javax.swing.BorderFactory;
048: import javax.swing.Box;
049: import javax.swing.BoxLayout;
050: import javax.swing.JButton;
051: import javax.swing.JDialog;
052: import javax.swing.JFileChooser;
053: import javax.swing.JLabel;
054: import javax.swing.JOptionPane;
055: import javax.swing.JPanel;
056: import javax.swing.JScrollPane;
057: import javax.swing.JTabbedPane;
058: import javax.swing.JTable;
059: import javax.swing.JTextArea;
060: import javax.swing.JTextField;
061: import javax.swing.ListSelectionModel;
062: import javax.swing.event.ListSelectionEvent;
063: import javax.swing.event.ListSelectionListener;
064:
065: import org.java.plugin.Extension;
066: import org.objectweb.salome_tmf.api.ApiConstants;
067: import org.objectweb.salome_tmf.api.Permission;
068: import org.objectweb.salome_tmf.data.DataConstants;
069: import org.objectweb.salome_tmf.data.Environment;
070: import org.objectweb.salome_tmf.data.Parameter;
071: import org.objectweb.salome_tmf.data.Script;
072: import org.objectweb.salome_tmf.ihm.languages.Language;
073: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
074: import org.objectweb.salome_tmf.ihm.main.plugins.PluginsTools;
075: import org.objectweb.salome_tmf.ihm.models.MyTableModel;
076: import org.objectweb.salome_tmf.ihm.models.ScriptFileFilter;
077: import org.objectweb.salome_tmf.ihm.models.TableSorter;
078: import org.objectweb.salome_tmf.ihm.tools.Tools;
079: import org.objectweb.salome_tmf.plugins.UICompCst;
080:
081: public class AskNewEnvironment extends JDialog implements ApiConstants,
082: DataConstants, ActionListener, ListSelectionListener {
083:
084: /**
085: * La zone texte pour saisir le nom de l'environnement
086: */
087: JTextField nameField;
088:
089: /**
090: * La zone texte pour saisir la description
091: */
092: JTextArea descriptionArea;
093:
094: /**
095: * Le nouvel environnement
096: */
097: Environment environment;
098:
099: /**
100: * Zone de texte pour saisir le nom du script
101: */
102: JLabel scriptLabel;
103:
104: /**
105: * Table des paramètres
106: */
107: JTable parametersTable;
108:
109: /**
110: * Modèle de sélection pour la table des paramètres
111: */
112: ListSelectionModel rowSM;
113:
114: JButton deleteScriptButton;
115:
116: JButton modifyParameterButton;
117: JButton deleteParameter;
118:
119: JButton okButton;
120:
121: JButton cancelButton;
122:
123: private File scriptFile;
124:
125: private Script script;
126:
127: JButton addParameterButton;
128:
129: JButton addScriptFileButton;
130:
131: JButton useDefinedParameterButton;
132:
133: TableSorter sorter;
134:
135: boolean newFile = false;
136:
137: static ScriptFileFilter[] tabPlugScriptFileFilter = null;
138: static JFileChooser fileChooser = new JFileChooser();
139:
140: AttachmentView attachmentPanel;
141:
142: /**************************************************************************/
143: /** CONSTRUCTEUR ***/
144: /**************************************************************************/
145:
146: public AskNewEnvironment(Environment oldEnvironment) {
147: super (SalomeTMFContext.getInstance().ptrFrame, true);
148:
149: int t_x = 1024 - 100;
150: int t_y = 768 / 3 * 2 - 50;
151: int t_x2 = 1024;
152: int t_y2 = 768;
153: try {
154: GraphicsEnvironment ge = GraphicsEnvironment
155: .getLocalGraphicsEnvironment();
156: GraphicsDevice[] gs = ge.getScreenDevices();
157: GraphicsDevice gd = gs[0];
158: GraphicsConfiguration[] gc = gd.getConfigurations();
159: Rectangle r = gc[0].getBounds();
160: t_x = r.width - 100;
161: t_y = r.height / 3 * 2 - 50;
162: t_x2 = r.width;
163: t_y2 = r.height;
164: } catch (Exception E) {
165:
166: }
167:
168: nameField = new JTextField(10);
169: descriptionArea = new JTextArea(15, 40);
170: JLabel testNameLabel = new JLabel(Language.getInstance()
171: .getText("Nom_de_l'environnement_:_"));
172: scriptLabel = new JLabel(Language.getInstance().getText(
173: "Nom_du_script_:_"));
174: parametersTable = new JTable();
175: modifyParameterButton = new JButton(Language.getInstance()
176: .getText("Modifier"));
177: deleteParameter = new JButton(Language.getInstance().getText(
178: "Supprimer"));
179: deleteScriptButton = new JButton(Language.getInstance()
180: .getText("Supprimer"));
181:
182: JPanel giveName = new JPanel();
183: giveName.setLayout(new BoxLayout(giveName, BoxLayout.X_AXIS));
184: giveName.setBorder(BorderFactory.createEmptyBorder(0, 10, 10,
185: 10));
186: giveName.add(Box.createHorizontalGlue());
187: giveName.add(testNameLabel);
188: giveName.add(Box.createRigidArea(new Dimension(10, 0)));
189: giveName.add(nameField);
190:
191: JScrollPane descriptionScrollPane = new JScrollPane(
192: descriptionArea);
193: descriptionScrollPane.setBorder(BorderFactory
194: .createTitledBorder(BorderFactory
195: .createLineBorder(Color.BLACK), Language
196: .getInstance().getText("Description")));
197: descriptionScrollPane.setPreferredSize(new Dimension(100, 100));
198:
199: addScriptFileButton = new JButton(Language.getInstance()
200: .getText("Chercher..."));
201: addScriptFileButton.setToolTipText(Language.getInstance()
202: .getText("Chercher_le_fichier_de_script"));
203: addScriptFileButton.addActionListener(this );
204:
205: deleteScriptButton.setToolTipText(Language.getInstance()
206: .getText("Supprimer_le_fichier_de_script"));
207: deleteScriptButton.addActionListener(this );
208:
209: JPanel giveScriptNamePanel = new JPanel(new FlowLayout(
210: FlowLayout.LEFT));
211: giveScriptNamePanel.add(scriptLabel);
212:
213: JPanel scriptButtonPanel = new JPanel(new FlowLayout(
214: FlowLayout.LEFT));
215: scriptButtonPanel.add(addScriptFileButton);
216: scriptButtonPanel.add(deleteScriptButton);
217:
218: JPanel giveScriptPanel = new JPanel();
219: giveScriptPanel.setLayout(new BoxLayout(giveScriptPanel,
220: BoxLayout.Y_AXIS));
221: giveScriptPanel.add(giveScriptNamePanel);
222: giveScriptPanel.add(scriptButtonPanel);
223:
224: sorter = new TableSorter(DataModel
225: .getEnvironmentParameterTableModel());
226: parametersTable.setModel(sorter);
227: sorter.setTableHeader(parametersTable.getTableHeader());
228:
229: JScrollPane parametersScrollPane = new JScrollPane(
230: parametersTable);
231: parametersScrollPane.setPreferredSize(new Dimension(450, 100));
232:
233: addParameterButton = new JButton(Language.getInstance()
234: .getText("Nouveau"));
235: addParameterButton.setToolTipText(Language.getInstance()
236: .getText("Ajouter_un_nouveau_paramètre"));
237: addParameterButton.addActionListener(this );
238:
239: useDefinedParameterButton = new JButton(Language.getInstance()
240: .getText("Utiliser"));
241: useDefinedParameterButton.setToolTipText(Language.getInstance()
242: .getText("Utiliser_un_paramètre_existant"));
243: useDefinedParameterButton.addActionListener(this );
244:
245: modifyParameterButton.setToolTipText(Language.getInstance()
246: .getText("Modifier_un_paramètre"));
247: modifyParameterButton.setEnabled(false);
248: modifyParameterButton.addActionListener(this );
249:
250: deleteParameter.setToolTipText(Language.getInstance().getText(
251: "Supprimer_un_paramètre"));
252: deleteParameter.setEnabled(false);
253: deleteParameter.addActionListener(this );
254:
255: //JPanel attachButtonPanel = new JPanel();
256: //attachButtonPanel.setLayout(new BoxLayout(attachButtonPanel, BoxLayout.Y_AXIS));
257: JPanel attachButtonPanel = new JPanel(new GridLayout(4, 1));
258: attachButtonPanel.add(addParameterButton);
259: attachButtonPanel.add(useDefinedParameterButton);
260: attachButtonPanel.add(modifyParameterButton);
261: attachButtonPanel.add(deleteParameter);
262:
263: JPanel parameterPanel = new JPanel();
264: parameterPanel.setLayout(new BoxLayout(parameterPanel,
265: BoxLayout.X_AXIS));
266: parametersScrollPane.setPreferredSize(new Dimension(t_x - 50,
267: t_y / 3));
268: parameterPanel.add(parametersScrollPane);
269: attachButtonPanel.setMaximumSize(new Dimension(50, t_y / 3));
270: parameterPanel.add(attachButtonPanel);
271: parameterPanel.setBorder(BorderFactory.createTitledBorder(
272: BorderFactory.createLineBorder(Color.BLACK), Language
273: .getInstance().getText("Paramètres")));
274:
275: /*JPanel textPanel = new JPanel();
276: textPanel.setLayout(new BoxLayout(textPanel,BoxLayout.Y_AXIS));
277: textPanel.add(Box.createRigidArea(new Dimension(0,10)));
278: textPanel.add(giveName);
279: textPanel.add(Box.createRigidArea(new Dimension(0,10)));
280: textPanel.add(giveScriptPanel);
281: textPanel.add(Box.createRigidArea(new Dimension(1,30)));
282: textPanel.add(descriptionScrollPane);
283: textPanel.add(Box.createRigidArea(new Dimension(1,30)));
284: textPanel.add(parameterPanel);
285: */
286:
287: JPanel textPanel = new JPanel();
288: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
289: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
290: giveScriptPanel.setMaximumSize(new Dimension(t_x, 30));
291: textPanel.add(giveScriptPanel);
292: textPanel.add(Box.createRigidArea(new Dimension(1, 30)));
293: textPanel.add(descriptionScrollPane);
294:
295: //attachmentPanel = new AttachmentView(DataModel.getApplet(), ENVIRONMENT, ENVIRONMENT, oldEnvironment, SMALL_SIZE_FOR_ATTACH, null, null, null);
296: attachmentPanel = new AttachmentView(DataModel.getApplet(),
297: ENVIRONMENT, ENVIRONMENT, oldEnvironment,
298: SMALL_SIZE_FOR_ATTACH, this );
299: attachmentPanel.setBorder(BorderFactory.createTitledBorder(
300: BorderFactory.createLineBorder(Color.BLACK), Language
301: .getInstance().getText("Attachements")));
302: //textPanel.add(attachmentPanel);
303:
304: okButton = new JButton(Language.getInstance()
305: .getText("Valider"));
306: okButton.setToolTipText(Language.getInstance().getText(
307: "Valider"));
308: okButton.addActionListener(this );
309:
310: cancelButton = new JButton(Language.getInstance().getText(
311: "Annuler"));
312: cancelButton.setToolTipText(Language.getInstance().getText(
313: "Annuler"));
314: cancelButton.addActionListener(this );
315:
316: JPanel buttonPanel = new JPanel(new FlowLayout());
317: buttonPanel.add(okButton);
318: buttonPanel.add(cancelButton);
319:
320: //textPanel.add(buttonPanel);
321:
322: //Initialisation des données de la fenêtre
323: initData(oldEnvironment);
324:
325: /*
326: Container contentPaneFrame = this.getContentPane();
327: contentPaneFrame.add(textPanel, BorderLayout.CENTER);
328: */
329: /*
330: Container contentPane = this.getContentPane();
331: contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
332:
333: giveName.setMaximumSize(new Dimension(t_x2, 30));
334: contentPane.add(giveName);
335:
336: textPanel.setMaximumSize(new Dimension(t_x2, t_y2/3));
337: contentPane.add(textPanel);
338:
339: parameterPanel.setMaximumSize(new Dimension(t_x2, t_y2/3));
340: contentPane.add(parameterPanel);
341:
342: attachmentPanel.setMaximumSize(new Dimension(t_x2, t_y2/3));
343: contentPane.add(attachmentPanel);
344:
345: buttonPanel.setMaximumSize(new Dimension(t_x2, 40));
346: contentPane.add(buttonPanel);
347: */
348:
349: JTabbedPane pJTabbedPane = new JTabbedPane();
350: Container contentPane = this .getContentPane();
351: contentPane.setLayout(new BoxLayout(contentPane,
352: BoxLayout.Y_AXIS));
353: JPanel envDetail = new JPanel();
354: envDetail.setLayout(new BoxLayout(envDetail, BoxLayout.Y_AXIS));
355: giveName.setMaximumSize(new Dimension(t_x2, 30));
356: envDetail.add(giveName);
357: textPanel.setMaximumSize(new Dimension(t_x2, t_y2 / 3));
358: envDetail.add(textPanel);
359: parameterPanel.setMaximumSize(new Dimension(t_x2, t_y2 / 3));
360: envDetail.add(parameterPanel);
361:
362: attachmentPanel.setMaximumSize(new Dimension(t_x2, t_y2 / 3));
363:
364: pJTabbedPane.add(Language.getInstance()
365: .getText("Environnement"), envDetail);
366: pJTabbedPane.add(
367: Language.getInstance().getText("Attachements"),
368: attachmentPanel);
369:
370: buttonPanel.setMaximumSize(new Dimension(t_x2, 40));
371: contentPane.add(pJTabbedPane);
372: contentPane.add(buttonPanel);
373:
374: rowSM = parametersTable.getSelectionModel();
375: rowSM.addListSelectionListener(this );
376:
377: this .addWindowListener(new WindowListener() {
378: public void windowClosing(WindowEvent e) {
379: environment = null;
380: }
381:
382: public void windowDeiconified(WindowEvent e) {
383: }
384:
385: public void windowOpened(WindowEvent e) {
386: }
387:
388: public void windowActivated(WindowEvent e) {
389: }
390:
391: public void windowDeactivated(WindowEvent e) {
392: }
393:
394: public void windowClosed(WindowEvent e) {
395: }
396:
397: public void windowIconified(WindowEvent e) {
398: }
399: });
400:
401: giveAccessToIhm();
402:
403: if (oldEnvironment == null) {
404: this .setTitle(Language.getInstance().getText(
405: "Ajouter_un_environnement"));
406: } else {
407: this .setTitle(Language.getInstance().getText(
408: "Modifier_un_environnement"));
409: }
410: if (tabPlugScriptFileFilter == null) {
411: initTabPlugScriptFileFilter();
412: }
413:
414: // Mapping entre objets graphiques et constantes
415: SalomeTMFContext.getInstance().addToUIComponentsMap(
416: UICompCst.DATA_MANAGEMENT_NEW_ENV_WINDOW, this );
417: // Activation des plugins associés
418: PluginsTools
419: .activateAssociatedPlgs(UICompCst.DATA_MANAGEMENT_NEW_ENV_WINDOW);
420: //this.setLocation(200,20);
421: setSize(t_x, t_y);
422: //this.setLocation((t_x2-t_x)/2,50);
423: /*this.setLocationRelativeTo(this.getParent());
424: this.pack();
425: this.setVisible(true);**/
426: centerScreen();
427:
428: } // Fin du constructeur AskNewEnvironment/1
429:
430: void centerScreen() {
431: Dimension dim = getToolkit().getScreenSize();
432: this .pack();
433: Rectangle abounds = getBounds();
434: setLocation((dim.width - abounds.width) / 2,
435: (dim.height - abounds.height) / 2);
436: this .setVisible(true);
437: requestFocus();
438: }
439:
440: public AskNewEnvironment() {
441: this (null);
442: } // Fin du constructeur AskNewEnvironment/0
443:
444: private void initTabPlugScriptFileFilter() {
445: if (SalomeTMFContext.getInstance().associatedScriptEngine
446: .size() == 0) {
447: deleteScriptButton.setEnabled(false);
448: addScriptFileButton.setEnabled(false);
449: fileChooser = null;
450: return;
451: }
452: tabPlugScriptFileFilter = new ScriptFileFilter[SalomeTMFContext
453: .getInstance().associatedScriptEngine.size()];
454: Enumeration e = SalomeTMFContext.getInstance().associatedScriptEngine
455: .keys();
456: int i = 0;
457: while (e.hasMoreElements()) {
458: Extension ScriptExt = (Extension) e.nextElement();
459: String extID = ScriptExt.getId();
460: String extList = (String) SalomeTMFContext.getInstance().associatedScriptEngine
461: .get(ScriptExt);
462: StringTokenizer st = new StringTokenizer(extList, ",");
463: String[] tabExt = new String[st.countTokens()];
464: //Util.log("Add extension " + extID + ", with filter :" + extList);
465: int j = 0;
466: while (st.hasMoreTokens()) {
467: tabExt[j] = st.nextToken();
468: j++;
469: }
470: tabPlugScriptFileFilter[i] = new ScriptFileFilter(extID,
471: tabExt);
472: i++;
473: }
474: int tabFilterSize = tabPlugScriptFileFilter.length;
475: for (i = 0; i < tabFilterSize; i++) {
476: fileChooser
477: .addChoosableFileFilter(tabPlugScriptFileFilter[i]);
478: }
479: fileChooser.setAcceptAllFileFilterUsed(false);
480: }
481:
482: /**
483: *
484: * @return
485: */
486: public Environment getEnvironment() {
487: return environment;
488: } // Fin de la méthode getEnvironment/0
489:
490: /**
491: *
492: * @param oldEnvironment
493: */
494: private void initData(Environment oldEnvironment) {
495: if (oldEnvironment != null) {
496: environment = oldEnvironment;
497: nameField.setText(oldEnvironment.getNameFromModel());
498: if (oldEnvironment.getInitScriptFromModel() != null) {
499: scriptLabel.setText(Language.getInstance().getText(
500: "Nom_du_script_:_")
501: + oldEnvironment.getInitScriptFromModel()
502: .getNameFromModel());
503: }
504: script = oldEnvironment.getInitScriptFromModel();
505: descriptionArea.setText(oldEnvironment
506: .getDescriptionFromModel());
507: ((MyTableModel) ((TableSorter) parametersTable.getModel())
508: .getTableModel()).clearTable();
509: int i = 0;
510: Set keysSet = oldEnvironment
511: .getParametersHashTableFromModel().keySet();
512: for (Iterator iter = keysSet.iterator(); iter.hasNext();) {
513: Parameter param = (Parameter) iter.next();
514: ((MyTableModel) ((TableSorter) parametersTable
515: .getModel()).getTableModel()).addValueAt(param
516: .getNameFromModel(), i, 0);
517: ((MyTableModel) ((TableSorter) parametersTable
518: .getModel()).getTableModel()).addValueAt(
519: oldEnvironment
520: .getParameterValueFromModel(param), i,
521: 1);
522: ((MyTableModel) ((TableSorter) parametersTable
523: .getModel()).getTableModel()).addValueAt(param
524: .getDescriptionFromModel(), i, 2);
525: }
526: Collection col = oldEnvironment.getAttachmentMapFromModel()
527: .values();
528: DataModel.initAttachmentTable(col);
529: } else {
530: environment = new Environment("", "");
531: ((MyTableModel) ((TableSorter) parametersTable.getModel())
532: .getTableModel()).clearTable();
533: DataModel.getAttachmentTableModel().clearTable();
534: }
535: DataModel.setCurrentEnvironment(environment);
536: } // Fin de la méthode initData/1
537:
538: private void createAndQuit() {
539: environment.updateInModel(nameField.getText().trim(),
540: descriptionArea.getText());
541: environment.addScriptInModel(script);
542: //environment.getAttachmentMapFromModel().clear();
543: /*Collection values = attachmentPanel.getAttachmentMap().values();
544: for (Iterator iter = values.iterator(); iter.hasNext();) {
545: environment.addAttachementInModel((Attachment)iter.next());
546: }*/
547:
548: AskNewEnvironment.this .dispose();
549: }
550:
551: public File getScriptFile() {
552: return scriptFile;
553: }
554:
555: private void giveAccessToIhm() {
556: if (!Permission.canDeleteCamp()) {
557: deleteScriptButton.setEnabled(false);
558: deleteParameter.setEnabled(false);
559: }
560: if (!Permission.canCreateCamp()) {
561: addParameterButton.setEnabled(false);
562: addScriptFileButton.setEnabled(false);
563: useDefinedParameterButton.setEnabled(false);
564: }
565: if (!Permission.canUpdateCamp()) {
566: modifyParameterButton.setEnabled(false);
567: }
568: }
569:
570: public void actionPerformed(ActionEvent e) {
571: Object source = e.getSource();
572: if (source.equals(addScriptFileButton)) {
573: addScriptPerformed(e);
574: } else if (source.equals(deleteScriptButton)) {
575: deleteScriptPerformed(e);
576: } else if (source.equals(addParameterButton)) {
577: addParameterPerformed(e);
578: } else if (source.equals(useDefinedParameterButton)) {
579: useDefinedParameterPerformed(e);
580: } else if (source.equals(modifyParameterButton)) {
581: modifyParameterPerformed(e);
582: } else if (source.equals(deleteParameter)) {
583: deleteParameterPerformed(e);
584: } else if (source.equals(okButton)) {
585: okButtonPerformed(e);
586: } else if (source.equals(cancelButton)) {
587: cancelPerformed(e);
588: }
589: }
590:
591: public void addScriptPerformed(ActionEvent e) {
592: if (fileChooser == null) {
593: addScriptFileButton.setEnabled(false);
594: deleteScriptButton.setEnabled(false);
595: return;
596: }
597: fileChooser.setApproveButtonText(Language.getInstance()
598: .getText("Valider"));
599:
600: int returnVal = fileChooser
601: .showOpenDialog(AskNewEnvironment.this );
602: if (returnVal == JFileChooser.APPROVE_OPTION) {
603: ScriptFileFilter filter = (ScriptFileFilter) fileChooser
604: .getFileFilter();
605:
606: String scriptPlugIns = filter.getDescription();
607: scriptFile = fileChooser.getSelectedFile();
608: try {
609: if (!scriptFile.exists()) {
610: scriptFile.createNewFile();
611: newFile = true;
612: }
613: } catch (Exception ex) {
614: return;
615: }
616: scriptLabel.setText(Language.getInstance().getText(
617: "Nom_du_script_:_")
618: + scriptFile.getAbsolutePath());
619: script = new Script(scriptFile.getName(), "");
620: script.setLocalisation(scriptFile.getAbsolutePath());
621: script.setScriptExtensionInModel(scriptPlugIns);
622: script.updatePlugArgInModel("");
623: script.setTypeInModel(INIT_SCRIPT);
624: }
625: }
626:
627: public void deleteScriptPerformed(ActionEvent e) {
628: if (script != null) {
629: int choice = -1;
630: Object[] options = { Language.getInstance().getText("Oui"),
631: Language.getInstance().getText("Non") };
632: choice = SalomeTMFContext.getInstance().askQuestion(
633: Language.getInstance().getText(
634: "Supprimer_le_fichier_de_script")
635: + " : " + script.getNameFromModel() + " ?",
636: Language.getInstance().getText("Attention_!"),
637: JOptionPane.WARNING_MESSAGE, options);
638: if (choice != JOptionPane.YES_OPTION) {
639: return;
640: }
641: scriptLabel.setText(Language.getInstance().getText(
642: "Nom_du_script_:_"));
643: script = null;
644: }
645: }
646:
647: public void addParameterPerformed(ActionEvent e) {
648: AskNewParameter askNewParameter = new AskNewParameter(
649: environment);
650: if (askNewParameter.getParameter() != null
651: && askNewParameter.getParameter().getNameFromModel() != null
652: && askNewParameter.getParameter().getNameFromModel() != "") {
653:
654: try {
655: // BdD
656: DataModel.getCurrentProject().addParameterToDBAndModel(
657: askNewParameter.getParameter());
658: //askNewParameter.getParameter().add2DB();
659: // IHM
660: ArrayList data = new ArrayList();
661: data.add(askNewParameter.getParameter()
662: .getNameFromModel());
663: data.add(askNewParameter.getValue());
664: data.add(askNewParameter.getParameter()
665: .getDescriptionFromModel());
666: DataModel.getEnvironmentParameterTableModel().addRow(
667: data);
668: environment.addParameterValueInModel(askNewParameter
669: .getParameter(), askNewParameter.getValue());
670: //ProjectData.getCurrentProject().addParameter(askNewParameter.getParameter());
671: data.remove(1);
672: DataModel.getParameterTableModel().addRow(data);
673:
674: } catch (Exception exception) {
675: Tools.ihmExceptionView(exception);
676: }
677: }
678: }
679:
680: public void useDefinedParameterPerformed(ActionEvent e) {
681: UsingDefinedParameterView usingDefinedParameterView = new UsingDefinedParameterView(
682: true, true);
683: if (usingDefinedParameterView.getParameter() != null) {
684: if (!environment
685: .containsParameterInModel(usingDefinedParameterView
686: .getParameter())) {
687: ArrayList data = new ArrayList();
688: data.add(usingDefinedParameterView.getParameter()
689: .getNameFromModel());
690: data.add(usingDefinedParameterView.getValue());
691: data.add(usingDefinedParameterView.getParameter()
692: .getDescriptionFromModel());
693: DataModel.getEnvironmentParameterTableModel().addRow(
694: data);
695: environment.addParameterValueInModel(
696: usingDefinedParameterView.getParameter(),
697: usingDefinedParameterView.getValue());
698: } else {
699: JOptionPane
700: .showMessageDialog(
701: AskNewEnvironment.this ,
702: Language
703: .getInstance()
704: .getText(
705: "Ce_paramètre_est_déjà_présent_dans_votre_environnement_!"),
706: Language.getInstance().getText(
707: "Erreur_!"),
708: JOptionPane.ERROR_MESSAGE);
709: }
710: }
711: }
712:
713: public void modifyParameterPerformed(ActionEvent e) {
714: int selectedRow = parametersTable.getSelectedRow();
715: if (selectedRow != -1) {
716: //Parameter param = environment.getParameter((String)TestData.getEnvironmentParameterTableModel().getValueAt(selectedRow,0));
717: Parameter param = environment
718: .getParameterFromModel((String) sorter.getValueAt(
719: selectedRow, 0));
720: AskNewParameter askNewParameter = new AskNewParameter(
721: environment, param);
722: if (askNewParameter.getParameter() != null) {
723:
724: sorter.setValueAt(askNewParameter.getParameter()
725: .getNameFromModel(), selectedRow, 0);
726: sorter.setValueAt(askNewParameter.getValue(),
727: selectedRow, 1);
728: sorter.setValueAt(askNewParameter.getParameter()
729: .getDescriptionFromModel(), selectedRow, 2);
730: //environment.setNewValue(askNewParameter.getParameter(), askNewParameter.getValue());
731: environment.updateParamValueInModel(askNewParameter
732: .getParameter(), askNewParameter.getValue());
733: }
734: }
735: }
736:
737: public void deleteParameterPerformed(ActionEvent e) {
738: int[] selectedRows = parametersTable.getSelectedRows();
739: for (int i = selectedRows.length - 1; i >= 0; i--) {
740: //environment.removeParameter((String)sorter.getValueAt(selectedRows[i],0));
741: environment.deleteDefParameterInModel((String) sorter
742: .getValueAt(selectedRows[i], 0));
743: DataModel.getEnvironmentParameterTableModel().removeData(
744: sorter.modelIndex(selectedRows[i]));
745: }
746: }
747:
748: public void okButtonPerformed(ActionEvent e) {
749: if (!nameField.getText().trim().equals("")) {
750: if (!DataModel.getCurrentProject().containsEnvironment(
751: nameField.getText().trim())
752: && !nameField.getText().trim().equals(
753: DataModel.EMPTY_NAME)
754: && !Environment.isInBase(DataModel
755: .getCurrentProject(), nameField.getText()
756: .trim())) {
757: createAndQuit();
758: } else if (DataModel
759: .getCurrentProject()
760: .getEnvironmentFromModel(nameField.getText().trim()) != null
761: && DataModel.getCurrentProject()
762: .getEnvironmentFromModel(
763: nameField.getText().trim()).equals(
764: environment)) {
765: createAndQuit();
766: } else {
767: JOptionPane
768: .showMessageDialog(
769: AskNewEnvironment.this ,
770: Language
771: .getInstance()
772: .getText(
773: "Ce_nom_d'environnement_existe_déjà_!"),
774: Language.getInstance().getText(
775: "Erreur_!"),
776: JOptionPane.ERROR_MESSAGE);
777: }
778: } else {
779: JOptionPane
780: .showMessageDialog(
781: AskNewEnvironment.this ,
782: Language
783: .getInstance()
784: .getText(
785: "Il_faut_obligatoirement_donner_un_nom_à_l'environnement_!"),
786: Language.getInstance().getText(
787: "Attention_!"),
788: JOptionPane.WARNING_MESSAGE);
789: }
790:
791: }
792:
793: public void cancelPerformed(ActionEvent e) {
794: environment = null;
795: if (newFile)
796: scriptFile.delete();
797: AskNewEnvironment.this .dispose();
798: }
799:
800: public void valueChanged(ListSelectionEvent e) {
801: int nbOfSelectedRows = parametersTable.getSelectedRowCount();
802: int selectedRow = parametersTable.getSelectedRow();
803: if (selectedRow != -1) {
804: if (nbOfSelectedRows != 1) {
805: if (Permission.canDeleteCamp())
806: deleteParameter.setEnabled(true);
807: modifyParameterButton.setEnabled(false);
808: } else {
809: if (Permission.canUpdateCamp())
810: modifyParameterButton.setEnabled(true);
811: if (Permission.canDeleteCamp())
812: deleteParameter.setEnabled(true);
813: }
814: } else {
815: deleteParameter.setEnabled(false);
816: modifyParameterButton.setEnabled(false);
817: }
818:
819: }
820:
821: } // Fin de la classe AskNewEnvironment
|