(no commit message)
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / user / wizard / UserWizardPage.java
index f432f4658a08f52d7a248027eb621f4251888e9b..1e2b48de526014a728a76d7f838622b7a07b8017 100644 (file)
@@ -11,6 +11,7 @@
 package eu.etaxonomy.taxeditor.user.wizard;
 
 import org.apache.log4j.Logger;
+import org.eclipse.jface.dialogs.IInputValidator;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CLabel;
@@ -34,6 +35,10 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @version 1.0
  */
 public class UserWizardPage extends WizardPage implements ModifyListener{
+       
+       public static final String NAME = "USER_WIZARD_PAGE";
+       
+
        private Composite composite;
        private Text text_username;
        private Text text_oldPassword;
@@ -46,11 +51,14 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
        private Text text_personLastName;
        private Text text_userEmail;
 
+       private IInputValidator uniqueUserNameValidator;
+       private IInputValidator passwordRepetitionEqualityValidator;
+       
        /**
         * @param pageName
         */
        protected UserWizardPage(User user) {
-               super("USER_WIZARD_PAGE");
+               super(NAME);
                
                this.user = user;
                
@@ -62,8 +70,10 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                }else{
                        setTitle("Edit existing user");
                        setDescription("Edit information for the selected user.");
-                       
-               }               
+               }
+
+               uniqueUserNameValidator = new UniqueUserNameValidator();
+               passwordRepetitionEqualityValidator = new PasswordRepetitionEqualityValidator();
        }
 
        private static final Logger logger = Logger.getLogger(UserWizardPage.class);
@@ -101,14 +111,15 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                
                setControl(composite);
                
+               setPageComplete(false);
+               
                init();
        }
 
        private void createPasswordFieldsEdit(Composite parent){
                CLabel label_oldPassword = new CLabel(parent, SWT.NULL);
                label_oldPassword.setText("Old Password");
-               text_oldPassword = new Text(parent, SWT.BORDER);
-               text_oldPassword.setEchoChar('*');
+               text_oldPassword = new Text(parent, SWT.PASSWORD | SWT.BORDER);
                text_oldPassword.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                text_oldPassword.addModifyListener(this);
                
@@ -119,8 +130,7 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
                CLabel label_password = new CLabel(parent, SWT.NULL);
                label_password.setText("Password");
                
-               text_password = new Text(parent, SWT.BORDER);
-               text_password.setEchoChar('*');
+               text_password = new Text(parent, SWT.PASSWORD | SWT.BORDER);
                text_password.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                text_password.addModifyListener(this);
                
@@ -193,4 +203,33 @@ public class UserWizardPage extends WizardPage implements ModifyListener{
        public User getUser() {
                return user;
        }
+       
+       private class UniqueUserNameValidator implements IInputValidator{
+
+               private static final String MESSAGE = "Username already exists";
+               
+               /* (non-Javadoc)
+                * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
+                */
+               public String isValid(String newText) {
+                       // query for username
+                       if( CdmStore.getUserService().loadUserByUsername(newText) != null){
+                               return MESSAGE;
+                       }
+                       
+                       return null;
+               }
+       }
+       
+       private class PasswordRepetitionEqualityValidator implements IInputValidator{
+
+               /* (non-Javadoc)
+                * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
+                */
+               public String isValid(String newText) {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+               
+       }
 }