ApplicationWorkbenchAdvisor : added comments
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 15 Aug 2014 15:31:41 +0000 (15:31 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 15 Aug 2014 15:31:41 +0000 (15:31 +0000)
EditPasswordElement : Added to make sure user exists in db before changing password
UserDetailElement : Disabled user text field since User is immutable
NewObjectHandler : added non-empty validator for the case of User and Group

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/handler/NewObjectHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/password/EditPasswordElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java

index cb759ae747aee5b97b7471cbc05cc2a9a151d05d..6de492486c1fbff9f58e26dd7894e0e8fa334e64 100644 (file)
@@ -133,7 +133,11 @@ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
 
        /**
         * Custom status handler for handling scenarios which are 
-        * not handled by the editor (e.g. runtime exceptions)
+        * not handled by the editor (e.g. runtime exceptions).
+        * 
+        * The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler}
+        * is not used or extended because we need a handler for specific scenarios
+        * which displays a custom built error dialog.
         * 
         * @author cmathew
         *
index 77e5606dd93f109a5cd2bb71127a99f31227aed7..fade7f89bf3e898a9ae0b5d487cbfaefdb3e8d52 100644 (file)
 
 package eu.etaxonomy.taxeditor.annotatedlineeditor.handler;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.IInputValidator;
 import org.eclipse.jface.dialogs.InputDialog;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Event;
@@ -47,7 +51,31 @@ public class NewObjectHandler extends AbstractHandler {
                        if (key != null) {
                                if(!(key instanceof SpecimenOrObservationType)) {
                                        String text = ((Event)event.getTrigger()).text; 
-                                       InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event), "Create " + text, "Enter new " + text, "", null); 
+                                       
+                                       //FIXME : This should probably go into some ValidatorFactory
+                                       IInputValidator nonEmptyInputValidator = null;
+                                       //FIXME : This is a workaround to not allow empty strings in the 
+                                       //        input dialog for User and Group entities. 
+                                       //        Normally this should be default
+                                       //        behaviour, so we need to discuss whether this handler
+                                       //        should be used to handle the creating new entities of
+                                       //        type other than User and Group.
+                                       //        Once #4348 is fixed this check can be removed.
+                                       if(text.equals("User") || text.equals("Group")) {
+                                               nonEmptyInputValidator = new IInputValidator() {
+                                                       public String isValid(String text) {                                                    
+                                                               if(text == null || text.isEmpty()) {
+                                                                       return "Input cannot be empty";
+                                                               }
+                                                               return null;
+                                                       }                       
+                                               };
+                                       }
+                                       InputDialog dialog = new InputDialog(HandlerUtil.getActiveShell(event), 
+                                                       "Create " + text, 
+                                                       "Enter new " + text, "",
+                                                       nonEmptyInputValidator); 
+
                                        if (dialog.open() != Window.CANCEL) { 
                                                ((AnnotatedLineEditor) editor).createAnnotatedLineNewObject(key, dialog.getValue()); 
                                        }
index 63145b223c6b6c754c58ca9561c9e8d7847750b3..85df5d02ef7c05b7b6888661e6e1a4229683dbae 100644 (file)
@@ -19,8 +19,11 @@ import org.eclipse.swt.widgets.Label;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.IUserService;
 import eu.etaxonomy.cdm.model.common.User;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -66,10 +69,13 @@ public class EditPasswordElement extends AbstractCdmFormElement implements Selec
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
-               PasswordWizard wizard = new PasswordWizard(user, conversation);
-               WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
-               
-               dialog.open();
+               if(!CdmStore.getService(IUserService.class).userExists(user.getUsername())) {
+                       MessagingUtils.warningDialog("Username does not exist", this, "Please create or save user '" + user.getUsername() + "' before changing password");
+               } else {
+                       PasswordWizard wizard = new PasswordWizard(user, conversation);
+                       WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);                
+                       dialog.open();
+               }
        }
 
        /* (non-Javadoc)
index ad14db124aaa8cbd95178152583c78e3c9411297..673befb06c6497402ec0828738f1e111aec875e8 100644 (file)
@@ -44,6 +44,8 @@ public class UserDetailElement extends AbstractCdmDetailElement<User> {
                        int style) {
                text_username = formFactory.createTextWithLabelElement(formElement,
                                "Username", entity.getUsername(), style);
+               // Disabling the text field since the user entity is immutable
+               text_username.setEnabled(false);
 
                if (userIsAuthenticated() || CdmStore.getLoginManager().isAdmin()) {
                        formFactory.createEditPasswordElement(