Project

General

Profile

Download (2.8 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.forms.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.store.CdmStore;
22
import eu.etaxonomy.taxeditor.store.StoreUtil;
23
import eu.etaxonomy.taxeditor.ui.forms.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 User user;
34
	private ConversationHolder conversation;
35
	
36
	public PasswordWizard(ConversationHolder conversation, User user){
37
		this.conversation = conversation;
38
		this.user = user;
39
	}
40
	
41
	/* (non-Javadoc)
42
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
43
	 */
44
	@Override
45
	public void addPages() {
46
		CdmFormFactory formFactory = new CdmFormFactory(Display.getDefault());
47
		
48
//		if(CdmStore.getLoginManager().isAdmin()){
49
//			
50
//		}else{
51
//		}
52
		passwordPage = new PasswordWizardPage(formFactory, getConversationHolder(), user);
53
		addPage(passwordPage);
54
	}
55
	
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
58
	 */
59
	@Override
60
	public boolean performFinish() {
61
		ConversationHolder internalConversation = CdmStore.getLoginManager().getConversationHolder();
62
		internalConversation.bind();
63
		try{
64
			if(CdmStore.getLoginManager().isAdmin()){
65
				CdmStore.getService(IUserService.class).changePasswordForUser(user.getUsername(), passwordPage.getNewPassword());
66
			}else{
67
				CdmStore.getService(IUserService.class).changePassword(passwordPage.getOldPassword(), passwordPage.getNewPassword());
68
			}
69
			internalConversation.commit();
70
			return true;
71
		}catch(Exception e){
72
			StoreUtil.errorDialog("Error while changing password", getClass(), "There was a problem changing the password.", e);
73
			return false;
74
		}finally{
75
			conversation.bind();
76
		}
77
	}
78

    
79
	/* (non-Javadoc)
80
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
81
	 */
82
	@Override
83
	public void update(CdmDataChangeMap arg0) {
84
		// TODO Auto-generated method stub
85
		
86
	}
87

    
88
	/* (non-Javadoc)
89
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
90
	 */
91
	@Override
92
	public ConversationHolder getConversationHolder() {
93
		return conversation;
94
	}
95

    
96
}
(2-2/3)