1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.ui.section.user;
|
5
|
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.Collection;
|
8
|
|
9
|
import eu.etaxonomy.cdm.model.agent.Person;
|
10
|
import eu.etaxonomy.cdm.model.permission.User;
|
11
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
12
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
13
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
14
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
15
|
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
|
16
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
17
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
18
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
19
|
|
20
|
/**
|
21
|
* @author n.hoffmann
|
22
|
*/
|
23
|
public class UserDetailElement extends AbstractCdmDetailElement<User> {
|
24
|
|
25
|
private TextWithLabelElement text_username;
|
26
|
private TextWithLabelElement text_emailAdress;
|
27
|
private EntitySelectionElement<Person> selection_person;
|
28
|
private CheckboxElement checkbox_credentialsNonExpired;
|
29
|
private CheckboxElement checkbox_enabled;
|
30
|
private CheckboxElement checkbox_accountNonLocked;
|
31
|
private CheckboxElement checkbox_accountNonExpired;
|
32
|
|
33
|
public UserDetailElement(CdmFormFactory formFactory,
|
34
|
ICdmFormElement formElement) {
|
35
|
super(formFactory, formElement);
|
36
|
}
|
37
|
|
38
|
@Override
|
39
|
protected void createControls(ICdmFormElement formElement, User entity,
|
40
|
int style) {
|
41
|
|
42
|
text_username = formFactory.createTextWithLabelElement(formElement,
|
43
|
"Username", entity.getUsername(), style);
|
44
|
// Disabling the text field since the user entity is immutable
|
45
|
text_username.setEnabled(false);
|
46
|
|
47
|
if (userIsAuthenticated() || CdmStore.getLoginManager().isUserManager() || CdmStore.getLoginManager().isAdmin() ) {
|
48
|
formFactory.createEditPasswordElement(
|
49
|
formElement, "Change Password", entity, style);
|
50
|
}
|
51
|
|
52
|
text_emailAdress = formFactory.createTextWithLabelElement(formElement,
|
53
|
"Email Adress", entity.getEmailAddress(), style);
|
54
|
|
55
|
selection_person = formFactory
|
56
|
.createSelectionElement(Person.class,
|
57
|
//getConversationHolder(),
|
58
|
formElement,
|
59
|
"Person",
|
60
|
entity.getPerson(),
|
61
|
EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE,
|
62
|
style);
|
63
|
|
64
|
checkbox_enabled = formFactory.createCheckbox(formElement, "Enabled",
|
65
|
entity.isEnabled(), style);
|
66
|
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public void setEnabled(boolean enabled) {
|
71
|
Collection<Object> except = new ArrayList<Object>();
|
72
|
|
73
|
for(ICdmFormElement formElement:getElements()){
|
74
|
if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
|
75
|
except.add(formElement);
|
76
|
}
|
77
|
}
|
78
|
setEnabled(enabled, except);
|
79
|
}
|
80
|
private boolean userIsAuthenticated() {
|
81
|
return getEntity().equals(
|
82
|
CdmStore.getLoginManager().getAuthenticatedUser());
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public void handleEvent(Object eventSource) {
|
87
|
if (eventSource == text_username) {
|
88
|
getEntity().setUsername(text_username.getText());
|
89
|
} else if (eventSource == text_emailAdress) {
|
90
|
getEntity().setEmailAddress(text_emailAdress.getText());
|
91
|
} else if (eventSource == selection_person) {
|
92
|
getEntity().setPerson(selection_person.getSelection());
|
93
|
} else if (eventSource == checkbox_accountNonExpired) {
|
94
|
getEntity().setAccountNonExpired(
|
95
|
checkbox_accountNonExpired.getSelection());
|
96
|
} else if (eventSource == checkbox_accountNonLocked) {
|
97
|
getEntity().setAccountNonLocked(
|
98
|
checkbox_accountNonLocked.getSelection());
|
99
|
} else if (eventSource == checkbox_enabled) {
|
100
|
getEntity().setEnabled(checkbox_enabled.getSelection());
|
101
|
} else if (eventSource == checkbox_credentialsNonExpired) {
|
102
|
getEntity().setCredentialsNonExpired(
|
103
|
checkbox_credentialsNonExpired.getSelection());
|
104
|
}
|
105
|
}
|
106
|
}
|