1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.forms.password;
|
12
|
|
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;
|
19
|
|
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.singlesource.ui.forms.CdmFormFactoryFacade;
|
24
|
import eu.etaxonomy.taxeditor.singlesource.ui.forms.TextWithLabelElementFacade;
|
25
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
26
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage;
|
27
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
29
|
|
30
|
/**
|
31
|
* <p>UserWizardPage class.</p>
|
32
|
*
|
33
|
* @author n.hoffmann
|
34
|
* @created 02.07.2009
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
public class PasswordWizardPage extends AbstractCdmEntityWizardPage<User> implements ModifyListener{
|
38
|
|
39
|
/** Constant <code>NAME="USER_WIZARD_PAGE"</code> */
|
40
|
public static final String NAME = "USER_WIZARD_PAGE";
|
41
|
|
42
|
private TextWithLabelElementFacade text_oldPassword;
|
43
|
private TextWithLabelElementFacade text_password;
|
44
|
private TextWithLabelElementFacade text_passwordRepeat;
|
45
|
private PasswordValidator passwordValidator;
|
46
|
|
47
|
/**
|
48
|
* @param formFactory
|
49
|
* @param conversation
|
50
|
* @param entity
|
51
|
*/
|
52
|
protected PasswordWizardPage(CdmFormFactoryFacade formFactory,
|
53
|
ConversationHolder conversation, User entity) {
|
54
|
super(formFactory, conversation, entity);
|
55
|
|
56
|
passwordValidator = new PasswordValidator();
|
57
|
}
|
58
|
|
59
|
/* (non-Javadoc)
|
60
|
* @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createControl(org.eclipse.swt.widgets.Composite)
|
61
|
*/
|
62
|
@Override
|
63
|
public void createControl(Composite parent) {
|
64
|
Composite control = formFactory.createComposite(parent);
|
65
|
control.setLayoutData(CdmFormFactoryFacade.FILL());
|
66
|
|
67
|
setPageComplete(false);
|
68
|
|
69
|
control.setLayout(CdmFormFactoryFacade.LAYOUT(2, false));
|
70
|
WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder());
|
71
|
|
72
|
text_oldPassword = formFactory.createTextWithLabelElement(rootElement, "Old Password", null, SWT.PASSWORD);
|
73
|
|
74
|
text_password = formFactory.createTextWithLabelElement(rootElement, "New Password", null, SWT.PASSWORD);
|
75
|
text_passwordRepeat = formFactory.createTextWithLabelElement(rootElement, "Repeat Password", null, SWT.PASSWORD);
|
76
|
|
77
|
((Text)text_passwordRepeat.getMainControl()).addModifyListener(this);
|
78
|
|
79
|
setControl(control);
|
80
|
}
|
81
|
|
82
|
|
83
|
/* (non-Javadoc)
|
84
|
* @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createElement(eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement)
|
85
|
*/
|
86
|
@Override
|
87
|
public AbstractCdmDetailElement<User> createElement(
|
88
|
ICdmFormElement rootElement) {
|
89
|
// not used
|
90
|
return null;
|
91
|
}
|
92
|
|
93
|
/* (non-Javadoc)
|
94
|
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
|
95
|
*/
|
96
|
/** {@inheritDoc} */
|
97
|
public void modifyText(ModifyEvent e) {
|
98
|
validate();
|
99
|
}
|
100
|
|
101
|
private void validate(){
|
102
|
String message;
|
103
|
|
104
|
if((message = passwordValidator.passwordsMatch(text_password.getText(), text_passwordRepeat.getText())) != null){
|
105
|
// pass
|
106
|
}
|
107
|
else if((message = passwordValidator.isValid(text_password.getText())) != null){
|
108
|
// pass
|
109
|
}
|
110
|
|
111
|
setErrorMessage(message);
|
112
|
}
|
113
|
|
114
|
private class UniqueUserNameValidator implements IInputValidator{
|
115
|
|
116
|
private static final String USER_EXISTS = "Username already exists";
|
117
|
private static final String NAME_TO_SHORT = "Username is empty";
|
118
|
|
119
|
/* (non-Javadoc)
|
120
|
* @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
|
121
|
*/
|
122
|
public String isValid(String newText) {
|
123
|
// query for username
|
124
|
if(newText.length() < 1){
|
125
|
setPageComplete(false);
|
126
|
return NAME_TO_SHORT;
|
127
|
}
|
128
|
if(CdmStore.getService(IUserService.class).userExists(newText)){
|
129
|
setPageComplete(false);
|
130
|
return USER_EXISTS;
|
131
|
}
|
132
|
|
133
|
setPageComplete(true);
|
134
|
return null;
|
135
|
}
|
136
|
}
|
137
|
|
138
|
private class PasswordValidator implements IInputValidator{
|
139
|
|
140
|
private static final int PW_MIN_LENGTH = 5;
|
141
|
|
142
|
private static final String TO_SHORT = "Password has to have at least " + PW_MIN_LENGTH + " characters";
|
143
|
private static final String NO_MATCH = "The passwords do not match";
|
144
|
|
145
|
/* (non-Javadoc)
|
146
|
* @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
|
147
|
*/
|
148
|
public String isValid(String newText) {
|
149
|
if(newText.length() < PW_MIN_LENGTH){
|
150
|
setPageComplete(false);
|
151
|
return TO_SHORT;
|
152
|
}
|
153
|
|
154
|
setPageComplete(true);
|
155
|
return null;
|
156
|
}
|
157
|
|
158
|
public String passwordsMatch(String password1, String password2){
|
159
|
|
160
|
if(! password1.equals(password2)){
|
161
|
setPageComplete(false);
|
162
|
return NO_MATCH;
|
163
|
}
|
164
|
|
165
|
setPageComplete(true);
|
166
|
return null;
|
167
|
}
|
168
|
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* @return
|
173
|
*/
|
174
|
public String getOldPassword() {
|
175
|
return text_oldPassword.getText();
|
176
|
}
|
177
|
|
178
|
/**
|
179
|
* @return
|
180
|
*/
|
181
|
public String getNewPassword() {
|
182
|
return text_password.getText();
|
183
|
}
|
184
|
}
|