2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.password
;
12 import org
.eclipse
.jface
.dialogs
.IInputValidator
;
13 import org
.eclipse
.swt
.SWT
;
14 import org
.eclipse
.swt
.events
.ModifyEvent
;
15 import org
.eclipse
.swt
.events
.ModifyListener
;
16 import org
.eclipse
.swt
.graphics
.Color
;
17 import org
.eclipse
.swt
.widgets
.Composite
;
18 import org
.eclipse
.swt
.widgets
.Text
;
20 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
21 import eu
.etaxonomy
.cdm
.model
.common
.User
;
22 import eu
.etaxonomy
.taxeditor
.Messages
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractCdmEntityWizardPage
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
36 public class PasswordWizardPage
extends AbstractCdmEntityWizardPage
<User
> implements ModifyListener
{
38 private TextWithLabelElement text_oldPassword
;
39 private TextWithLabelElement text_password
;
40 private TextWithLabelElement text_passwordRepeat
;
41 private final PasswordValidator passwordValidator
;
43 protected PasswordWizardPage(CdmFormFactory formFactory
,
44 ConversationHolder conversation
, User entity
) {
45 super(formFactory
, conversation
, entity
);
47 passwordValidator
= new PasswordValidator();
49 setTitle(Messages
.PasswordWizardPage_CHANGE_PASSWORD
);
50 setDescription(Messages
.PasswordWizardPage_CHANGE_PASSWORD_AND_CONFIRM
);
54 public void createControl(Composite parent
) {
55 Composite control
= formFactory
.createComposite(parent
);
56 control
.setLayoutData(LayoutConstants
.FILL());
58 setPageComplete(false);
60 control
.setLayout(LayoutConstants
.LAYOUT(2, false));
61 WizardPageRootElement rootElement
= new WizardPageRootElement(formFactory
, control
, getConversationHolder());
63 if(isChangingOwnPassword()) {
64 text_oldPassword
= formFactory
.createTextWithLabelElement(rootElement
, Messages
.PasswordWizardPage_OLD_PASSWORD
, null, SWT
.PASSWORD
);
66 text_password
= formFactory
.createTextWithLabelElement(rootElement
, Messages
.PasswordWizardPage_NEW_PASSWORD
, null, SWT
.PASSWORD
);
67 text_passwordRepeat
= formFactory
.createTextWithLabelElement(rootElement
, Messages
.PasswordWizardPage_REPEAT_PASSWORD
, null, SWT
.PASSWORD
);
69 ((Text
)text_passwordRepeat
.getMainControl()).addModifyListener(this);
71 Color bgColor
= getShell().getBackground();
72 rootElement
.setBackground(bgColor
);
73 control
.setBackground(bgColor
);
77 protected boolean isChangingOwnPassword() {
78 return getEntity() != null && getEntity().getUsername().equals(CdmStore
.getCurrentAuthentiation().getName());
83 public AbstractCdmDetailElement
<User
> createElement(
84 ICdmFormElement rootElement
) {
91 public void modifyText(ModifyEvent e
) {
95 private void validate(){
98 if((message
= passwordValidator
.passwordsMatch(text_password
.getText(), text_passwordRepeat
.getText())) != null){
101 else if((message
= passwordValidator
.isValid(text_password
.getText())) != null){
105 setErrorMessage(message
);
108 private class PasswordValidator
implements IInputValidator
{
110 private final int PW_MIN_LENGTH
= 5;
112 private final String TO_SHORT
= String
.format(Messages
.PasswordWizardPage_PASSWORD_MIN_CHARACTER
, PW_MIN_LENGTH
);
113 private final String NO_MATCH
= Messages
.PasswordWizardPage_PASSWORDS_DO_NOT_MATCH
;
116 public String
isValid(String newText
) {
117 if(newText
.length() < PW_MIN_LENGTH
){
118 setPageComplete(false);
122 setPageComplete(true);
126 public String
passwordsMatch(String password1
, String password2
){
128 if(! password1
.equals(password2
)){
129 setPageComplete(false);
133 setPageComplete(true);
139 public String
getOldPassword() {
140 return text_oldPassword
.getText();
143 public String
getNewPassword() {
144 return text_password
.getText();