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
.wizard
.WizardPage
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.custom
.CLabel
;
17 import org
.eclipse
.swt
.events
.ModifyEvent
;
18 import org
.eclipse
.swt
.events
.ModifyListener
;
19 import org
.eclipse
.swt
.layout
.GridData
;
20 import org
.eclipse
.swt
.layout
.GridLayout
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Group
;
23 import org
.eclipse
.swt
.widgets
.Text
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
26 import eu
.etaxonomy
.cdm
.model
.common
.User
;
27 import eu
.etaxonomy
.taxeditor
.model
.CommonHelper
;
28 import eu
.etaxonomy
.taxeditor
.model
.Resources
;
29 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
36 public class UserWizardPage
extends WizardPage
implements ModifyListener
{
37 private Composite composite
;
38 private Text text_username
;
39 private Text text_oldPassword
;
40 private Text text_password
;
41 private Text text_passwordRepeat
;
43 private boolean newMode
= false;
44 private Group group_person
;
45 private Text text_personFirstName
;
46 private Text text_personLastName
;
47 private Text text_userEmail
;
52 protected UserWizardPage(User user
) {
53 super("USER_WIZARD_PAGE");
58 setTitle("Create new user");
59 setDescription("Enter information for new user.");
61 this.user
= User
.NewInstance(null, null);
63 setTitle("Edit existing user");
64 setDescription("Edit information for the selected user.");
69 private static final Logger logger
= Logger
.getLogger(UserWizardPage
.class);
72 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
74 public void createControl(Composite parent
) {
76 composite
= new Composite(parent
, SWT
.NULL
);
77 GridLayout compositeLayout
= new GridLayout();
78 compositeLayout
.numColumns
= 2;
79 composite
.setLayout(compositeLayout
);
80 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
82 CLabel label_username
= new CLabel(composite
, SWT
.NULL
);
83 label_username
.setText("Username");
84 text_username
= new Text(composite
, SWT
.BORDER
);
85 text_username
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
86 text_username
.addModifyListener(this);
89 text_username
.setEditable(false);
90 text_username
.setBackground(Resources
.getColor(Resources
.SEARCH_VIEW_FOREGROUND
));
94 createPasswordFieldsNew(composite
);
95 }else if(CdmStore
.getLoginManager().getAuthenticatedUser().equals(user
)){
96 createPasswordFieldsEdit(composite
);
99 group_person
= createPersonGroup(composite
);
100 group_person
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false, 2, 1));
102 setControl(composite
);
107 private void createPasswordFieldsEdit(Composite parent
){
108 CLabel label_oldPassword
= new CLabel(parent
, SWT
.NULL
);
109 label_oldPassword
.setText("Old Password");
110 text_oldPassword
= new Text(parent
, SWT
.BORDER
);
111 text_oldPassword
.setEchoChar('*');
112 text_oldPassword
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
113 text_oldPassword
.addModifyListener(this);
115 createPasswordFieldsNew(parent
);
118 private void createPasswordFieldsNew(Composite parent
){
119 CLabel label_password
= new CLabel(parent
, SWT
.NULL
);
120 label_password
.setText("Password");
122 text_password
= new Text(parent
, SWT
.BORDER
);
123 text_password
.setEchoChar('*');
124 text_password
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
125 text_password
.addModifyListener(this);
127 new CLabel(parent
, SWT
.NULL
);
128 text_passwordRepeat
= new Text(parent
, SWT
.BORDER
);
129 text_passwordRepeat
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, false));
130 text_passwordRepeat
.setEchoChar('*');
131 text_passwordRepeat
.addModifyListener(this);
134 private Group
createPersonGroup(Composite parent
){
136 Group group
= new Group(parent
, SWT
.NONE
);
137 GridLayout layout
= new GridLayout();
138 layout
.numColumns
= 2;
139 group
.setLayout(layout
);
141 CLabel label_personFirstName
= new CLabel(group
, SWT
.NULL
);
142 label_personFirstName
.setText("First Name");
143 text_personFirstName
= new Text(group
, SWT
.BORDER
);
144 text_personFirstName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
145 text_personFirstName
.addModifyListener(this);
147 CLabel label_personLastName
= new CLabel(group
, SWT
.NULL
);
148 label_personLastName
.setText("Last Name");
149 text_personLastName
= new Text(group
, SWT
.BORDER
);
150 text_personLastName
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
151 text_personLastName
.addModifyListener(this);
154 CLabel label_userEmail
= new CLabel(group
, SWT
.NULL
);
155 label_userEmail
.setText("Email");
156 text_userEmail
= new Text(group
, SWT
.BORDER
);
157 text_userEmail
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
158 text_userEmail
.addModifyListener(this);
166 private void init() {
167 CommonHelper
.editTextWithoutTriggeringListeners(text_username
, this, user
.getUsername());
168 if(user
.getPerson() == null){
169 user
.setPerson(Person
.NewInstance());
171 CommonHelper
.editTextWithoutTriggeringListeners(text_personFirstName
, this, user
.getPerson().getFirstname());
172 CommonHelper
.editTextWithoutTriggeringListeners(text_personLastName
, this, user
.getPerson().getLastname());
173 CommonHelper
.editTextWithoutTriggeringListeners(text_userEmail
, this, user
.getEmailAddress());
178 * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
180 public void modifyText(ModifyEvent e
) {
182 user
.setUsername(text_username
.getText().trim());
183 user
.setPassword(text_password
.getText());
185 user
.getPerson().setFirstname(text_personFirstName
.getText());
186 user
.getPerson().setLastname(text_personLastName
.getText());
187 user
.setEmailAddress(text_userEmail
.getText());
193 public User
getUser() {