Revision 98c2f401
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java | ||
---|---|---|
13 | 13 |
import java.util.List; |
14 | 14 |
import java.util.UUID; |
15 | 15 |
|
16 |
import org.apache.commons.lang.StringUtils; |
|
16 | 17 |
import org.apache.log4j.Logger; |
17 | 18 |
import org.hibernate.criterion.Restrictions; |
18 | 19 |
import org.springframework.context.annotation.Scope; |
... | ... | |
46 | 47 |
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent; |
47 | 48 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction; |
48 | 49 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction; |
50 |
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorActionStrRep; |
|
49 | 51 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater; |
50 | 52 |
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader; |
51 | 53 |
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO; |
... | ... | |
362 | 364 |
getView().getInfraSpecificEpithetField() |
363 | 365 |
); |
364 | 366 |
WeaklyRelatedEntityCombobox<TaxonName> genusOrUninomialField = (WeaklyRelatedEntityCombobox<TaxonName>)event.getNewField(); |
365 |
// FIXME genusOrUninomialField.setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater<TaxonName>(genusOrUninomialField)); |
|
366 | 367 |
genusOrUninomialField.loadFrom(genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider.getPageSize()); |
367 | 368 |
genusOrUninomialField.setValue(event.getOldField().getValue()); |
368 | 369 |
}else { |
... | ... | |
384 | 385 |
BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView()); |
385 | 386 |
|
386 | 387 |
if(boundTargetField != null){ |
387 |
if(boundTargetField.matchesPropertyIdPath("nomenclaturalReference")){ |
|
388 |
if(boundTargetField.matchesPropertyIdPath("genusOrUninomial")){ |
|
389 |
if(event.isCreateOrModifiedType()){ |
|
390 |
getCache().load(event.getEntity()); |
|
391 |
if(getView().getGenusOrUninomialField() instanceof WeaklyRelatedEntityCombobox){ |
|
392 |
WeaklyRelatedEntityCombobox<TaxonName> weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox<TaxonName>)getView().getGenusOrUninomialField(); |
|
393 |
if(event.isCreatedType()){ |
|
394 |
weaklyRelatedEntityCombobox.setValue(((TaxonName)event.getEntity()).getGenusOrUninomial()); |
|
395 |
weaklyRelatedEntityCombobox.reload(); |
|
396 |
} else { |
|
397 |
weaklyRelatedEntityCombobox.reload(); |
|
398 |
} |
|
399 |
// NOTE: in constrast to the ToOneRelatedEntityCombobox the .discard() does not |
|
400 |
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload() |
|
401 |
weaklyRelatedEntityCombobox.updateButtons(); |
|
402 |
} |
|
403 |
} |
|
404 |
} else |
|
405 |
if(boundTargetField.matchesPropertyIdPath("specificEpithet")){ |
|
388 | 406 |
if(event.isCreateOrModifiedType()){ |
407 |
getCache().load(event.getEntity()); |
|
389 | 408 |
|
409 |
if(getView().getSpecificEpithetField() instanceof WeaklyRelatedEntityCombobox){ |
|
410 |
WeaklyRelatedEntityCombobox weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox)getView().getSpecificEpithetField(); |
|
411 |
if(event.isCreatedType()){ |
|
412 |
getView().getSpecificEpithetField().setValue(((TaxonName)event.getEntity()).getSpecificEpithet()); |
|
413 |
weaklyRelatedEntityCombobox.reload(); |
|
414 |
} else { |
|
415 |
weaklyRelatedEntityCombobox.reload(); |
|
416 |
} |
|
417 |
// NOTE: in constrast to the ToOneRelatedEntityCombobox the .discard() does not |
|
418 |
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload() |
|
419 |
weaklyRelatedEntityCombobox.updateButtons(); |
|
420 |
} |
|
421 |
} |
|
422 |
} else |
|
423 |
if(boundTargetField.matchesPropertyIdPath("nomenclaturalReference")){ |
|
424 |
if(event.isCreateOrModifiedType()){ |
|
390 | 425 |
getCache().load(event.getEntity()); |
391 | 426 |
if(event.isCreatedType()){ |
392 | 427 |
getView().getNomReferenceCombobox().setValue((Reference) event.getEntity()); |
... | ... | |
396 | 431 |
getView().getCombinationAuthorshipField().discard(); //refresh from the datasource |
397 | 432 |
getView().updateAuthorshipFields(); |
398 | 433 |
} |
399 |
} |
|
434 |
} else
|
|
400 | 435 |
if(boundTargetField.matchesPropertyIdPath("validationFor.otherName")){ |
401 | 436 |
ReloadableLazyComboBox<TaxonName> otherNameField = asReloadableLazyComboBox(boundTargetField.getField(TaxonName.class)); |
402 | 437 |
if(event.isCreateOrModifiedType()){ |
... | ... | |
472 | 507 |
|
473 | 508 |
if(boundPropertyId != null){ |
474 | 509 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){ |
475 |
TaxonNamePopupEditor validatedNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
476 |
validatedNamePopup.withDeleteButton(true);
|
|
510 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
511 |
namePopup.withDeleteButton(true);
|
|
477 | 512 |
getView().getModesActive().stream() |
478 | 513 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
479 |
.forEach(m -> validatedNamePopup.enableMode(m));
|
|
480 |
validatedNamePopup.loadInEditor(event.getEntityUuid());
|
|
514 |
.forEach(m -> namePopup.enableMode(m));
|
|
515 |
namePopup.loadInEditor(event.getEntityUuid());
|
|
481 | 516 |
} |
482 | 517 |
} |
518 |
} |
|
519 |
|
|
520 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class) |
|
521 |
public void onTaxonNameEditorActionStrRepEdit(TaxonNameEditorActionStrRep event) { |
|
522 |
|
|
523 |
if(getView() == null || event.getSourceView() != getView() ){ |
|
524 |
return; |
|
525 |
} |
|
526 |
|
|
527 |
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget()); |
|
483 | 528 |
|
529 |
if(boundPropertyId != null){ |
|
530 |
if(boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")){ |
|
531 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event); |
|
532 |
namePopup.withDeleteButton(true); |
|
533 |
getView().getModesActive().stream() |
|
534 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
|
535 |
.forEach(m -> namePopup.enableMode(m)); |
|
536 |
namePopup.loadInEditor(event.getEntityUuid()); |
|
537 |
} |
|
538 |
} |
|
484 | 539 |
} |
485 | 540 |
|
486 | 541 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class) |
... | ... | |
494 | 549 |
|
495 | 550 |
if(boundPropertyId != null){ |
496 | 551 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){ |
497 |
TaxonNamePopupEditor validatedNamePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
498 |
validatedNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
499 |
validatedNamePopup.withDeleteButton(true);
|
|
552 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
|
553 |
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
|
554 |
namePopup.withDeleteButton(true);
|
|
500 | 555 |
getView().getModesActive().stream() |
501 | 556 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
502 |
.forEach(m -> validatedNamePopup.enableMode(m)); |
|
503 |
validatedNamePopup.loadInEditor(null); |
|
557 |
.forEach(m -> namePopup.enableMode(m)); |
|
558 |
namePopup.loadInEditor(null); |
|
559 |
} |
|
560 |
} |
|
561 |
} |
|
562 |
|
|
563 |
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class) |
|
564 |
public void onTaxonNameEditorActionStrRepAdd(TaxonNameEditorActionStrRep event) { |
|
565 |
|
|
566 |
if(getView() == null || event.getSourceView() != getView() ){ |
|
567 |
return; |
|
568 |
} |
|
569 |
|
|
570 |
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget()); |
|
571 |
|
|
572 |
if(boundPropertyId != null){ |
|
573 |
if(boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")){ |
|
574 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event); |
|
575 |
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE)); |
|
576 |
namePopup.withDeleteButton(true); |
|
577 |
String nameString = event.getTarget().getValue(); |
|
578 |
getView().getModesActive().stream() |
|
579 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
|
580 |
.forEach(m -> namePopup.enableMode(m)); |
|
581 |
namePopup.loadInEditor(null); |
|
582 |
if(StringUtils.isNotEmpty(nameString)){ |
|
583 |
if(boundPropertyId.matches("genusOrUninomial")){ |
|
584 |
namePopup.getGenusOrUninomialField().setValue(nameString); |
|
585 |
namePopup.getRankSelect().setValue(Rank.GENUS()); |
|
586 |
} |
|
587 |
if(boundPropertyId.matches("specificEpithet")){ |
|
588 |
namePopup.getSpecificEpithetField().setValue(nameString); |
|
589 |
namePopup.getGenusOrUninomialField().setValue(getView().getGenusOrUninomialField().getValue()); |
|
590 |
namePopup.getRankSelect().setValue(Rank.SPECIES()); |
|
591 |
} |
|
592 |
} |
|
504 | 593 |
} |
505 | 594 |
} |
506 | 595 |
} |
Also available in: Unified diff
ref #7783 using WeaklyRelatedEntityCombobox in TaxonNameEditor: add, edit buttons working and enabled state updating ok