Project

General

Profile

Download (3.33 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
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.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.ui.password;
12

    
13
import org.eclipse.jface.wizard.Wizard;
14
import org.eclipse.swt.widgets.Display;
15

    
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;
24

    
25
/**
26
 * @author n.hoffmann
27
 * @created Mar 10, 2011
28
 * @version 1.0
29
 */
30
public class PasswordWizard extends Wizard implements IConversationEnabled{
31

    
32
	private PasswordWizardPage passwordPage;
33
	private final User user;
34
	private final ConversationHolder conversation;
35

    
36
	/**
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
40
	 */
41
	public PasswordWizard(User user, ConversationHolder conversation){
42
		this.conversation = conversation;
43
		this.user = user;
44
	}
45

    
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
48
	 */
49
	@Override
50
	public void addPages() {
51
		CdmFormFactory formFactory = new CdmFormFactory(Display.getDefault());
52

    
53
		passwordPage = new PasswordWizardPage(formFactory, getConversationHolder(), user);
54
		addPage(passwordPage);
55
	}
56

    
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
59
	 */
60
	@Override
61
	public boolean performFinish() {
62

    
63
		ConversationHolder internalConversation = CdmStore.getCurrentApplicationConfiguration().NewConversation();
64
	    internalConversation.bind();
65
	    internalConversation.startTransaction();
66
		try{
67
			if(passwordPage.isChangingOwnPassword()){
68
			    // change own password with validating of old one
69
				CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
70
			}else{
71
			    // change others passwords
72
			    CdmStore.getService(IUserService.class).changePasswordForUser(user.getUsername(), passwordPage.getNewPassword());
73
			}
74
		    internalConversation.commit(false);
75
		    internalConversation.unbind();
76
		    internalConversation.close();
77
			return true;
78
		}catch(Exception e){
79
			MessagingUtils.warningDialog("Could not change password", this, "The old password is not correct.");
80
			//MessagingUtils.messageDialog("Error while changing password", getClass(), "There was a problem changing the password.", e);
81
			return false;
82
		}finally{
83
		    if(conversation != null){
84
		        conversation.bind();
85
		    }
86
		}
87
	}
88

    
89
	/* (non-Javadoc)
90
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
91
	 */
92
	@Override
93
	public void update(CdmDataChangeMap arg0) {
94
		// TODO Auto-generated method stub
95

    
96
	}
97

    
98
	/* (non-Javadoc)
99
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
100
	 */
101
	@Override
102
	public ConversationHolder getConversationHolder() {
103
		return conversation;
104
	}
105

    
106
}
(2-2/3)