From 35a95f17522d68e3643b4bbb2aafe2eac76e7a60 Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Fri, 15 Aug 2014 15:31:41 +0000 Subject: [PATCH] ApplicationWorkbenchAdvisor : added comments 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 --- .../ApplicationWorkbenchAdvisor.java | 6 +++- .../handler/NewObjectHandler.java | 30 ++++++++++++++++++- .../ui/password/EditPasswordElement.java | 14 ++++++--- .../ui/section/user/UserDetailElement.java | 2 ++ 4 files changed, 46 insertions(+), 6 deletions(-) diff --git a/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java b/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java index cb759ae74..6de492486 100644 --- a/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java +++ b/eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchAdvisor.java @@ -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 * diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/handler/NewObjectHandler.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/handler/NewObjectHandler.java index 77e5606dd..fade7f89b 100644 --- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/handler/NewObjectHandler.java +++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/handler/NewObjectHandler.java @@ -10,9 +10,13 @@ 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()); } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/password/EditPasswordElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/password/EditPasswordElement.java index 63145b223..85df5d02e 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/password/EditPasswordElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/password/EditPasswordElement.java @@ -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) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java index ad14db124..673befb06 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/user/UserDetailElement.java @@ -44,6 +44,8 @@ public class UserDetailElement extends AbstractCdmDetailElement { 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( -- 2.34.1