3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.forms
.password
;
13 import org
.eclipse
.jface
.dialogs
.IInputValidator
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.ModifyEvent
;
16 import org
.eclipse
.swt
.events
.ModifyListener
;
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
.api
.service
.IUserService
;
22 import eu
.etaxonomy
.cdm
.model
.common
.User
;
23 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 import eu
.etaxonomy
.taxeditor
.ui
.forms
.AbstractCdmEntityWizardPage
;
25 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
;
26 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TextWithLabelElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
31 * <p>UserWizardPage class.</p>
37 public class PasswordWizardPage
extends AbstractCdmEntityWizardPage
<User
> implements ModifyListener
{
39 /** Constant <code>NAME="USER_WIZARD_PAGE"</code> */
40 public static final String NAME
= "USER_WIZARD_PAGE";
42 private TextWithLabelElement text_oldPassword
;
43 private TextWithLabelElement text_password
;
44 private TextWithLabelElement text_passwordRepeat
;
45 private PasswordValidator passwordValidator
;
52 protected PasswordWizardPage(CdmFormFactory formFactory
,
53 ConversationHolder conversation
, User entity
) {
54 super(formFactory
, conversation
, entity
);
56 passwordValidator
= new PasswordValidator();
60 * @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createControl(org.eclipse.swt.widgets.Composite)
63 public void createControl(Composite parent
) {
64 Composite control
= formFactory
.createComposite(parent
);
65 control
.setLayoutData(CdmFormFactory
.FILL());
67 setPageComplete(false);
69 control
.setLayout(CdmFormFactory
.LAYOUT(2, false));
70 WizardPageRootElement rootElement
= new WizardPageRootElement(formFactory
, control
, getConversationHolder());
72 if(!CdmStore
.getLoginManager().isAdmin()){
73 text_oldPassword
= formFactory
.createTextWithLabelElement(rootElement
, "Old Password", null, SWT
.PASSWORD
);
75 text_password
= formFactory
.createTextWithLabelElement(rootElement
, "New Password", null, SWT
.PASSWORD
);
76 text_passwordRepeat
= formFactory
.createTextWithLabelElement(rootElement
, "Repeat Password", null, SWT
.PASSWORD
);
78 ((Text
)text_passwordRepeat
.getMainControl()).addModifyListener(this);
85 * @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createElement(eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement)
88 public AbstractCdmDetailElement
<User
> createElement(
89 ICdmFormElement rootElement
) {
95 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
98 public void modifyText(ModifyEvent e
) {
102 private void validate(){
105 if((message
= passwordValidator
.passwordsMatch(text_password
.getText(), text_passwordRepeat
.getText())) != null){
108 else if((message
= passwordValidator
.isValid(text_password
.getText())) != null){
112 setErrorMessage(message
);
115 private class UniqueUserNameValidator
implements IInputValidator
{
117 private static final String USER_EXISTS
= "Username already exists";
118 private static final String NAME_TO_SHORT
= "Username is empty";
121 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
123 public String
isValid(String newText
) {
124 // query for username
125 if(newText
.length() < 1){
126 setPageComplete(false);
127 return NAME_TO_SHORT
;
129 if(CdmStore
.getService(IUserService
.class).userExists(newText
)){
130 setPageComplete(false);
134 setPageComplete(true);
139 private class PasswordValidator
implements IInputValidator
{
141 private static final int PW_MIN_LENGTH
= 5;
143 private static final String TO_SHORT
= "Password has to have at least " + PW_MIN_LENGTH
+ " characters";
144 private static final String NO_MATCH
= "The passwords do not match";
147 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
149 public String
isValid(String newText
) {
150 if(newText
.length() < PW_MIN_LENGTH
){
151 setPageComplete(false);
155 setPageComplete(true);
159 public String
passwordsMatch(String password1
, String password2
){
161 if(! password1
.equals(password2
)){
162 setPageComplete(false);
166 setPageComplete(true);
175 public String
getOldPassword() {
176 return text_oldPassword
.getText();
182 public String
getNewPassword() {
183 return text_password
.getText();