2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
.dialogs
;
18 import org
.argeo
.ArgeoException
;
19 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.graphics
.Point
;
24 import org
.eclipse
.swt
.layout
.GridData
;
25 import org
.eclipse
.swt
.layout
.GridLayout
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Control
;
28 import org
.eclipse
.swt
.widgets
.Label
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
30 import org
.eclipse
.swt
.widgets
.Text
;
31 import org
.springframework
.security
.userdetails
.UserDetailsManager
;
33 /** Dialog to change the current user password */
34 public class ChangePasswordDialog
extends TitleAreaDialog
{
35 private static final long serialVersionUID
= -2447446550246803237L;
37 private Text currentPassword
, newPassword1
, newPassword2
;
38 private UserDetailsManager userDetailsManager
;
40 public ChangePasswordDialog(Shell parentShell
,
41 UserDetailsManager securityService
) {
43 this.userDetailsManager
= securityService
;
46 protected Point
getInitialSize() {
47 return new Point(400, 450);
50 protected Control
createDialogArea(Composite parent
) {
51 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
52 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
53 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
54 composite
.setLayout(new GridLayout(2, false));
55 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
56 currentPassword
= createLP(composite
, "Current password");
57 newPassword1
= createLP(composite
, "New password");
58 newPassword2
= createLP(composite
, "Repeat new password");
60 setMessage("Change password", IMessageProvider
.INFORMATION
);
66 protected void okPressed() {
67 if (!newPassword1
.getText().equals(newPassword2
.getText()))
68 throw new ArgeoException("Passwords are different");
70 userDetailsManager
.changePassword(currentPassword
.getText(),
71 newPassword1
.getText());
73 } catch (Exception e
) {
74 MessageDialog
.openError(newPassword1
.getShell(), "Error",
75 "Cannot change password");
80 /** Creates label and password. */
81 protected Text
createLP(Composite parent
, String label
) {
82 new Label(parent
, SWT
.NONE
).setText(label
);
83 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.PASSWORD
85 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
89 protected void configureShell(Shell shell
) {
90 super.configureShell(shell
);
91 shell
.setText("Change password");