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.Container;
028: import java.awt.Dimension;
029: import java.awt.FlowLayout;
030: import java.awt.Frame;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033:
034: import javax.swing.Box;
035: import javax.swing.BoxLayout;
036: import javax.swing.JButton;
037: import javax.swing.JDialog;
038: import javax.swing.JLabel;
039: import javax.swing.JOptionPane;
040: import javax.swing.JPanel;
041: import javax.swing.JPasswordField;
042: import javax.swing.JTextField;
043: import org.objectweb.salome_tmf.data.AdminVTData;
044: import org.objectweb.salome_tmf.data.User;
045: import org.objectweb.salome_tmf.ihm.languages.Language;
046:
047: /**
048: * Classe qui permet d'afficher une fenêtre demandant d'entrer les
049: * informations pour les nouveaux utilisateurs
050: */
051: public class AskNewUser extends JDialog {
052:
053: /**
054: * Le Field permettant de récupérer le login
055: */
056: private JTextField loginField;
057:
058: /**
059: * Le Field permettant de récupérer le prénom
060: */
061: private JTextField firstNameField;
062:
063: /**
064: * Le Field permettant de récupérer le nom
065: */
066: private JTextField lastNameField;
067:
068: /**
069: * Le Field permettant de récupérer l'email
070: */
071: private JTextField emailField;
072:
073: /**
074: * Le Field permettant de récupérer la numéro de téléphone
075: */
076: private JTextField phoneField;
077:
078: /**
079: * Le Field permettant de récupérer le mot de passe
080: */
081: private JPasswordField pwdField;
082:
083: /**
084: * L'utilisateur créé
085: */
086: private User user;
087:
088: /**
089: * Le mot de passe par défaut pour le nouvel utilisateur
090: */
091: private char[] password;
092:
093: boolean newUser = false;
094: String oldUserLogin = "";
095:
096: /******************************************************************************/
097: /** CONSTRUCTEUR ***/
098: /******************************************************************************/
099:
100: /**
101: * Constructeur de la fenêtre.
102: * @param textToBePrompt chaîne correspondant à la demande.
103: */
104: public AskNewUser(User oldUser, Frame owner) {
105:
106: super (owner, true);
107:
108: if (oldUser == null) {
109: newUser = true;
110: } else {
111: oldUserLogin = oldUser.getLogin();
112: }
113:
114: loginField = new JTextField(10);
115: firstNameField = new JTextField(10);
116: lastNameField = new JTextField(10);
117: emailField = new JTextField(10);
118: phoneField = new JTextField(10);
119: pwdField = new JPasswordField(10);
120: JPanel page = new JPanel();
121:
122: JLabel obligation = new JLabel(Language.getInstance().getText(
123: "*_:_champ_obligatoire"));
124:
125: JLabel loginLabel = new JLabel(Language.getInstance().getText(
126: "Login*_:"));
127: JLabel lastNameLabel = new JLabel(Language.getInstance()
128: .getText("Nom*_:"));
129: JLabel firstNameLabel = new JLabel(Language.getInstance()
130: .getText("Prénom*_:"));
131: JLabel emailLabel = new JLabel(Language.getInstance().getText(
132: "Email*_:"));
133: JLabel phoneLabel = new JLabel(Language.getInstance().getText(
134: "Téléphone_:_"));
135: JLabel pwdLabel = new JLabel(Language.getInstance().getText(
136: "Mot_de_passe*_:_"));
137:
138: JPanel allField = new JPanel();
139: allField.setLayout(new BoxLayout(allField, BoxLayout.Y_AXIS));
140: allField.add(Box.createVerticalGlue());
141: allField.add(loginField);
142: allField.add(Box.createRigidArea(new Dimension(1, 15)));
143: allField.add(lastNameField);
144: allField.add(Box.createRigidArea(new Dimension(1, 15)));
145: allField.add(firstNameField);
146: allField.add(Box.createRigidArea(new Dimension(1, 15)));
147: allField.add(emailField);
148: allField.add(Box.createRigidArea(new Dimension(1, 15)));
149: allField.add(phoneField);
150: if (newUser) {
151: allField.add(Box.createRigidArea(new Dimension(1, 15)));
152: allField.add(pwdField);
153: }
154:
155: JPanel giveName = new JPanel();
156: giveName.setLayout(new BoxLayout(giveName, BoxLayout.Y_AXIS));
157: giveName.add(Box.createVerticalGlue());
158: giveName.add(loginLabel);
159: giveName.add(Box.createRigidArea(new Dimension(1, 20)));
160: giveName.add(lastNameLabel);
161: giveName.add(Box.createRigidArea(new Dimension(1, 20)));
162: giveName.add(firstNameLabel);
163: giveName.add(Box.createRigidArea(new Dimension(1, 20)));
164: giveName.add(emailLabel);
165: giveName.add(Box.createRigidArea(new Dimension(1, 20)));
166: giveName.add(phoneLabel);
167: if (newUser) {
168: giveName.add(Box.createRigidArea(new Dimension(1, 20)));
169: giveName.add(pwdLabel);
170: }
171:
172: JPanel textPanel = new JPanel();
173: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));
174:
175: textPanel.add(giveName);
176: textPanel.add(allField);
177:
178: JButton okButton = new JButton(Language.getInstance().getText(
179: "Valider"));
180: okButton.setToolTipText(Language.getInstance().getText(
181: "Valider"));
182: okButton.addActionListener(new ActionListener() {
183: public void actionPerformed(ActionEvent e) {
184: boolean ok = true;
185: user = new User();
186: if ((!loginField.getText().trim().equals(""))
187: && (!loginField.getText().trim().equals(""))) {
188: if ((!AdminVTData.containsLogin(loginField
189: .getText().trim()))
190: || (oldUserLogin.equals(loginField
191: .getText().trim()))) {
192: user.setLogin(loginField.getText().trim());
193: if (!lastNameField.getText().equals("")) {
194: user.setLastName(lastNameField.getText());
195: if (!firstNameField.getText().equals("")) {
196: user.setFirstName(firstNameField
197: .getText());
198: if (!emailField.getText().equals("")) {
199: user.setEmail(emailField.getText());
200: if (pwdField.getPassword().length != 0) {
201: password = pwdField
202: .getPassword();
203: } else if (newUser) {
204: warning(
205: pwdField,
206: Language
207: .getInstance()
208: .getText(
209: "Vous_devez_entrer_un_mot_de_passe_par_défaut_!"));
210: ok = false;
211: }
212: } else {
213: warning(
214: emailField,
215: Language
216: .getInstance()
217: .getText(
218: "Vous_devez_entrer_un_email_!"));
219: ok = false;
220: }
221: } else {
222: warning(
223: firstNameField,
224: Language
225: .getInstance()
226: .getText(
227: "Vous_devez_entrer_un_prénom_!"));
228: ok = false;
229: }
230: } else {
231: warning(
232: lastNameField,
233: Language
234: .getInstance()
235: .getText(
236: "Vous_devez_entrer_un_nom_!"));
237: ok = false;
238: }
239: } else {
240: JOptionPane.showMessageDialog(AskNewUser.this ,
241: Language.getInstance().getText(
242: "Ce_login_existe_déjà_!"),
243: Language.getInstance().getText(
244: "Erreur_!"),
245: JOptionPane.ERROR_MESSAGE);
246: ok = false;
247: }
248: } else {
249: warning(loginField, Language.getInstance().getText(
250: "Vous_devez_entrer_un_nom_de_login_!"));
251: ok = false;
252: }
253: if (phoneField.getText() != "") {
254: user.setPhoneNumber(phoneField.getText());
255: }
256: if (ok)
257: AskNewUser.this .dispose();
258: }
259: });
260:
261: JButton cancelButton = new JButton(Language.getInstance()
262: .getText("Annuler"));
263: cancelButton.setToolTipText(Language.getInstance().getText(
264: "Annuler"));
265: cancelButton.addActionListener(new ActionListener() {
266: public void actionPerformed(ActionEvent e) {
267: user = null;
268: password = null;
269: AskNewUser.this .dispose();
270: }
271: });
272:
273: JPanel buttonPanel = new JPanel();
274: buttonPanel.setLayout(new BorderLayout());
275: buttonPanel.add(okButton, BorderLayout.NORTH);
276: buttonPanel.add(cancelButton, BorderLayout.SOUTH);
277:
278: JPanel obligationPanel = new JPanel(new FlowLayout(
279: FlowLayout.RIGHT));
280: obligationPanel.add(obligation);
281:
282: page.add(textPanel, BorderLayout.WEST);
283: page.add(Box.createRigidArea(new Dimension(40, 10)),
284: BorderLayout.CENTER);
285: page.add(buttonPanel, BorderLayout.EAST);
286:
287: Container contentPaneFrame = this .getContentPane();
288: contentPaneFrame.add(page, BorderLayout.CENTER);
289: contentPaneFrame.add(obligationPanel, BorderLayout.SOUTH);
290:
291: initData(oldUser);
292: if (oldUser != null) {
293: this .setTitle(Language.getInstance().getText(
294: "Modifier_un_utilisateur"));
295: } else {
296: this .setTitle(Language.getInstance().getText(
297: "Créer_un_nouvel_utilisateur"));
298: }
299:
300: this .setLocation(400, 300);
301: this .pack();
302: this .setVisible(true);
303: } // Fin du constructeur AskName/1
304:
305: /******************************************************************************/
306: /** METHODES PUBLIQUES ***/
307: /******************************************************************************/
308:
309: /**
310: * Récupère le nouvel utilisateur
311: * @return
312: */
313: public User getUser() {
314: return user;
315: } // Fin de la méthode getUser/0
316:
317: private void initData(User oldUser) {
318: if (oldUser != null) {
319: user = oldUser;
320: loginField.setText(oldUser.getLogin());
321: firstNameField.setText(oldUser.getFirstName());
322: lastNameField.setText(oldUser.getLastName());
323: emailField.setText(oldUser.getEmail());
324: phoneField.setText(oldUser.getPhoneNumber());
325:
326: } else {
327: user = new User();
328: }
329: }
330:
331: /**
332: * Affiche une fenêtre de warning para rapport au field passé en paramètre
333: * avec le message passé en paramètre
334: * @param field le field concerné
335: * @param msg message à afficher
336: */
337: public void warning(JTextField field, String msg) {
338: field.selectAll();
339: JOptionPane.showMessageDialog(AskNewUser.this , msg, Language
340: .getInstance().getText("Erreur_!"),
341: JOptionPane.ERROR_MESSAGE);
342: field.requestFocusInWindow();
343: } // Fin de la méthode warning/2
344:
345: /**
346: * Retourne le mot de passe
347: * @return le mot de passe
348: */
349: public char[] getPassword() {
350: return password;
351: } // Fin de la méthode getPassword/0
352: } // Fin de la classe AskNewUser
|