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.common;
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.Frame;
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.JTextArea;
046: import javax.swing.JTextField;
047:
048: import org.objectweb.salome_tmf.data.AdminProjectData;
049: import org.objectweb.salome_tmf.data.DataConstants;
050: import org.objectweb.salome_tmf.data.Family;
051: import org.objectweb.salome_tmf.data.Group;
052: import org.objectweb.salome_tmf.data.Parameter;
053: import org.objectweb.salome_tmf.data.SimpleData;
054: import org.objectweb.salome_tmf.ihm.languages.Language;
055:
056: /**
057: * Classe qui permet d'afficher une fenêtre demandant d'entrer les
058: * informations pour un nouveau paramètre, un nouveau groupe ou une nouvelle
059: * famille.
060: * @author teaml039
061: * @version 0.1
062: */
063: public class AskNameAndDescription extends JDialog implements
064: DataConstants {
065:
066: /**
067: * le champ pour entrer le nom du paramètre
068: */
069: JTextField textFirst;
070:
071: /**
072: * le champ description
073: */
074: JTextArea descriptionArea;
075:
076: /**
077: * Un paramètre
078: */
079: Parameter parameter;
080:
081: /**
082: * Le type de donnée à récupérer
083: */
084: int givenType;
085:
086: /**
087: * Un groupe
088: */
089: Group group;
090:
091: /**
092: * Une famille
093: */
094: Family family;
095:
096: AdminProjectData pAdminProjectData;
097:
098: /******************************************************************************/
099: /** CONSTRUCTEUR ***/
100: /******************************************************************************/
101:
102: /**
103: * Constructeur de la fenêtre permettant de demander deux informations.
104: * @param type le type de donnée à récupérer
105: * @param title le titre de la fenêtre
106: * @param question le label proposant le texte à entrer
107: * @param name le nom à placer dans le texteField
108: * @param descr texte à placer dans la description
109: */
110: public AskNameAndDescription(int type, String title,
111: String question, SimpleData elem, Frame owner,
112: AdminProjectData adminProjectData) {
113: super (owner, true);
114: pAdminProjectData = adminProjectData;
115: textFirst = new JTextField(15);
116: descriptionArea = new JTextArea(10, 20);
117: JPanel page = new JPanel();
118:
119: JLabel promptFirst = new JLabel(question);
120:
121: JPanel onlyTextPanel = new JPanel();
122: onlyTextPanel.setLayout(new BoxLayout(onlyTextPanel,
123: BoxLayout.X_AXIS));
124: onlyTextPanel.add(Box.createRigidArea(new Dimension(0, 10)));
125: onlyTextPanel.add(promptFirst);
126: onlyTextPanel.add(textFirst);
127:
128: JScrollPane descriptionScrollPane = new JScrollPane(
129: descriptionArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
130: JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
131: descriptionScrollPane.setBorder(BorderFactory
132: .createTitledBorder(BorderFactory
133: .createLineBorder(Color.BLACK), Language
134: .getInstance().getText("Description")));
135:
136: JPanel textPanel = new JPanel();
137: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
138: textPanel.add(Box.createRigidArea(new Dimension(0, 10)));
139: textPanel.add(onlyTextPanel);
140: textPanel.add(Box.createRigidArea(new Dimension(10, 10)));
141: textPanel.add(descriptionScrollPane);
142:
143: JButton okButton = new JButton(Language.getInstance().getText(
144: "Valider"));
145: okButton.setToolTipText(Language.getInstance().getText(
146: "Valider"));
147: okButton.addActionListener(new ActionListener() {
148: public void actionPerformed(ActionEvent e) {
149: if (!textFirst.getText().trim().equals("")) {
150: if (givenType == GROUP) {
151: if (pAdminProjectData
152: .getCurrentProjectFromModel()
153: .getGroupFromModel(
154: textFirst.getText().trim()) == null) {
155: group.updateNameInModel(textFirst.getText()
156: .trim());
157: group
158: .updateDescriptionInModel(descriptionArea
159: .getText());
160: AskNameAndDescription.this .dispose();
161: } else if (pAdminProjectData
162: .getCurrentProjectFromModel()
163: .getGroupFromModel(
164: textFirst.getText().trim())
165: .equals(group)) {
166: group.updateNameInModel(textFirst.getText()
167: .trim());
168: group
169: .updateDescriptionInModel(descriptionArea
170: .getText());
171: AskNameAndDescription.this .dispose();
172: } else {
173: JOptionPane
174: .showMessageDialog(
175: AskNameAndDescription.this ,
176: Language
177: .getInstance()
178: .getText(
179: "Ce_nom_de_groupe_existe_déjà_!"),
180: Language
181: .getInstance()
182: .getText("Erreur_!"),
183: JOptionPane.ERROR_MESSAGE);
184: }
185: } else if (givenType == FAMILY) {
186: family.updateInModel(
187: textFirst.getText().trim(),
188: descriptionArea.getText());
189: AskNameAndDescription.this .dispose();
190: } else {
191: parameter
192: .updateDescriptionInModel(descriptionArea
193: .getText());
194: parameter.updateNameInModel(textFirst.getText()
195: .trim());
196: AskNameAndDescription.this .dispose();
197: }
198: } else {
199: JOptionPane
200: .showMessageDialog(
201: AskNameAndDescription.this ,
202: Language
203: .getInstance()
204: .getText(
205: "Il_faut_obligatoirement_donner_un_nom_!"),
206: Language.getInstance().getText(
207: "Attention_!"),
208: JOptionPane.WARNING_MESSAGE);
209: }
210: }
211: });
212:
213: JButton cancelButton = new JButton(Language.getInstance()
214: .getText("Annuler"));
215: cancelButton.setToolTipText(Language.getInstance().getText(
216: "Annuler"));
217: cancelButton.addActionListener(new ActionListener() {
218: public void actionPerformed(ActionEvent e) {
219: parameter = null;
220: family = null;
221: group = null;
222: AskNameAndDescription.this .dispose();
223: }
224: });
225:
226: JPanel buttonPanel = new JPanel();
227: buttonPanel.setLayout(new BorderLayout());
228: buttonPanel.add(okButton, BorderLayout.NORTH);
229: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
230:
231: page.add(textPanel, BorderLayout.WEST);
232: page.add(Box.createRigidArea(new Dimension(40, 10)),
233: BorderLayout.CENTER);
234: page.add(buttonPanel, BorderLayout.EAST);
235:
236: initData(elem, type);
237:
238: this .addWindowListener(new WindowListener() {
239: public void windowClosing(WindowEvent e) {
240: parameter = null;
241: family = null;
242: group = null;
243: }
244:
245: public void windowDeiconified(WindowEvent e) {
246: }
247:
248: public void windowOpened(WindowEvent e) {
249: }
250:
251: public void windowActivated(WindowEvent e) {
252: }
253:
254: public void windowDeactivated(WindowEvent e) {
255: }
256:
257: public void windowClosed(WindowEvent e) {
258: }
259:
260: public void windowIconified(WindowEvent e) {
261: }
262: });
263:
264: Container contentPaneFrame = this .getContentPane();
265: contentPaneFrame.add(page, BorderLayout.CENTER);
266: this .setTitle(title);
267: //this.setLocation(400,300);
268: this .setLocationRelativeTo(this .getParent());
269: this .pack();
270: this .setVisible(true);
271: } // Fin du constructeur AskNewParameter/5
272:
273: /**
274: * Le nom et la description sont vides.
275: * @param type le type de donnée à récupérer
276: * @param title le titre de la fenêtre
277: * @param question le label proposant le texte à entrer
278: */
279: public AskNameAndDescription(int type, String title,
280: String question, Frame owner,
281: AdminProjectData adminProjectData) {
282: this (type, title, question, null, owner, adminProjectData);
283: } // Fin du constructeur AskNewParameter/3
284:
285: /******************************************************************************/
286: /** METHODES PUBLIQUES ***/
287: /******************************************************************************/
288:
289: /**
290: * Retourne le paramètre créé
291: * @return le paramètre créé
292: */
293: public Parameter getNewParameter() {
294: return parameter;
295: } // Fin de la méthode getNewParameter/0
296:
297: /**
298: * Retourne le groupe créé
299: * @return le groupe créé
300: */
301: public Group getGroup() {
302: return group;
303: } // Fin de la méthode getGroup/0
304:
305: /**
306: * Retourne la famille créée
307: * @return la famille créée
308: */
309: public Family getFamily() {
310: return family;
311: } // Fin de la méthode getFamily/0
312:
313: private void initData(SimpleData elem, int type) {
314: givenType = type;
315: if (elem != null) {
316: textFirst.setText(elem.getNameFromModel());
317: descriptionArea.setText(elem.getDescriptionFromModel());
318: if (elem instanceof Group) {
319: group = (Group) elem;
320: } else if (elem instanceof Parameter) {
321: parameter = (Parameter) elem;
322: } else if (elem instanceof Family) {
323: family = (Family) elem;
324: }
325: if (givenType == PARAMETER) {
326: textFirst.setEnabled(false);
327: }
328: } else {
329: if (givenType == GROUP) {
330: group = new Group("", "");
331: } else if (givenType == PARAMETER) {
332: parameter = new Parameter("", "");
333: } else if (givenType == FAMILY) {
334: family = new Family("", "");
335: }
336: }
337: }
338: } // Fin de la classe AskNewParameter
|