Revision 6d29f629
Added by Andreas Kohlbecker about 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.vaadin.component.common; |
10 | 10 |
|
11 |
import java.util.Arrays; |
|
11 | 12 |
import java.util.EnumSet; |
12 | 13 |
import java.util.List; |
13 | 14 |
|
... | ... | |
203 | 204 |
titleField.bindTo(fieldGroup, "titleCache", "protectedTitleCache"); |
204 | 205 |
nomenclaturalTitleField.bindTo(fieldGroup, "nomenclaturalTitle", "protectedNomenclaturalTitleCache"); |
205 | 206 |
fieldGroup.setItemDataSource(new BeanItem<Team>((Team)newValue)); |
207 |
boolean readonlyState = personsListEditor.isReadOnly(); |
|
206 | 208 |
fieldGroup.bind(personsListEditor, "teamMembers"); // here personField is set readonly since setTeamMembers does not exist |
207 |
personsListEditor.setReadOnly(false); // fixing the readonly state
|
|
209 |
personsListEditor.setReadOnly(readonlyState); // fixing the readonly state
|
|
208 | 210 |
|
209 | 211 |
personsListEditor.registerParentFieldGroup(fieldGroup); |
210 | 212 |
|
... | ... | |
213 | 215 |
} |
214 | 216 |
|
215 | 217 |
} |
216 |
|
|
218 |
adaptToUserPermissions(newValue); |
|
217 | 219 |
updateToolBarButtonStates(); |
218 | 220 |
} |
219 | 221 |
|
222 |
|
|
223 |
private void adaptToUserPermissions(TeamOrPersonBase teamOrPerson) { |
|
224 |
|
|
225 |
if(teamOrPerson == null){ |
|
226 |
return; |
|
227 |
} |
|
228 |
|
|
229 |
UserHelper userHelper = UserHelper.fromSession(); |
|
230 |
boolean canEdit = userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE); |
|
231 |
if(!canEdit){ |
|
232 |
setContentReadOnly(true); |
|
233 |
} |
|
234 |
} |
|
235 |
|
|
220 | 236 |
private void checkUserPermissions(TeamOrPersonBase<?> newValue) { |
221 | 237 |
boolean userCanEdit = UserHelper.fromSession().userHasPermission(newValue, "DELETE", "UPDATE"); |
222 | 238 |
setEnabled(userCanEdit); |
... | ... | |
346 | 362 |
@Override |
347 | 363 |
public void setReadOnly(boolean readOnly) { |
348 | 364 |
super.setReadOnly(readOnly); |
349 |
setDeepReadOnly(readOnly, getContent()); |
|
365 |
setContentReadOnly(readOnly); |
|
366 |
} |
|
367 |
|
|
368 |
/** |
|
369 |
* Set the nested team or person to read only but keep the state of the <code>TeamOrPersonField</code> untouched so |
|
370 |
* that the <code>removeButton</code>, <code>personButton</code> and <code>teamButton</code> can stay operational. |
|
371 |
* |
|
372 |
* @param readOnly |
|
373 |
*/ |
|
374 |
public void setContentReadOnly(boolean readOnly) { |
|
375 |
setDeepReadOnly(readOnly, getContent(), Arrays.asList(removeButton, personButton, teamButton)); |
|
376 |
updateCaptionReadonlyNotice(); |
|
350 | 377 |
} |
351 | 378 |
|
352 | 379 |
|
Also available in: Unified diff
ref #7366 TeamOrPersonField read only if user lacks editing permissions