Revision e90e4ec3
Added by Andreas Kohlbecker about 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java | ||
---|---|---|
17 | 17 |
|
18 | 18 |
import com.vaadin.shared.ui.label.ContentMode; |
19 | 19 |
import com.vaadin.spring.annotation.SpringComponent; |
20 |
import com.vaadin.ui.AbstractField; |
|
20 | 21 |
import com.vaadin.ui.Alignment; |
21 | 22 |
import com.vaadin.ui.CheckBox; |
22 | 23 |
import com.vaadin.ui.GridLayout; |
... | ... | |
24 | 25 |
import com.vaadin.ui.ListSelect; |
25 | 26 |
import com.vaadin.ui.TextField; |
26 | 27 |
|
28 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
|
27 | 29 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
28 | 30 |
import eu.etaxonomy.cdm.model.name.Rank; |
29 | 31 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
... | ... | |
94 | 96 |
|
95 | 97 |
private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class); |
96 | 98 |
|
99 |
private Boolean isInferredCombinationAuthorship = null; |
|
100 |
|
|
101 |
private Boolean isInferredBasionymAuthorship = null; |
|
102 |
|
|
103 |
private Boolean isInferredExBasionymAuthorship = null; |
|
104 |
|
|
97 | 105 |
/** |
98 | 106 |
* @param layout |
99 | 107 |
* @param dtoType |
... | ... | |
217 | 225 |
basionymToggle.setValue(HAS_BASIONYM_DEFAULT); |
218 | 226 |
basionymToggle.addValueChangeListener(e -> { |
219 | 227 |
updateFieldVisibility(); |
228 |
updateAuthorshipFields(); |
|
220 | 229 |
}); |
221 | 230 |
basionymToggle.setStyleName(getDefaultComponentStyles()); |
222 | 231 |
grid.addComponent(basionymToggle, 2, row, 3, row); |
... | ... | |
323 | 332 |
|
324 | 333 |
setAdvancedModeEnabled(true); |
325 | 334 |
registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField); |
326 |
registerAdvancedModeComponents(basionymAuthorshipField.getCachFields()); |
|
327 |
registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields()); |
|
335 |
|
|
336 |
registerAdvancedModeComponents(combinationAuthorshipField); |
|
337 |
registerAdvancedModeComponents(basionymAuthorshipField); |
|
338 |
registerAdvancedModeComponents(exBasionymAuthorshipField); |
|
339 |
|
|
328 | 340 |
registerAdvancedModeComponents(combinationAuthorshipField.getCachFields()); |
329 | 341 |
registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields()); |
342 |
registerAdvancedModeComponents(basionymAuthorshipField.getCachFields()); |
|
343 |
registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields()); |
|
344 |
|
|
330 | 345 |
setAdvancedMode(false); |
331 | 346 |
|
332 | 347 |
} |
333 | 348 |
|
334 |
/** |
|
335 |
* @param rank |
|
336 |
* @return |
|
337 |
*/ |
|
338 |
private void updateFieldVisibility() { |
|
339 |
|
|
340 |
// TODO use getField() instead and remove field references |
|
341 |
|
|
342 |
TaxonName taxonName = getBean(); |
|
343 |
Rank rank = taxonName.getRank(); |
|
344 |
|
|
345 |
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES()); |
|
346 |
Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue()); |
|
347 |
Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue()); |
|
348 |
|
|
349 |
basionymAuthorshipField.setVisible(withBasionym != null && withBasionym); |
|
350 |
exBasionymAuthorshipField.setVisible(withBasionym); |
|
351 |
basionymsComboboxSelect.setVisible(withBasionym); |
|
352 |
|
|
353 |
if(taxonName != null){ |
|
354 |
if(modesActive.contains(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){ |
|
355 |
basionymAuthorshipField.setVisible(taxonName.getBasionymAuthorship() != null); |
|
356 |
exBasionymAuthorshipField.setVisible(taxonName.getExBasionymAuthorship() != null); |
|
349 |
protected TeamOrPersonBase inferBasiomynAuthors(TaxonName taxonName) { |
|
350 |
TaxonName basionym = taxonName.getBasionym(); |
|
351 |
if(basionym != null){ |
|
352 |
if(basionym.getCombinationAuthorship() != null){ |
|
353 |
return basionym.getCombinationAuthorship(); |
|
354 |
} else if(basionym.getNomenclaturalReference() != null){ |
|
355 |
return basionym.getNomenclaturalReference().getAuthorship(); |
|
357 | 356 |
} |
358 | 357 |
} |
358 |
return null; |
|
359 |
} |
|
359 | 360 |
|
360 |
infraSpecificEpithetField.setVisible(rank.isInfraSpecific()); |
|
361 |
specificEpithetField.setVisible(isSpeciesOrBelow); |
|
362 |
infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup()); |
|
363 |
genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial"); |
|
364 |
exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation); |
|
361 |
protected TeamOrPersonBase inferExBasiomynAuthors(TaxonName taxonName) { |
|
362 |
TaxonName basionym = taxonName.getBasionym(); |
|
363 |
if(basionym != null){ |
|
364 |
return basionym.getExCombinationAuthorship(); |
|
365 |
} |
|
366 |
return null; |
|
367 |
} |
|
368 |
|
|
369 |
protected TeamOrPersonBase inferCombinationAuthors(TaxonName taxonName) { |
|
370 |
if(taxonName.getNomenclaturalReference() != null) { |
|
371 |
return taxonName.getNomenclaturalReference().getAuthorship(); |
|
372 |
} |
|
373 |
return null; |
|
365 | 374 |
} |
366 | 375 |
|
367 | 376 |
@Override |
... | ... | |
378 | 387 |
validationToggle.setReadOnly(showExAuthors); |
379 | 388 |
exCombinationAuthorshipField.setVisible(showExAuthors); |
380 | 389 |
|
381 |
if(isModeEnabled(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
|
|
382 |
combinationAuthorshipField.setVisible(taxonName.getCombinationAuthorship() != null);
|
|
390 |
if(isModeEnabled(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
|
|
391 |
updateAuthorshipFields();
|
|
383 | 392 |
} |
384 |
if(isModeEnabled(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly) && getBean().getNomenclaturalReference() != null) {
|
|
393 |
if(isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY) && getBean().getNomenclaturalReference() != null) {
|
|
385 | 394 |
nomReferenceCombobox.setCaption("Selection limited to nomenclatural reference and sections"); |
386 | 395 |
} |
387 |
if(isModeEnabled(TaxonNamePopupEditorMode.requireNomenclaturalReference)) {
|
|
396 |
if(isModeEnabled(TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE)) {
|
|
388 | 397 |
if(combinationAuthorshipField.getValue() == null){ |
389 | 398 |
nomReferenceCombobox.setRequired(true); |
390 | 399 |
} else { |
... | ... | |
398 | 407 |
|
399 | 408 |
} |
400 | 409 |
|
410 |
/** |
|
411 |
* @param taxonName |
|
412 |
*/ |
|
413 |
@Override |
|
414 |
public void updateAuthorshipFields() { |
|
415 |
|
|
416 |
TaxonName taxonName = getBean(); |
|
417 |
|
|
418 |
// ------------- CombinationAuthors |
|
419 |
isInferredCombinationAuthorship = updateAuthorshipField( |
|
420 |
taxonName.getCombinationAuthorship(), |
|
421 |
inferCombinationAuthors(taxonName), |
|
422 |
combinationAuthorshipField, |
|
423 |
nomReferenceCombobox.getSelect(), |
|
424 |
isInferredCombinationAuthorship); |
|
425 |
|
|
426 |
|
|
427 |
// ------------- Basionym and ExBasionymAuthors |
|
428 |
if(BooleanUtils.isTrue(basionymToggle.getValue())){ |
|
429 |
|
|
430 |
isInferredBasionymAuthorship = updateAuthorshipField( |
|
431 |
taxonName.getBasionymAuthorship(), |
|
432 |
inferBasiomynAuthors(taxonName), |
|
433 |
basionymAuthorshipField, |
|
434 |
basionymsComboboxSelect, |
|
435 |
isInferredBasionymAuthorship |
|
436 |
); |
|
437 |
|
|
438 |
isInferredExBasionymAuthorship = updateAuthorshipField( |
|
439 |
taxonName.getExBasionymAuthorship(), |
|
440 |
inferExBasiomynAuthors(taxonName), |
|
441 |
exBasionymAuthorshipField, |
|
442 |
//no point adding the basionymsComboboxSelect again, it has bee registered already for the BasionymAuthorship above |
|
443 |
null, |
|
444 |
isInferredExBasionymAuthorship |
|
445 |
); |
|
446 |
} |
|
447 |
} |
|
448 |
|
|
449 |
/** |
|
450 |
* |
|
451 |
* @param authorship |
|
452 |
* the value of the taxonName authorship field |
|
453 |
* @param inferredAuthors |
|
454 |
* the value inferred from other fields which may be set as authorship to the taxon name |
|
455 |
* @param authorshipField |
|
456 |
* the ui element to edit the taxonName authorship field |
|
457 |
* @param updateTriggerField |
|
458 |
* @param lastInferredAuthorshipState |
|
459 |
* @return |
|
460 |
*/ |
|
461 |
protected Boolean updateAuthorshipField(TeamOrPersonBase<?> authorship, TeamOrPersonBase inferredAuthors, |
|
462 |
TeamOrPersonField authorshipField, AbstractField updateTriggerField, |
|
463 |
Boolean lastInferredAuthorshipState) { |
|
464 |
|
|
465 |
if(authorship == null){ |
|
466 |
authorshipField.setValue(inferredAuthors); |
|
467 |
lastInferredAuthorshipState = true; |
|
468 |
} else { |
|
469 |
boolean authorshipMatch = authorship == inferredAuthors; |
|
470 |
if(lastInferredAuthorshipState == null){ |
|
471 |
// initialization of isInferredCombinationAuthorship in case the editor is just being initialized |
|
472 |
lastInferredAuthorshipState = authorshipMatch; |
|
473 |
if(updateTriggerField != null){ |
|
474 |
// IMPORTANT! |
|
475 |
// this ChangeListener must be added at this very late point in the editor lifecycle so that it is called after |
|
476 |
// the ToOneRelatedEntityReloader which may have been added to the updateTriggerField in the presenters handleViewEntered() method. |
|
477 |
// Otherwise we risk multiple representation problems in the hibernate session |
|
478 |
updateTriggerField.addValueChangeListener(e -> updateAuthorshipFields()); |
|
479 |
} |
|
480 |
} |
|
481 |
if(!authorshipMatch && lastInferredAuthorshipState){ |
|
482 |
// update the combinationAuthorshipField to follow changes of the nomenclatural reference in case it was autofilled before |
|
483 |
authorshipField.setValue(inferredAuthors); |
|
484 |
lastInferredAuthorshipState = true; |
|
485 |
} |
|
486 |
} |
|
487 |
authorshipField.setVisible(!lastInferredAuthorshipState); |
|
488 |
return lastInferredAuthorshipState; |
|
489 |
} |
|
490 |
|
|
491 |
/** |
|
492 |
* @param rank |
|
493 |
* @return |
|
494 |
*/ |
|
495 |
private void updateFieldVisibility() { |
|
496 |
|
|
497 |
// TODO use getField() instead and remove field references |
|
498 |
|
|
499 |
TaxonName taxonName = getBean(); |
|
500 |
Rank rank = taxonName.getRank(); |
|
501 |
|
|
502 |
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES()); |
|
503 |
Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue()); |
|
504 |
Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue()); |
|
505 |
|
|
506 |
basionymAuthorshipField.setVisible(withBasionym != null && withBasionym); |
|
507 |
exBasionymAuthorshipField.setVisible(withBasionym); |
|
508 |
basionymsComboboxSelect.setVisible(withBasionym); |
|
509 |
|
|
510 |
if(taxonName != null){ |
|
511 |
if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){ |
|
512 |
updateAuthorshipFields(); |
|
513 |
} |
|
514 |
} |
|
515 |
|
|
516 |
infraSpecificEpithetField.setVisible(rank.isInfraSpecific()); |
|
517 |
specificEpithetField.setVisible(isSpeciesOrBelow); |
|
518 |
infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup()); |
|
519 |
genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial"); |
|
520 |
exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation); |
|
521 |
} |
|
522 |
|
|
401 | 523 |
/** |
402 | 524 |
* {@inheritDoc} |
403 | 525 |
*/ |
Also available in: Unified diff
ref #7344 new TaxonNameEditor mode to allow autofilling of name authorship fields