001 /** =====================================================================
002 *
003 * File Name : $Id: ChangePasswordDialogBox.java,v 1.6 2008/01/15 11:08:16 cb Exp $
004 *
005 * Description
006 * -----------
007 *
008 * =====================================================================
009 *
010 * @author : Craige Bevil
011 * Control Software Group
012 * Isaac Newton Group of Telescopes
013 *
014 * =====================================================================
015 *
016 * Modification Log
017 *
018 * Vers Date Author Reason
019 * ---- ---- ------ ------
020 * 1 C.Bevil First Release
021 *
022 * Commissioning Notes
023 * -------------------
024 *
025 * None
026 *
027 * =====================================================================
028 *
029 * @version : $Id: ChangePasswordDialogBox.java,v 1.6 2008/01/15 11:08:16 cb Exp $
030 *
031 * @author : $Author: cb $
032 *
033 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/client/ChangePasswordDialogBox.java,v 1.6 2008/01/15 11:08:16 cb Exp $
034 *
035 * Log : $Log: ChangePasswordDialogBox.java,v $
036 * Log : Revision 1.6 2008/01/15 11:08:16 cb
037 * Log : Ran through PMD and sorted out the javadoc so that we could export the
038 * Log : javadoc to the javadoc repository.
039 * Log :
040 * Log : Revision 1.5 2007/12/17 11:42:02 cb
041 * Log : Modified so the focus is put into the first field of the dialog
042 * Log :
043 * Log : Revision 1.4 2007/12/13 14:46:38 cb
044 * Log : Modified as the Javascript library that I was using for displaying
045 * Log : messages clashes with the dialog boxes and looks the display.
046 * Log :
047 * Log : Revision 1.3 2007/12/12 15:26:17 cb
048 * Log : Added new javascript library which allows fancy message boxes to be
049 * Log : displayed.
050 * Log :
051 * Log : Revision 1.2 2007/08/17 14:22:28 cb
052 * Log : Optimised after PMD, display in centre of screen
053 * Log :
054 * Log : Revision 1.1 2007/07/24 08:25:23 cb
055 * Log : First version
056 * Log :
057 *
058 * =====================================================================*/
059
060 package GWTApplication.client;
061
062 import com.google.gwt.user.client.*;
063 import com.google.gwt.user.client.rpc.*;
064 import com.google.gwt.user.client.ui.*;
065 import com.google.gwt.user.client.ui.DockPanel.*;
066
067 import com.google.gwt.user.client.ui.FlexTable.*;
068 import java.util.*;
069
070 /**
071 * This class will allow the user to change his password. It
072 * does by means of a pop up dialog which will allow the user to
073 * enter his new password twice. If the passwords do not match the
074 * attempt at setting the password is rejected.
075 * @author Craige Bevil
076 * @version $Id: ChangePasswordDialogBox.java,v 1.6 2008/01/15 11:08:16 cb Exp $
077 */
078
079 public class ChangePasswordDialogBox extends FaultDBForm implements ClickListener {
080
081 /**
082 * This is the submit button widget
083 */
084
085 final private Button SubmitButton;
086
087 /**
088 * The user will enter his new password into this text box widget.
089 */
090
091 final private PasswordTextBox NewPassword = new PasswordTextBox();
092
093 /**
094 * The user will enter his new password into this text box widget.
095 */
096
097 private PasswordTextBox PasswordConfirmation = new PasswordTextBox();
098
099 /**
100 * This is the cancel button widget
101 */
102
103 final private Button CancelButton;
104
105 /**
106 * This is the main dialog box which will be displayed
107 */
108
109 DialogBox ChangePasswordDialog = new DialogBox(false);
110
111 /**
112 * This is the email address of the person that is to have his
113 * password updated
114 */
115
116 String emailAddress;
117
118 /**
119 * Constructor
120 * @param svc Used to communicate with the remote servlet
121 * container.
122 * @param emailAddress This is the email address of the person who
123 * is to have his password changed.
124 */
125
126 ChangePasswordDialogBox (final FaultServiceAsync svc,final String emailAddress) {
127
128 final DockPanel panel = new DockPanel();
129
130 this.svc = svc;
131 this.emailAddress = emailAddress;
132
133 final FlexTable tmp = new FlexTable();
134
135 // Now create the field into which the user will enter his new
136 // password
137
138 tmp.setText(0,0,internationalizationConstants.newPassword());
139 tmp.setWidget(0,1,NewPassword);
140
141 tmp.setText(1,0,internationalizationConstants.confirmPassword());
142 tmp.setWidget(1,1,PasswordConfirmation);
143
144 panel.add(tmp,DockPanel.NORTH);
145
146 // Now add the submit and cancel button
147
148 SubmitButton = new Button(internationalizationConstants.changePassword(),this);
149 CancelButton = new Button(internationalizationConstants.cancel(),this);
150
151 panel.add(SubmitButton,DockPanel.WEST);
152 panel.add(CancelButton,DockPanel.WEST);
153 panel.setSpacing(10);
154
155 // Now add the main panel to the dialog box
156
157 ChangePasswordDialog.setWidget(panel);
158
159 ChangePasswordDialog.setText(internationalizationConstants.changePassword());
160 }
161
162
163 /**
164 * This is the click handler which is called when the user calls
165 * presses one of the buttons on the dialog. It results in the
166 * process of changing the password being initiated.
167 * @param sender This is the widget which raised the event.
168 */
169
170 public void onClick (final Widget sender) {
171
172 if (sender.equals(SubmitButton)) {
173
174 // Now we need to link the which was entered to the
175 // fault. First we need to check to see if the fault is
176 // actually in the fault database
177
178 if (NewPassword.getText().equals("") || PasswordConfirmation.getText().equals("")) {
179 Window.alert(internationalizationConstants.allFieldsMustBeFilledIn());
180 return;
181 }
182
183 // Verify that both of the passwords are the same
184
185 if (!NewPassword.getText().equals(PasswordConfirmation.getText())) {
186 Window.alert(internationalizationConstants.passwordMismatch());
187 return;
188 }
189
190 // Get the servlet to change the password w
191
192 svc.resetPassword (emailAddress,NewPassword.getText(),new AsyncCallback() {
193
194 public void onSuccess (final Object result) {
195 ChangePasswordDialog.hide();
196 Window.alert(internationalizationConstants.passwordHasBeenUpdated());
197 }
198
199 public void onFailure (Throwable ex) {
200 Window.alert(internationalizationConstants.unableToUpdatePassword());
201 }
202 });
203
204 } else if (sender.equals(CancelButton)) {
205 ChangePasswordDialog.hide();
206 }
207 }
208
209 /**
210 * Displays the dialog which will allow the user to change his
211 * password.
212 */
213
214 public void showChangePasswordDialog () {
215 ChangePasswordDialog.show();
216 ChangePasswordDialog.center();
217 NewPassword.setFocus(true);
218 }
219 }
220