8234ee2834a3f1d6d95b88d715c013372c1dc9c0
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / password / EditPasswordElement.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.password;
11
12 import org.eclipse.jface.wizard.WizardDialog;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Label;
18
19 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
21 import eu.etaxonomy.cdm.api.service.IUserService;
22 import eu.etaxonomy.cdm.model.common.User;
23 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
24 import eu.etaxonomy.taxeditor.Messages;
25 import eu.etaxonomy.taxeditor.model.MessagingUtils;
26 import eu.etaxonomy.taxeditor.store.CdmStore;
27 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
28 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
30 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
31
32 /**
33 * @author n.hoffmann
34 * @created Mar 10, 2011
35 * @version 1.0
36 */
37 public class EditPasswordElement extends AbstractCdmFormElement implements SelectionListener, IConversationEnabled{
38
39 private User user;
40 private Button button;
41
42 private ConversationHolder conversation;
43
44 public EditPasswordElement(CdmFormFactory formFactory,
45 ICdmFormElement formElement, String labelString, User user, ConversationHolder conversation) {
46 super(formFactory, formElement);
47
48 this.conversation = conversation;
49 this.user = user;
50
51 Label label = formFactory.createLabel(getLayoutComposite(), null);
52 addControl(label);
53
54 String buttonLabelString = (labelString != null) ? labelString : Messages.PasswordWizardPage_CHANGE_PASSWORD;
55
56 button = formFactory.createButton(getLayoutComposite(), buttonLabelString, SWT.PUSH);
57 button.setLayoutData(LayoutConstants.RIGHT());
58 addControl(button);
59
60 button.addSelectionListener(this);
61 }
62
63 @Override
64 public void widgetSelected(SelectionEvent e) {
65 if(!CdmStore.getService(IUserService.class).userExists(user.getUsername())) {
66 MessagingUtils.warningDialog(Messages.EditPasswordElement_USERNAME_DOES_NOT_EXIST, this, String.format(Messages.EditPasswordElement_PLEASE_CREATE_OR_SAVE_USER, user.getUsername()));
67 } else {
68 PasswordWizard wizard = new PasswordWizard(user, conversation);
69 WizardDialog dialog = new WizardDialog(getLayoutComposite().getShell(), wizard);
70 dialog.open();
71 }
72 }
73
74 @Override
75 public void widgetDefaultSelected(SelectionEvent e) {}
76
77 @Override
78 public void update(CdmDataChangeMap arg0) {}
79
80 @Override
81 public ConversationHolder getConversationHolder() {
82 return conversation;
83 }
84
85
86 }