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