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
.user
.wizard
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.jface
.dialogs
.IInputValidator
;
15 import org
.eclipse
.jface
.wizard
.WizardPage
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.custom
.CLabel
;
18 import org
.eclipse
.swt
.events
.ModifyEvent
;
19 import org
.eclipse
.swt
.events
.ModifyListener
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Group
;
24 import org
.eclipse
.swt
.widgets
.Text
;
26 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
27 import eu
.etaxonomy
.cdm
.model
.common
.User
;
28 import eu
.etaxonomy
.taxeditor
.model
.CommonHelper
;
29 import eu
.etaxonomy
.taxeditor
.model
.Resources
;
30 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 public class UserWizardPage
extends WizardPage
implements ModifyListener
{
39 public static final String NAME
= "USER_WIZARD_PAGE";
42 private Composite composite
;
43 private Text text_username
;
44 private Text text_oldPassword
;
45 private Text text_password
;
46 private Text text_passwordRepeat
;
48 private boolean newMode
= false;
49 private Group group_person
;
50 private Text text_personFirstName
;
51 private Text text_personLastName
;
52 private Text text_userEmail
;
54 private IInputValidator uniqueUserNameValidator
;
55 private IInputValidator passwordRepetitionEqualityValidator
;
60 protected UserWizardPage(User user
) {
66 setTitle("Create new user");
67 setDescription("Enter information for new user.");
69 this.user
= User
.NewInstance(null, null);
71 setTitle("Edit existing user");
72 setDescription("Edit information for the selected user.");
75 uniqueUserNameValidator
= new UniqueUserNameValidator();
76 passwordRepetitionEqualityValidator
= new PasswordRepetitionEqualityValidator();
79 private static final Logger logger
= Logger
.getLogger(UserWizardPage
.class);
82 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
84 public void createControl(Composite parent
) {
86 composite
= new Composite(parent
, SWT
.NULL
);
87 GridLayout compositeLayout
= new GridLayout();
88 compositeLayout
.numColumns
= 2;
89 composite
.setLayout(compositeLayout
);
90 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
92 CLabel label_username
= new CLabel(composite
, SWT
.NULL
);
93 label_username
.setText("Username");
94 text_username
= new Text(composite
, SWT
.BORDER
);
95 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
96 text_username
.addModifyListener(this);
99 text_username
.setEditable(false);
100 text_username
.setBackground(Resources
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
104 createPasswordFieldsNew(composite
);
105 }else if(CdmStore
.getLoginManager().getAuthenticatedUser().equals(user
)){
106 createPasswordFieldsEdit(composite
);
109 group_person
= createPersonGroup(composite
);
110 group_person
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
112 setControl(composite
);
114 setPageComplete(false);
119 private void createPasswordFieldsEdit(Composite parent
){
120 CLabel label_oldPassword
= new CLabel(parent
, SWT
.NULL
);
121 label_oldPassword
.setText("Old Password");
122 text_oldPassword
= new Text(parent
, SWT
.PASSWORD
| SWT
.BORDER
);
123 text_oldPassword
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
124 text_oldPassword
.addModifyListener(this);
126 createPasswordFieldsNew(parent
);
129 private void createPasswordFieldsNew(Composite parent
){
130 CLabel label_password
= new CLabel(parent
, SWT
.NULL
);
131 label_password
.setText("Password");
133 text_password
= new Text(parent
, SWT
.PASSWORD
| SWT
.BORDER
);
134 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
135 text_password
.addModifyListener(this);
137 new CLabel(parent
, SWT
.NULL
);
138 text_passwordRepeat
= new Text(parent
, SWT
.BORDER
);
139 text_passwordRepeat
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
140 text_passwordRepeat
.setEchoChar('*');
141 text_passwordRepeat
.addModifyListener(this);
144 private Group
createPersonGroup(Composite parent
){
146 Group group
= new Group(parent
, SWT
.NONE
);
147 GridLayout layout
= new GridLayout();
148 layout
.numColumns
= 2;
149 group
.setLayout(layout
);
151 CLabel label_personFirstName
= new CLabel(group
, SWT
.NULL
);
152 label_personFirstName
.setText("First Name");
153 text_personFirstName
= new Text(group
, SWT
.BORDER
);
154 text_personFirstName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
155 text_personFirstName
.addModifyListener(this);
157 CLabel label_personLastName
= new CLabel(group
, SWT
.NULL
);
158 label_personLastName
.setText("Last Name");
159 text_personLastName
= new Text(group
, SWT
.BORDER
);
160 text_personLastName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
161 text_personLastName
.addModifyListener(this);
164 CLabel label_userEmail
= new CLabel(group
, SWT
.NULL
);
165 label_userEmail
.setText("Email");
166 text_userEmail
= new Text(group
, SWT
.BORDER
);
167 text_userEmail
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
168 text_userEmail
.addModifyListener(this);
176 private void init() {
177 CommonHelper
.editTextWithoutTriggeringListeners(text_username
, this, user
.getUsername());
178 if(user
.getPerson() == null){
179 user
.setPerson(Person
.NewInstance());
181 CommonHelper
.editTextWithoutTriggeringListeners(text_personFirstName
, this, user
.getPerson().getFirstname());
182 CommonHelper
.editTextWithoutTriggeringListeners(text_personLastName
, this, user
.getPerson().getLastname());
183 CommonHelper
.editTextWithoutTriggeringListeners(text_userEmail
, this, user
.getEmailAddress());
188 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
190 public void modifyText(ModifyEvent e
) {
192 user
.setUsername(text_username
.getText().trim());
193 user
.setPassword(text_password
.getText());
195 user
.getPerson().setFirstname(text_personFirstName
.getText());
196 user
.getPerson().setLastname(text_personLastName
.getText());
197 user
.setEmailAddress(text_userEmail
.getText());
203 public User
getUser() {
207 private class UniqueUserNameValidator
implements IInputValidator
{
209 private static final String MESSAGE
= "Username already exists";
212 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
214 public String
isValid(String newText
) {
215 // query for username
216 if( CdmStore
.getUserService().loadUserByUsername(newText
) != null){
224 private class PasswordRepetitionEqualityValidator
implements IInputValidator
{
227 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
229 public String
isValid(String newText
) {
230 // TODO Auto-generated method stub