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;
025:
026: import java.awt.BorderLayout;
027: import java.awt.Color;
028: import java.awt.Container;
029: import java.awt.Dimension;
030: import java.awt.FlowLayout;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033: import java.awt.event.WindowEvent;
034: import java.awt.event.WindowListener;
035:
036: import javax.swing.BorderFactory;
037: import javax.swing.Box;
038: import javax.swing.BoxLayout;
039: import javax.swing.JButton;
040: import javax.swing.JDialog;
041: import javax.swing.JLabel;
042: import javax.swing.JOptionPane;
043: import javax.swing.JPanel;
044: import javax.swing.JScrollPane;
045: import javax.swing.JTable;
046: import javax.swing.JTextArea;
047: import javax.swing.JTextField;
048:
049: import org.objectweb.salome_tmf.data.ConnectionData;
050: import org.objectweb.salome_tmf.data.Environment;
051: import org.objectweb.salome_tmf.data.Parameter;
052: import org.objectweb.salome_tmf.data.ProjectData;
053: import org.objectweb.salome_tmf.ihm.datawrapper.DataModel;
054: import org.objectweb.salome_tmf.ihm.languages.Language;
055: import org.objectweb.salome_tmf.ihm.models.TableSorter;
056: import org.objectweb.salome_tmf.ihm.models.UsingParameterMouseListener;
057:
058: /**
059: * Classe qui permet d'afficher une fenêtre demandant d'entrer les
060: * informations pour un nouveau paramètre, un nouveau groupe ou une nouvelle
061: * famille.
062: * @author teaml039
063: * @version 0.1
064: */
065: public class AskNewParameter extends JDialog {
066:
067: /**
068: * le champ pour entrer le nom du paramètre
069: */
070: JTextField nameField;
071:
072: /**
073: * le champ pour entrer la valeur du paramètre
074: */
075: JTextField valueField;
076:
077: /**
078: * le champ description
079: */
080: JTextArea descriptionArea;
081:
082: /**
083: * Un paramètre
084: */
085: Parameter parameter;
086:
087: /**
088: * Valeur du paramètre
089: */
090: String value;
091:
092: /**
093: * Environnment courant
094: */
095: Environment environment;
096:
097: JTable parameterTable;
098: TableSorter sorter;
099:
100: /******************************************************************************/
101: /** CONSTRUCTEUR ***/
102: /******************************************************************************/
103:
104: /**
105: * Constructeur de la fenêtre permettant de demander deux informations.
106: * @param param un paramètre
107: */
108: public AskNewParameter(Environment env, Parameter param) {
109: super (SalomeTMF.ptrFrame, true);
110:
111: nameField = new JTextField(15);
112: valueField = new JTextField(15);
113: descriptionArea = new JTextArea(10, 20);
114: parameterTable = new JTable();
115: JLabel promptFirst = new JLabel(Language.getInstance().getText(
116: "Nom_du_paramètre_:_"));
117:
118: JPanel onlyTextPanel = new JPanel();
119: onlyTextPanel.setLayout(new BoxLayout(onlyTextPanel,
120: BoxLayout.X_AXIS));
121: onlyTextPanel.add(Box.createRigidArea(new Dimension(0, 10)));
122: onlyTextPanel.add(promptFirst);
123: onlyTextPanel.add(nameField);
124:
125: JLabel valueLabel = new JLabel(Language.getInstance().getText(
126: "Valeur_du_paramètre_:_"));
127:
128: JPanel valuePanel = new JPanel();
129: valuePanel
130: .setLayout(new BoxLayout(valuePanel, BoxLayout.X_AXIS));
131: valuePanel.add(Box.createRigidArea(new Dimension(0, 10)));
132: valuePanel.add(valueLabel);
133: valuePanel.add(valueField);
134:
135: JScrollPane descriptionScrollPane = new JScrollPane(
136: descriptionArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
137: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
138: descriptionScrollPane.setBorder(BorderFactory
139: .createTitledBorder(BorderFactory
140: .createLineBorder(Color.BLACK), Language
141: .getInstance().getText("Description")));
142:
143: JPanel textPanel = new JPanel();
144: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
145: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
146: textPanel.add(onlyTextPanel);
147: textPanel.add(Box.createRigidArea(new Dimension(10, 10)));
148: if (env != null) {
149: textPanel.add(valuePanel);
150: textPanel.add(Box.createRigidArea(new Dimension(10, 10)));
151: }
152: textPanel.add(descriptionScrollPane);
153:
154: sorter = new TableSorter(DataModel.getParameterTableModel());
155: parameterTable.setModel(sorter);
156: sorter.setTableHeader(parameterTable.getTableHeader());
157:
158: parameterTable
159: .setPreferredScrollableViewportSize(new Dimension(700,
160: 350));
161:
162: JScrollPane parametersScrollPane = new JScrollPane(
163: parameterTable);
164: parametersScrollPane.setPreferredSize(new Dimension(450, 150));
165: parametersScrollPane
166: .setBorder(BorderFactory.createTitledBorder(
167: BorderFactory.createLineBorder(Color.BLACK),
168: Language.getInstance().getText(
169: "Paramètres_existants")));
170:
171: if (env == null) {
172: parameterTable
173: .addMouseListener(new UsingParameterMouseListener(
174: true, true));
175: } else {
176: parameterTable
177: .addMouseListener(new UsingParameterMouseListener(
178: false, false));
179: }
180:
181: JButton okButton = new JButton(Language.getInstance().getText(
182: "Valider"));
183: okButton.setToolTipText(Language.getInstance().getText(
184: "Valider"));
185: okButton.addActionListener(new ActionListener() {
186: public void actionPerformed(ActionEvent e) {
187: if (!nameField.getText().trim().equals("")) {
188: if (!ProjectData.getCurrentProject()
189: .containsParameter(
190: nameField.getText().trim())
191: && !ConnectionData.isInBaseParam(nameField
192: .getText().trim())) {
193: parameter.setName(nameField.getText().trim());
194: value = valueField.getText();
195: parameter.setDescription(descriptionArea
196: .getText());
197: AskNewParameter.this .dispose();
198: } else if (ProjectData.getCurrentProject()
199: .getParameter(nameField.getText().trim())
200: .equals(parameter)) {
201: parameter.setName(nameField.getText().trim());
202: value = valueField.getText();
203: parameter.setDescription(descriptionArea
204: .getText());
205: AskNewParameter.this .dispose();
206: } else {
207: JOptionPane
208: .showMessageDialog(
209: AskNewParameter.this ,
210: Language
211: .getInstance()
212: .getText(
213: "Ce_nom_de_paramètre_existe_déjà_!"),
214: Language.getInstance().getText(
215: "Erreur_!"),
216: JOptionPane.ERROR_MESSAGE);
217: }
218: } else {
219: JOptionPane
220: .showMessageDialog(
221: AskNewParameter.this ,
222: Language
223: .getInstance()
224: .getText(
225: "Il_faut_obligatoirement_donner_un_nom_au_paramètre_!"),
226: Language.getInstance().getText(
227: "Attention_!"),
228: JOptionPane.WARNING_MESSAGE);
229: }
230: }
231: });
232:
233: JButton cancelButton = new JButton(Language.getInstance()
234: .getText("Annuler"));
235: cancelButton.setToolTipText(Language.getInstance().getText(
236: "Annuler"));
237: cancelButton.addActionListener(new ActionListener() {
238: public void actionPerformed(ActionEvent e) {
239: parameter = null;
240: AskNewParameter.this .dispose();
241: }
242: });
243:
244: JPanel buttonPanel = new JPanel(new FlowLayout(
245: FlowLayout.CENTER));
246: buttonPanel.add(okButton);
247: buttonPanel.add(cancelButton);
248:
249: textPanel.add(buttonPanel);
250: textPanel.add(Box.createRigidArea(new Dimension(40, 10)));
251:
252: Container contentPaneFrame = this .getContentPane();
253: contentPaneFrame.add(textPanel, BorderLayout.NORTH);
254: contentPaneFrame.add(parametersScrollPane, BorderLayout.CENTER);
255:
256: this .addWindowListener(new WindowListener() {
257: public void windowClosing(WindowEvent e) {
258: parameter = null;
259: }
260:
261: public void windowDeiconified(WindowEvent e) {
262: }
263:
264: public void windowOpened(WindowEvent e) {
265: }
266:
267: public void windowActivated(WindowEvent e) {
268: }
269:
270: public void windowDeactivated(WindowEvent e) {
271: }
272:
273: public void windowClosed(WindowEvent e) {
274: }
275:
276: public void windowIconified(WindowEvent e) {
277: }
278: });
279:
280: initData(env, param);
281:
282: this .setTitle(Language.getInstance().getText(
283: "Nouveau_paramètre"));
284: this .setLocation(400, 250);
285: this .pack();
286: this .setVisible(true);
287: } // Fin du constructeur AskNewParameter/5
288:
289: /**
290: * Le nom et la description sont vides.
291: * @param type le type de donnée à récupérer
292: * @param title le titre de la fenêtre
293: * @param question le label proposant le texte à entrer
294: */
295: public AskNewParameter(Environment env) {
296: this (env, null);
297: } // Fin du constructeur AskNewParameter/3
298:
299: /******************************************************************************/
300: /** METHODES PUBLIQUES ***/
301: /******************************************************************************/
302:
303: /**
304: * Retourne le paramètre créé
305: * @return le paramètre créé
306: */
307: public Parameter getParameter() {
308: return parameter;
309: } // Fin de la méthode getParameter/0
310:
311: /**
312: *
313: * @param param
314: */
315: private void initData(Environment env, Parameter param) {
316: if (env != null && param != null) {
317: valueField.setText(env.getParameterValue(param));
318: }
319: if (param != null) {
320: parameter = param;
321: nameField.setText(param.getName());
322: nameField.setEnabled(false);
323: descriptionArea.setText(param.getDescription());
324: } else {
325: parameter = new Parameter();
326: }
327: environment = env;
328: } // Fin de la méthode initData/1
329:
330: /**
331: *
332: * @return
333: */
334: public String getValue() {
335: return value;
336: }
337:
338: public Environment getEnvironment() {
339: return environment;
340: }
341: } // Fin de la classe AskNewParameter
|