3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.password
;
13 import org
.eclipse
.jface
.wizard
.Wizard
;
14 import org
.eclipse
.swt
.widgets
.Display
;
16 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
17 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
18 import eu
.etaxonomy
.cdm
.api
.service
.IUserService
;
19 import eu
.etaxonomy
.cdm
.model
.common
.User
;
20 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
21 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
22 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 * @created Mar 10, 2011
30 public class PasswordWizard
extends Wizard
implements IConversationEnabled
{
32 private PasswordWizardPage passwordPage
;
33 private final User user
;
34 private final ConversationHolder conversation
;
37 * @param user the user to change the password for
38 * @param conversation this optional parameter can be null. Only supply conversation if you
39 * need to run this wizard is a nested conversation
41 public PasswordWizard(User user
, ConversationHolder conversation
){
42 this.conversation
= conversation
;
47 * @see org.eclipse.jface.wizard.Wizard#addPages()
50 public void addPages() {
51 CdmFormFactory formFactory
= new CdmFormFactory(Display
.getDefault());
53 passwordPage
= new PasswordWizardPage(formFactory
, getConversationHolder(), user
);
54 addPage(passwordPage
);
58 * @see org.eclipse.jface.wizard.Wizard#performFinish()
61 public boolean performFinish() {
63 ConversationHolder internalConversation
= CdmStore
.getCurrentApplicationConfiguration().NewConversation();
64 internalConversation
.bind();
65 internalConversation
.startTransaction();
67 if(passwordPage
.isChangingOwnPassword()){
68 // change own password with validating of old one
69 CdmStore
.getService(IUserService
.class).changePassword(passwordPage
.getOldPassword(), passwordPage
.getNewPassword());
71 // change others passwords
72 CdmStore
.getService(IUserService
.class).changePasswordForUser(user
.getUsername(), passwordPage
.getNewPassword());
74 internalConversation
.commit(false);
75 internalConversation
.unbind();
76 internalConversation
.close();
79 MessagingUtils
.warningDialog("Could not change password", this, "The old password is not correct.");
83 if(conversation
!= null){
90 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
93 public void update(CdmDataChangeMap arg0
) {
94 // TODO Auto-generated method stub
99 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
102 public ConversationHolder
getConversationHolder() {