Revision fbae3d00
Added by Andreas Kohlbecker almost 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/PersonField.java | ||
---|---|---|
135 | 135 |
* |
136 | 136 |
*/ |
137 | 137 |
private void checkUserPermissions(Person newValue) { |
138 |
boolean userCanEdit = UserHelper.fromSession().userHasPermission(newValue, "DELETE", "UPDATE"); |
|
139 |
boolean isUnsavedEnitity = newValue.getId() == 0; |
|
140 |
setEnabled(isUnsavedEnitity || userCanEdit); |
|
138 |
boolean userCanEdit = newValue == null || !newValue.isPersited() || UserHelper.fromSession().userHasPermission(newValue, "DELETE", "UPDATE"); |
|
139 |
setEnabled(userCanEdit); |
|
141 | 140 |
} |
142 | 141 |
|
143 | 142 |
private void setMode(Mode mode){ |
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/TeamOrPersonField.java | ||
---|---|---|
122 | 122 |
|
123 | 123 |
selectConfirmButton.setEnabled(teamOrPersonSelect.getValue() != null); |
124 | 124 |
selectConfirmButton.addClickListener(e -> { |
125 |
// new entitiy being set, reset the readonly state |
|
126 |
resetReadOnlyComponents(); |
|
125 | 127 |
setValue(teamOrPersonSelect.getValue()); |
126 | 128 |
teamOrPersonSelect.clear(); |
127 | 129 |
updateToolBarButtonStates(); |
128 | 130 |
}); |
129 | 131 |
removeButton.addClickListener(e -> { |
132 |
resetReadOnlyComponents(); |
|
130 | 133 |
setValue(null); |
131 | 134 |
updateToolBarButtonStates(); |
132 | 135 |
}); |
... | ... | |
134 | 137 |
|
135 | 138 |
personButton.addClickListener(e -> { |
136 | 139 |
setValue(Person.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!! |
137 |
updateToolBarButtonStates(); |
|
140 |
|
|
138 | 141 |
}); |
139 | 142 |
personButton.setDescription("Add person"); |
140 | 143 |
teamButton.addClickListener(e -> { |
141 | 144 |
setValue(Team.NewInstance()); // FIXME add SelectField or open select dialog, use ToOneSelect field!! |
142 |
updateToolBarButtonStates(); |
|
145 |
// updateToolBarButtonStates();
|
|
143 | 146 |
}); |
144 | 147 |
teamButton.setDescription("Add team"); |
145 | 148 |
|
... | ... | |
179 | 182 |
@Override |
180 | 183 |
protected void setInternalValue(TeamOrPersonBase<?> newValue) { |
181 | 184 |
|
185 |
TeamOrPersonBase<?> oldValue = getValue(); |
|
182 | 186 |
super.setInternalValue(newValue); |
183 | 187 |
|
184 | 188 |
newValue = HibernateProxyHelper.deproxy(newValue); |
... | ... | |
189 | 193 |
if(newValue != null) { |
190 | 194 |
|
191 | 195 |
if(Person.class.isAssignableFrom(newValue.getClass())){ |
192 |
// value is a Person:
|
|
196 |
// value is a Person |
|
193 | 197 |
compositeWrapper.addComponent(personField); |
194 | 198 |
|
195 | 199 |
personField.setValue((Person) newValue); |
... | ... | |
198 | 202 |
} |
199 | 203 |
else if(Team.class.isAssignableFrom(newValue.getClass())){ |
200 | 204 |
// otherwise it a Team |
201 |
|
|
202 | 205 |
compositeWrapper.addComponents(titleField, nomenclaturalTitleField, personsListEditor); |
203 | 206 |
|
204 | 207 |
titleField.bindTo(fieldGroup, "titleCache", "protectedTitleCache"); |
... | ... | |
213 | 216 |
} else { |
214 | 217 |
setComponentError(new UserError("TeamOrPersonField Error: Unsupported value type: " + newValue.getClass().getName())); |
215 | 218 |
} |
216 |
|
|
219 |
} else { |
|
220 |
if(oldValue != null){ |
|
221 |
// value is null --> clean up all nested fields |
|
222 |
// allow replacing old content in the editor by null |
|
223 |
setReadOnlyComponents(false); |
|
224 |
if(oldValue instanceof Person){ |
|
225 |
personField.unregisterParentFieldGroup(fieldGroup); |
|
226 |
personField.setReadOnly(false); |
|
227 |
personField.setValue((Person) null); |
|
228 |
} else { |
|
229 |
titleField.unbindFrom(fieldGroup); |
|
230 |
nomenclaturalTitleField.unbindFrom(fieldGroup); |
|
231 |
fieldGroup.unbind(personsListEditor); |
|
232 |
fieldGroup.setItemDataSource((Team)null); |
|
233 |
personsListEditor.registerParentFieldGroup(null); |
|
234 |
personsListEditor.setReadOnly(false); |
|
235 |
personsListEditor.setValue(null); |
|
236 |
personsListEditor.registerParentFieldGroup(null); |
|
237 |
} |
|
238 |
} |
|
217 | 239 |
} |
218 | 240 |
adaptToUserPermissions(newValue); |
219 | 241 |
updateToolBarButtonStates(); |
... | ... | |
227 | 249 |
} |
228 | 250 |
|
229 | 251 |
UserHelper userHelper = UserHelper.fromSession(); |
230 |
boolean canEdit = userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE); |
|
252 |
boolean canEdit = !teamOrPerson.isPersited() || userHelper.userHasPermission(teamOrPerson, CRUD.UPDATE);
|
|
231 | 253 |
if(!canEdit){ |
232 |
setContentReadOnly(true);
|
|
254 |
setReadOnlyComponents(true);
|
|
233 | 255 |
} |
234 | 256 |
} |
235 | 257 |
|
... | ... | |
362 | 384 |
@Override |
363 | 385 |
public void setReadOnly(boolean readOnly) { |
364 | 386 |
super.setReadOnly(readOnly); |
365 |
setContentReadOnly(readOnly); |
|
387 |
setReadOnlyComponents(readOnly); |
|
388 |
} |
|
389 |
|
|
390 |
/** |
|
391 |
* Reset the readonly state of nested components to <code>false</code>. |
|
392 |
*/ |
|
393 |
protected void resetReadOnlyComponents() { |
|
394 |
if(!isReadOnly()){ |
|
395 |
setReadOnlyComponents(false); |
|
396 |
} |
|
366 | 397 |
} |
367 | 398 |
|
368 | 399 |
/** |
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. |
|
400 |
* Set the nested components (team or person fields) to read only but |
|
401 |
* keep the state of the <code>TeamOrPersonField</code> untouched so |
|
402 |
* that the <code>teamOrPersonSelect</code>, <code>removeButton</code>, |
|
403 |
* <code>personButton</code> and <code>teamButton</code> stay operational. |
|
371 | 404 |
* |
372 | 405 |
* @param readOnly |
373 | 406 |
*/ |
374 |
public void setContentReadOnly(boolean readOnly) {
|
|
375 |
setDeepReadOnly(readOnly, getContent(), Arrays.asList(removeButton, personButton, teamButton)); |
|
407 |
public void setReadOnlyComponents(boolean readOnly) {
|
|
408 |
setDeepReadOnly(readOnly, getContent(), Arrays.asList(removeButton, personButton, teamButton, teamOrPersonSelect));
|
|
376 | 409 |
updateCaptionReadonlyNotice(); |
377 | 410 |
} |
378 | 411 |
|
src/main/java/eu/etaxonomy/vaadin/component/CompositeCustomField.java | ||
---|---|---|
41 | 41 |
|
42 | 42 |
private List<Component> sizedComponents = new ArrayList<>(); |
43 | 43 |
|
44 |
private CommitHandler commitHandler = new CommitHandler() { |
|
45 |
|
|
46 |
@Override |
|
47 |
public void preCommit(CommitEvent commitEvent) throws CommitException { |
|
48 |
// commit the nested bean(s) first |
|
49 |
if(getFieldGroup() != null){ |
|
50 |
getFieldGroup().commit(); |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
@Override |
|
55 |
public void postCommit(CommitEvent commitEvent) throws CommitException { |
|
56 |
// noting to do |
|
57 |
}}; |
|
58 |
|
|
44 | 59 |
protected List<Component> getStyledComponents() { |
45 | 60 |
if(styledComponents == null){ |
46 | 61 |
styledComponents = new ArrayList<>(); |
... | ... | |
190 | 205 |
|
191 | 206 |
@Override |
192 | 207 |
public void registerParentFieldGroup(FieldGroup parent) { |
193 |
parent.addCommitHandler(new CommitHandler() { |
|
194 |
|
|
195 |
@Override |
|
196 |
public void preCommit(CommitEvent commitEvent) throws CommitException { |
|
197 |
// commit the nested bean(s) first |
|
198 |
if(getFieldGroup() != null){ |
|
199 |
getFieldGroup().commit(); |
|
200 |
} |
|
201 |
} |
|
208 |
parent.addCommitHandler(commitHandler); |
|
209 |
} |
|
202 | 210 |
|
203 |
@Override |
|
204 |
public void postCommit(CommitEvent commitEvent) throws CommitException { |
|
205 |
// noting to do |
|
206 |
}} |
|
207 |
); |
|
211 |
@Override |
|
212 |
public void unregisterParentFieldGroup(FieldGroup parent) { |
|
213 |
parent.removeCommitHandler(commitHandler); |
|
208 | 214 |
} |
209 | 215 |
|
210 | 216 |
/** |
src/main/java/eu/etaxonomy/vaadin/component/NestedFieldGroup.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
public abstract void registerParentFieldGroup(FieldGroup parent); |
28 | 28 |
|
29 |
/** |
|
30 |
* @param parent |
|
31 |
*/ |
|
32 |
public abstract void unregisterParentFieldGroup(FieldGroup parent); |
|
33 |
|
|
29 | 34 |
} |
src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java | ||
---|---|---|
98 | 98 |
textField.setEnabled(unlockSwitch.getValue()); |
99 | 99 |
} |
100 | 100 |
|
101 |
public void unbindFrom(FieldGroup fieldGroup){ |
|
102 |
fieldGroup.unbind(textField); |
|
103 |
fieldGroup.unbind(unlockSwitch); |
|
104 |
textField.setEnabled(false); |
|
105 |
} |
|
106 |
|
|
101 | 107 |
/** |
102 | 108 |
* {@inheritDoc} |
103 | 109 |
*/ |
src/main/java/eu/etaxonomy/vaadin/component/ToManyRelatedEntitiesListSelect.java | ||
---|---|---|
139 | 139 |
// TODO remove from nested fields |
140 | 140 |
updateValue(); |
141 | 141 |
updateButtonStates(); |
142 |
|
|
143 | 142 |
} |
144 | 143 |
|
144 |
|
|
145 | 145 |
/** |
146 | 146 |
* @param field |
147 | 147 |
* @return |
... | ... | |
184 | 184 |
List<V> beanList = getValue(); |
185 | 185 |
beanList.clear(); |
186 | 186 |
beanList.addAll(nestedValues); |
187 |
setInternalValue(beanList, false);
|
|
187 |
setInternalValue(beanList); |
|
188 | 188 |
} |
189 | 189 |
|
190 | 190 |
/** |
... | ... | |
216 | 216 |
@Override |
217 | 217 |
protected void setInternalValue(List<V> newValue) { |
218 | 218 |
|
219 |
setInternalValue(newValue, true); |
|
220 |
|
|
221 |
} |
|
222 |
|
|
223 |
protected void setInternalValue(List<V> newValue, boolean doUpdateFields) { |
|
224 |
|
|
225 | 219 |
super.setInternalValue(newValue); |
226 | 220 |
|
227 | 221 |
if(valueInitiallyWasNull == null){ |
... | ... | |
231 | 225 |
if(newValue != null){ |
232 | 226 |
// newValue is already converted, need to use the original value from the data source |
233 | 227 |
boolean isListType = List.class.isAssignableFrom(getPropertyDataSource().getValue().getClass()); |
228 |
// if(valueInitiallyWasNull && isOrderedCollection != isListType){ |
|
234 | 229 |
if(valueInitiallyWasNull && isOrderedCollection != isListType){ |
235 | 230 |
// need to reset the grid in this case, so that the button groups are created correctly |
236 | 231 |
grid.setRows(1); |
237 | 232 |
grid.removeAllComponents(); |
238 | 233 |
} |
239 | 234 |
isOrderedCollection = isListType; |
235 |
} else { |
|
236 |
// reset the grid |
|
237 |
grid.removeAllComponents(); |
|
238 |
grid.setRows(1); |
|
240 | 239 |
} |
241 | 240 |
|
242 | 241 |
if(!creatingFields){ |
Also available in: Unified diff
ref #7366 fixing problems with readonly states in TeamOrPersonField and subcomponents and fixing problems with removal and re-adding of entities