Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / password / EditPasswordElement.java
index b3a720b6aab187e5c823e133c6cf85bac2c2ac16..c26c709590b77eb82e6dca1cd438e1a533528f1e 100644 (file)
@@ -1,9 +1,8 @@
-// $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.
 */
@@ -19,11 +18,15 @@ 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.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+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;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 
 /**
@@ -37,56 +40,43 @@ public class EditPasswordElement extends AbstractCdmFormElement implements Selec
        private Button button;
 
        private ConversationHolder conversation;
-       
-       /**
-        * @param formFactory
-        * @param formElement
-        */
+
        public EditPasswordElement(CdmFormFactory formFactory,
                        ICdmFormElement formElement, String labelString, User user, ConversationHolder conversation) {
                super(formFactory, formElement);
-               
+
                this.conversation = conversation;
                this.user = user;
-               
+
                Label label = formFactory.createLabel(getLayoutComposite(), null);
                addControl(label);
-               
-               String buttonLabelString = (labelString != null) ? labelString : "Change Password";
-               
+
+               String buttonLabelString = (labelString != null) ? labelString : Messages.PasswordWizardPage_CHANGE_PASSWORD;
+
                button = formFactory.createButton(getLayoutComposite(), buttonLabelString, SWT.PUSH);
                button.setLayoutData(LayoutConstants.RIGHT());
                addControl(button);
-               
+
                button.addSelectionListener(this);
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
-        */
        @Override
        public void widgetSelected(SelectionEvent e) {
-               PasswordWizard wizard = new PasswordWizard(conversation, user);
-               WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
-               
-               dialog.open();
+               if(!CdmStore.getService(IUserService.class).userExists(user.getUsername())) {
+                       MessagingUtils.warningDialog(Messages.EditPasswordElement_USERNAME_DOES_NOT_EXIST, this, String.format(Messages.EditPasswordElement_PLEASE_CREATE_OR_SAVE_USER, user.getUsername()));
+               } else {
+                       PasswordWizard wizard = new PasswordWizard(user, conversation);
+                       WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
+                       dialog.open();
+               }
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
-        */
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {}
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
-        */
        @Override
        public void update(CdmDataChangeMap arg0) {}
 
-       /* (non-Javadoc)
-        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
-        */
        @Override
        public ConversationHolder getConversationHolder() {
                return conversation;