1 package org
.argeo
.security
.ui
.dialogs
;
3 import org
.argeo
.ArgeoException
;
4 import org
.argeo
.security
.CurrentUserService
;
5 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
6 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
7 import org
.eclipse
.swt
.SWT
;
8 import org
.eclipse
.swt
.graphics
.Point
;
9 import org
.eclipse
.swt
.layout
.GridData
;
10 import org
.eclipse
.swt
.layout
.GridLayout
;
11 import org
.eclipse
.swt
.widgets
.Composite
;
12 import org
.eclipse
.swt
.widgets
.Control
;
13 import org
.eclipse
.swt
.widgets
.Label
;
14 import org
.eclipse
.swt
.widgets
.Shell
;
15 import org
.eclipse
.swt
.widgets
.Text
;
17 /** Dialog to change the current user password */
18 public class ChangePasswordDialog
extends TitleAreaDialog
{
19 private Text currentPassword
, newPassword1
, newPassword2
;
20 private CurrentUserService securityService
;
22 public ChangePasswordDialog(Shell parentShell
,
23 CurrentUserService securityService
) {
25 this.securityService
= securityService
;
28 protected Point
getInitialSize() {
29 return new Point(300, 250);
32 protected Control
createDialogArea(Composite parent
) {
33 Composite dialogarea
= (Composite
) super.createDialogArea(parent
);
34 dialogarea
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
35 Composite composite
= new Composite(dialogarea
, SWT
.NONE
);
36 composite
.setLayout(new GridLayout(2, false));
37 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
38 currentPassword
= createLP(composite
, "Current password");
39 newPassword1
= createLP(composite
, "New password");
40 newPassword2
= createLP(composite
, "Repeat new password");
42 setMessage("Change password", IMessageProvider
.INFORMATION
);
48 protected void okPressed() {
49 if (!newPassword1
.getText().equals(newPassword2
.getText()))
50 throw new ArgeoException("Passwords are different");
51 securityService
.updateCurrentUserPassword(currentPassword
.getText(),
52 newPassword1
.getText());
56 /** Creates label and password. */
57 protected Text
createLP(Composite parent
, String label
) {
58 new Label(parent
, SWT
.NONE
).setText(label
);
59 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.PASSWORD
61 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
65 protected void configureShell(Shell shell
) {
66 super.configureShell(shell
);
67 shell
.setText("Change password");