-// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
-import eu.etaxonomy.cdm.api.service.IUserService;
import eu.etaxonomy.cdm.model.common.User;
+import eu.etaxonomy.taxeditor.l10n.Messages;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmEntityWizardPage;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
/**
- * <p>UserWizardPage class.</p>
- *
* @author n.hoffmann
* @created 02.07.2009
* @version 1.0
*/
public class PasswordWizardPage extends AbstractCdmEntityWizardPage<User> implements ModifyListener{
- /** Constant <code>NAME="USER_WIZARD_PAGE"</code> */
- public static final String NAME = "USER_WIZARD_PAGE";
-
private TextWithLabelElement text_oldPassword;
private TextWithLabelElement text_password;
private TextWithLabelElement text_passwordRepeat;
- private PasswordValidator passwordValidator;
+ private final PasswordValidator passwordValidator;
- private UniqueUserNameValidator uniqueUsernameValidator;
-
- /**
- * @param formFactory
- * @param conversation
- * @param entity
- */
protected PasswordWizardPage(CdmFormFactory formFactory,
ConversationHolder conversation, User entity) {
super(formFactory, conversation, entity);
-
+
passwordValidator = new PasswordValidator();
- uniqueUsernameValidator = new UniqueUserNameValidator();
+
+ setTitle(Messages.PasswordWizardPage_CHANGE_PASSWORD);
+ setDescription(Messages.PasswordWizardPage_CHANGE_PASSWORD_AND_CONFIRM);
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createControl(org.eclipse.swt.widgets.Composite)
- */
@Override
public void createControl(Composite parent) {
Composite control = formFactory.createComposite(parent);
control.setLayoutData(LayoutConstants.FILL());
-
+
setPageComplete(false);
-
+
control.setLayout(LayoutConstants.LAYOUT(2, false));
WizardPageRootElement rootElement = new WizardPageRootElement(formFactory, control, getConversationHolder());
-
- if(!CdmStore.getLoginManager().isAdmin()){
- text_oldPassword = formFactory.createTextWithLabelElement(rootElement, "Old Password", null, SWT.PASSWORD);
+
+ if(isChangingOwnPassword()) {
+ text_oldPassword = formFactory.createTextWithLabelElement(rootElement, Messages.PasswordWizardPage_OLD_PASSWORD, null, SWT.PASSWORD);
}
- text_password = formFactory.createTextWithLabelElement(rootElement, "New Password", null, SWT.PASSWORD);
- text_passwordRepeat = formFactory.createTextWithLabelElement(rootElement, "Repeat Password", null, SWT.PASSWORD);
-
+ text_password = formFactory.createTextWithLabelElement(rootElement, Messages.PasswordWizardPage_NEW_PASSWORD, null, SWT.PASSWORD);
+ text_passwordRepeat = formFactory.createTextWithLabelElement(rootElement, Messages.PasswordWizardPage_REPEAT_PASSWORD, null, SWT.PASSWORD);
+
((Text)text_passwordRepeat.getMainControl()).addModifyListener(this);
-
+
+ Color bgColor = getShell().getBackground();
+ rootElement.setBackground(bgColor);
+ control.setBackground(bgColor);
setControl(control);
}
-
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.ui.forms.AbstractCdmEntityWizardPage#createElement(eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement)
- */
+
+ protected boolean isChangingOwnPassword() {
+ return getEntity() != null && getEntity().getUsername().equals(CdmStore.getCurrentAuthentiation().getName());
+ }
+
+
@Override
public AbstractCdmDetailElement<User> createElement(
ICdmFormElement rootElement) {
// not used
return null;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
+
/** {@inheritDoc} */
- public void modifyText(ModifyEvent e) {
+ @Override
+ public void modifyText(ModifyEvent e) {
validate();
}
-
+
private void validate(){
String message;
-
+
if((message = passwordValidator.passwordsMatch(text_password.getText(), text_passwordRepeat.getText())) != null){
// pass
}
else if((message = passwordValidator.isValid(text_password.getText())) != null){
// pass
}
-
- setErrorMessage(message);
- }
-
- private class UniqueUserNameValidator implements IInputValidator{
-
- private static final String USER_EXISTS = "Username already exists";
- private static final String NAME_TO_SHORT = "Username is empty";
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
- */
- public String isValid(String newText) {
- // query for username
- if(newText.length() < 1){
- setPageComplete(false);
- return NAME_TO_SHORT;
- }
- if(CdmStore.getService(IUserService.class).userExists(newText)){
- setPageComplete(false);
- return USER_EXISTS;
- }
-
- setPageComplete(true);
- return null;
- }
+
+ setErrorMessage(message);
}
-
+
private class PasswordValidator implements IInputValidator{
- private static final int PW_MIN_LENGTH = 5;
-
- private static final String TO_SHORT = "Password has to have at least " + PW_MIN_LENGTH + " characters";
- private static final String NO_MATCH = "The passwords do not match";
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
- */
- public String isValid(String newText) {
+ private final int PW_MIN_LENGTH = 5;
+
+ private final String TO_SHORT = String.format(Messages.PasswordWizardPage_PASSWORD_MIN_CHARACTER, PW_MIN_LENGTH);
+ private final String NO_MATCH = Messages.PasswordWizardPage_PASSWORDS_DO_NOT_MATCH;
+
+ @Override
+ public String isValid(String newText) {
if(newText.length() < PW_MIN_LENGTH){
setPageComplete(false);
return TO_SHORT;
}
-
+
setPageComplete(true);
return null;
}
-
+
public String passwordsMatch(String password1, String password2){
if(! password1.equals(password2)){
setPageComplete(false);
return NO_MATCH;
}
-
+
setPageComplete(true);
return null;
}
-
+
}
- /**
- * @return
- */
public String getOldPassword() {
return text_oldPassword.getText();
}
- /**
- * @return
- */
public String getNewPassword() {
return text_password.getText();
}