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.Dimension;
028: import java.awt.FlowLayout;
029: import java.awt.Frame;
030: import java.awt.Rectangle;
031: import java.awt.event.ActionEvent;
032: import java.awt.event.ActionListener;
033:
034: import javax.swing.BorderFactory;
035: import javax.swing.Box;
036: import javax.swing.BoxLayout;
037: import javax.swing.JButton;
038: import javax.swing.JDialog;
039: import javax.swing.JLabel;
040: import javax.swing.JOptionPane;
041: import javax.swing.JPanel;
042: import javax.swing.JPasswordField;
043:
044: import org.objectweb.salome_tmf.api.Api;
045: import org.objectweb.salome_tmf.api.MD5paswd;
046: import org.objectweb.salome_tmf.api.Util;
047: import org.objectweb.salome_tmf.ihm.languages.Language;
048: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
049: import org.objectweb.salome_tmf.ihm.tools.Tools;
050:
051: public class ChangePwdWindow extends JDialog {
052:
053: JPanel panel = new JPanel(new BorderLayout());
054:
055: /**
056: * Ancien mot de passe
057: */
058: JPasswordField oldUserPassword = new JPasswordField(20);
059:
060: /**
061: * Nouveau mot de passe : premier
062: */
063: JPasswordField newUserPasswordFirst = new JPasswordField(20);
064:
065: /**
066: * Nouveau mot de passe : second
067: */
068: JPasswordField newUserPasswordSecond = new JPasswordField(20);
069:
070: /** Creates a new instance of ChangePwdWindow */
071: public ChangePwdWindow(Frame owner) {
072:
073: super (owner, true);
074: JButton validateButton = new JButton(Language.getInstance()
075: .getText("Valider"));
076: validateButton.setToolTipText(Language.getInstance().getText(
077: "Valider"));
078: validateButton.addActionListener(new ActionListener() {
079: public void actionPerformed(ActionEvent e) {
080: if (Api.isConnected()) {
081:
082: //String pass = ConnectionData.getAdminVTSelect().getUserPassword(ProjectData.getCurrentUser().getLogin());
083: String pass = "";
084: try {
085: pass = DataModel.getCurrentUser()
086: .getPasswordFromDB();
087: } catch (Exception passEx) {
088: if (Api.isDEBUG()) {
089: passEx.printStackTrace();
090: Util
091: .log("[ChangePwdWindow->validateButton] Exception "
092: + passEx);
093: }
094: JOptionPane.showMessageDialog(
095: ChangePwdWindow.this , passEx, Language
096: .getInstance().getText(
097: "Erreur_!"),
098: JOptionPane.ERROR_MESSAGE);
099: return;
100: }
101: //if (oldUserPassword.getText().trim().equals(pass)) {
102: boolean _valid = false;
103: try {
104: _valid = MD5paswd.testPassword(new String(
105: oldUserPassword.getPassword()).trim(),
106: pass);
107: } catch (Exception ex) {
108: JOptionPane.showMessageDialog(
109: ChangePwdWindow.this , ex, Language
110: .getInstance().getText(
111: "Erreur_!"),
112: JOptionPane.ERROR_MESSAGE);
113: return;
114: }
115: if (_valid) {
116: if (new String(newUserPasswordFirst
117: .getPassword()).trim().equals(
118: new String(newUserPasswordSecond
119: .getPassword()).trim())) {
120: //int transNumber = -1;
121: try {
122: //transNumber = Api.beginTransaction(ApiConstants.UPDATE_PASSWORD);
123: //ConnectionData.getAdminVTUpdate().updateAdminPassword(ProjectData.getCurrentUser().getLogin(),new String(newUserPasswordSecond.getPassword()).trim());
124:
125: DataModel
126: .getCurrentUser()
127: .updatePasswordInDB(
128: new String(
129: newUserPasswordSecond
130: .getPassword())
131: .trim());
132:
133: oldUserPassword.setText("");
134: newUserPasswordFirst.setText("");
135: newUserPasswordSecond.setText("");
136: JOptionPane
137: .showMessageDialog(
138: ChangePwdWindow.this ,
139: Language
140: .getInstance()
141: .getText(
142: "Votre_mot_de_passe_a_été_modifié."),
143: Language
144: .getInstance()
145: .getText(
146: "Succès_!"),
147: JOptionPane.INFORMATION_MESSAGE);
148: //Api.commitTrans(transNumber);
149: ChangePwdWindow.this .dispose();
150: } catch (Exception exception) {
151: //Api.forceRollBackTrans(transNumber);
152: Tools.ihmExceptionView(exception);
153: }
154:
155: } else {
156: newUserPasswordFirst.setText("");
157: newUserPasswordSecond.setText("");
158: JOptionPane
159: .showMessageDialog(
160: ChangePwdWindow.this ,
161: Language
162: .getInstance()
163: .getText(
164: "Impossible_de_changer_le_mot_de_passe.\nVous_n'avez_pas_entrer_deux_fois_le_même_mot_de_passe."),
165: Language
166: .getInstance()
167: .getText("Erreur_!"),
168: JOptionPane.ERROR_MESSAGE);
169: }
170: } else {
171: oldUserPassword.setText("");
172: JOptionPane
173: .showMessageDialog(
174: ChangePwdWindow.this ,
175: Language
176: .getInstance()
177: .getText(
178: "Impossible_de_changer_le_mot_de_passe.\nL'ancien_mot_de_passe_est_incorrect."),
179: Language.getInstance().getText(
180: "Erreur_!"),
181: JOptionPane.ERROR_MESSAGE);
182: }
183: } else {
184: JOptionPane
185: .showMessageDialog(
186: ChangePwdWindow.this ,
187: Language
188: .getInstance()
189: .getText(
190: "Impossible_de_changer_le_mot_de_passe.\nVous_n'êtes_pas_connecter_à_la_base."),
191: Language.getInstance().getText(
192: "Erreur_!"),
193: JOptionPane.ERROR_MESSAGE);
194: }
195: }
196: });
197:
198: JButton cancelButton = new JButton(Language.getInstance()
199: .getText("Annuler"));
200: cancelButton.setToolTipText(Language.getInstance().getText(
201: "Annuler"));
202: cancelButton.addActionListener(new ActionListener() {
203: public void actionPerformed(ActionEvent e) {
204: oldUserPassword.setText(null);
205: newUserPasswordFirst.setText(null);
206: newUserPasswordSecond.setText(null);
207: ChangePwdWindow.this .dispose();
208:
209: }
210: });
211:
212: JLabel oldQuestion = new JLabel(Language.getInstance().getText(
213: "Entrez_votre_ancien_mot_de_passe_:"));
214:
215: JLabel question = new JLabel(Language.getInstance().getText(
216: "Entrez_votre_nouveau_mot_de_passe_:"));
217:
218: JLabel confirmation = new JLabel(Language.getInstance()
219: .getText("Confirmer_le_nouveau_mot_de_passe_:"));
220:
221: JPanel textFieldPane = new JPanel();
222: textFieldPane.setLayout(new BoxLayout(textFieldPane,
223: BoxLayout.Y_AXIS));
224: textFieldPane.add(oldUserPassword);
225: textFieldPane.add(Box.createRigidArea(new Dimension(1, 50)));
226: textFieldPane.add(newUserPasswordFirst);
227: textFieldPane.add(Box.createRigidArea(new Dimension(1, 50)));
228: textFieldPane.add(newUserPasswordSecond);
229:
230: JPanel textPane = new JPanel();
231: textPane.setLayout(new BoxLayout(textPane, BoxLayout.Y_AXIS));
232: textPane.add(oldQuestion);
233: textPane.add(Box.createRigidArea(new Dimension(1, 50)));
234: textPane.add(question);
235: textPane.add(Box.createRigidArea(new Dimension(1, 50)));
236: textPane.add(confirmation);
237:
238: JPanel textPaneAll = new JPanel(new FlowLayout(
239: FlowLayout.CENTER));
240: textPaneAll.add(textPane);
241: textPaneAll.add(textFieldPane);
242:
243: JPanel buttonPanel = new JPanel(new FlowLayout(
244: FlowLayout.CENTER));
245: buttonPanel.add(validateButton);
246: buttonPanel.add(cancelButton);
247:
248: JPanel labelSet = new JPanel();
249: labelSet.add(textPaneAll);
250: //labelSet.setBorder(BorderFactory.createEmptyBorder(100, 10, 10, 100));
251:
252: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
253: panel.add(labelSet);
254: panel.add(buttonPanel);
255: panel.setBorder(BorderFactory.createRaisedBevelBorder());
256:
257: this .getContentPane().add(panel);
258:
259: this .setTitle(Language.getInstance().getText(
260: "Changement_du_mot_de_passe"));
261: //this.setLocation(300,300);
262: /**this.pack();
263: this.setLocationRelativeTo(this.getParent());
264: */
265: centerScreen();
266: }
267:
268: void centerScreen() {
269: Dimension dim = getToolkit().getScreenSize();
270: this .pack();
271: Rectangle abounds = getBounds();
272: setLocation((dim.width - abounds.width) / 2,
273: (dim.height - abounds.height) / 2);
274: // this.setVisible(true);
275: // requestFocus();
276: }
277: }
|