Revision 6d74a77f
Added by Andreas Kohlbecker almost 5 years ago
src/main/java/eu/etaxonomy/vaadin/component/ToManyRelatedEntitiesListSelect.java | ||
---|---|---|
160 | 160 |
grid.removeRow(row); |
161 | 161 |
// TODO remove from nested fields |
162 | 162 |
updateValue(); |
163 |
updateButtonStates();
|
|
163 |
updateComponentStates();
|
|
164 | 164 |
} |
165 | 165 |
|
166 | 166 |
|
... | ... | |
191 | 191 |
if(i >= 0 && i + 1 < grid.getRows()){ |
192 | 192 |
grid.replaceComponent(grid.getComponent(GRID_X_FIELD, i), grid.getComponent(GRID_X_FIELD, i + 1)); |
193 | 193 |
grid.replaceComponent(grid.getComponent(GRID_X_FIELD + 1 , i), grid.getComponent(GRID_X_FIELD + 1, i + 1)); |
194 |
updateButtonStates();
|
|
194 |
updateComponentStates();
|
|
195 | 195 |
updateValue(); |
196 | 196 |
} else { |
197 | 197 |
throw new RuntimeException("Cannot swap rows out of the grid bounds"); |
... | ... | |
284 | 284 |
newRowNeeded = false; |
285 | 285 |
F field = (F)fieldComponent; |
286 | 286 |
if(data.get(row) != null && field.getValue() != data.get(row)){ |
287 |
boolean roState = field.isReadOnly(); |
|
288 |
field.setReadOnly(false); |
|
287 | 289 |
field.setValue(data.get(row)); |
290 |
field.setReadOnly(roState); |
|
288 | 291 |
} |
289 | 292 |
} |
290 | 293 |
} |
... | ... | |
360 | 363 |
} |
361 | 364 |
grid.addComponent(field, GRID_X_FIELD, row); |
362 | 365 |
grid.addComponent(buttonGroup, GRID_X_BUTTON_GROUP, row); |
363 |
updateButtonStates();
|
|
366 |
updateComponentStates();
|
|
364 | 367 |
nestFieldGroup(field); |
365 | 368 |
row++; |
366 | 369 |
} catch (InstantiationException e) { |
... | ... | |
458 | 461 |
} |
459 | 462 |
} |
460 | 463 |
|
461 |
private void updateButtonStates(){
|
|
464 |
private void updateComponentStates(){
|
|
462 | 465 |
|
463 | 466 |
boolean isWritable = !getState().readOnly; |
464 | 467 |
int fieldsCount = getNestedFields().size(); |
... | ... | |
471 | 474 |
F field = (F) grid.getComponent(GRID_X_FIELD, row); |
472 | 475 |
CssLayout buttonGroup = (CssLayout) grid.getComponent(GRID_X_FIELD + 1, row); |
473 | 476 |
|
477 |
boolean isWritableField = isWritableField(field); |
|
478 |
field.setReadOnly(!isWritableField); |
|
479 |
|
|
474 | 480 |
int addButtonIndex = 0; |
475 | 481 |
if(withEditButton){ |
476 | 482 |
addButtonIndex++; |
477 | 483 |
// edit |
478 | 484 |
Button editCreateButton = ((Button)buttonGroup.getComponent(0)); |
479 | 485 |
editCreateButton.setDescription(field.getValue() == null ? "New" : "Edit"); |
480 |
editCreateButton.setEnabled(isWritable && (field.getValue() == null |
|
481 |
|| field.getValue() != null && testEditButtonPermission(field.getValue()))); |
|
486 |
editCreateButton.setEnabled(isWritableField); // the should button must always be enabled to allow viewing even readonly data. (https://dev.e-taxonomy.eu/redmine/issues/8217) |
|
482 | 487 |
} |
483 | 488 |
// add |
484 | 489 |
buttonGroup.getComponent(addButtonIndex).setEnabled(isWritable && (isLast || isOrderedCollection)); |
... | ... | |
494 | 499 |
} |
495 | 500 |
} |
496 | 501 |
|
502 |
/** |
|
503 |
* @param isWritable |
|
504 |
* @param field |
|
505 |
* @return |
|
506 |
*/ |
|
507 |
public boolean isWritableField(F field) { |
|
508 |
boolean isWritable = !getState().readOnly; |
|
509 |
return isWritable && (field.getValue() == null |
|
510 |
|| field.getValue() != null && testEditButtonPermission(field.getValue())); |
|
511 |
} |
|
512 |
|
|
497 | 513 |
/** |
498 | 514 |
* @param field |
499 | 515 |
* @return |
... | ... | |
738 | 754 |
@Override |
739 | 755 |
public void setReadOnly(boolean readOnly) { |
740 | 756 |
super.setReadOnly(readOnly); |
741 |
updateButtonStates();
|
|
757 |
updateComponentStates();
|
|
742 | 758 |
} |
743 | 759 |
|
744 | 760 |
|
Also available in: Unified diff
ref #8217 proper setting of the readonly state for ToManyRelatedEntitiesListSelect fields