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