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.Dimension;
028: import java.awt.FlowLayout;
029: import java.awt.Frame;
030: import java.awt.event.ActionEvent;
031: import java.awt.event.ActionListener;
032:
033: import javax.swing.BorderFactory;
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:
043: import org.objectweb.salome_tmf.api.Api;
044: import org.objectweb.salome_tmf.api.ApiConstants;
045: import org.objectweb.salome_tmf.api.MD5paswd;
046: import org.objectweb.salome_tmf.data.ConnectionData;
047: import org.objectweb.salome_tmf.data.ProjectData;
048: import org.objectweb.salome_tmf.ihm.languages.Language;
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 (ConnectionData.isConnected()) {
081:
082: String pass = ConnectionData.getAdminVTSelect()
083: .getUserPassword(
084: ProjectData.getCurrentUser()
085: .getLogin());
086: //if (oldUserPassword.getText().trim().equals(pass)) {
087: boolean _valid = false;
088: try {
089: _valid = MD5paswd.testPassword(new String(
090: oldUserPassword.getPassword()).trim(),
091: pass);
092: } catch (Exception ex) {
093: }
094: if (_valid) {
095: if (new String(newUserPasswordFirst
096: .getPassword()).trim().equals(
097: new String(newUserPasswordSecond
098: .getPassword()).trim())) {
099: int transNumber = -1;
100: try {
101: transNumber = Api
102: .beginTransaction(ApiConstants.UPDATE_PASSWORD);
103: ConnectionData
104: .getAdminVTUpdate()
105: .updateAdminPassword(
106: ProjectData
107: .getCurrentUser()
108: .getLogin(),
109: new String(
110: newUserPasswordSecond
111: .getPassword())
112: .trim());
113: oldUserPassword.setText("");
114: newUserPasswordFirst.setText("");
115: newUserPasswordSecond.setText("");
116: JOptionPane
117: .showMessageDialog(
118: ChangePwdWindow.this ,
119: Language
120: .getInstance()
121: .getText(
122: "Votre_mot_de_passe_a_été_modifié."),
123: Language
124: .getInstance()
125: .getText(
126: "Succès_!"),
127: JOptionPane.INFORMATION_MESSAGE);
128: Api.commitTrans(transNumber);
129: ChangePwdWindow.this .dispose();
130: } catch (Exception exception) {
131: Api.forceRollBackTrans(transNumber);
132: Tools.ihmExceptionView(exception
133: .toString());
134: }
135:
136: } else {
137: newUserPasswordFirst.setText("");
138: newUserPasswordSecond.setText("");
139: JOptionPane
140: .showMessageDialog(
141: ChangePwdWindow.this ,
142: Language
143: .getInstance()
144: .getText(
145: "Impossible_de_changer_le_mot_de_passe.\nVous_n'avez_pas_entrer_deux_fois_le_même_mot_de_passe."),
146: Language
147: .getInstance()
148: .getText("Erreur_!"),
149: JOptionPane.ERROR_MESSAGE);
150: }
151: } else {
152: oldUserPassword.setText("");
153: JOptionPane
154: .showMessageDialog(
155: ChangePwdWindow.this ,
156: Language
157: .getInstance()
158: .getText(
159: "Impossible_de_changer_le_mot_de_passe.\nL'ancien_mot_de_passe_est_incorrect."),
160: Language.getInstance().getText(
161: "Erreur_!"),
162: JOptionPane.ERROR_MESSAGE);
163: }
164: } else {
165: JOptionPane
166: .showMessageDialog(
167: ChangePwdWindow.this ,
168: Language
169: .getInstance()
170: .getText(
171: "Impossible_de_changer_le_mot_de_passe.\nVous_n'êtes_pas_connecter_à_la_base."),
172: Language.getInstance().getText(
173: "Erreur_!"),
174: JOptionPane.ERROR_MESSAGE);
175: }
176: }
177: });
178:
179: JButton cancelButton = new JButton(Language.getInstance()
180: .getText("Annuler"));
181: cancelButton.setToolTipText(Language.getInstance().getText(
182: "Annuler"));
183: cancelButton.addActionListener(new ActionListener() {
184: public void actionPerformed(ActionEvent e) {
185: oldUserPassword.setText(null);
186: newUserPasswordFirst.setText(null);
187: newUserPasswordSecond.setText(null);
188: ChangePwdWindow.this .dispose();
189:
190: }
191: });
192:
193: JLabel oldQuestion = new JLabel(Language.getInstance().getText(
194: "Entrez_votre_ancien_mot_de_passe_:"));
195:
196: JLabel question = new JLabel(Language.getInstance().getText(
197: "Entrez_votre_nouveau_mot_de_passe_:"));
198:
199: JLabel confirmation = new JLabel(Language.getInstance()
200: .getText("Confirmer_le_nouveau_mot_de_passe_:"));
201:
202: JPanel textFieldPane = new JPanel();
203: textFieldPane.setLayout(new BoxLayout(textFieldPane,
204: BoxLayout.Y_AXIS));
205: textFieldPane.add(oldUserPassword);
206: textFieldPane.add(Box.createRigidArea(new Dimension(1, 50)));
207: textFieldPane.add(newUserPasswordFirst);
208: textFieldPane.add(Box.createRigidArea(new Dimension(1, 50)));
209: textFieldPane.add(newUserPasswordSecond);
210:
211: JPanel textPane = new JPanel();
212: textPane.setLayout(new BoxLayout(textPane, BoxLayout.Y_AXIS));
213: textPane.add(oldQuestion);
214: textPane.add(Box.createRigidArea(new Dimension(1, 50)));
215: textPane.add(question);
216: textPane.add(Box.createRigidArea(new Dimension(1, 50)));
217: textPane.add(confirmation);
218:
219: JPanel textPaneAll = new JPanel(new FlowLayout(
220: FlowLayout.CENTER));
221: textPaneAll.add(textPane);
222: textPaneAll.add(textFieldPane);
223:
224: JPanel buttonPanel = new JPanel(new FlowLayout(
225: FlowLayout.CENTER));
226: buttonPanel.add(validateButton);
227: buttonPanel.add(cancelButton);
228:
229: JPanel labelSet = new JPanel();
230: labelSet.add(textPaneAll);
231: //labelSet.setBorder(BorderFactory.createEmptyBorder(100, 10, 10, 100));
232:
233: panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
234: panel.add(labelSet);
235: panel.add(buttonPanel);
236: panel.setBorder(BorderFactory.createRaisedBevelBorder());
237:
238: this .getContentPane().add(panel);
239:
240: this .setTitle(Language.getInstance().getText(
241: "Changement_du_mot_de_passe"));
242: this .setLocation(300, 300);
243: this.pack();
244: }
245:
246: }
|