Revision e5237e50
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java | ||
---|---|---|
23 | 23 |
import com.vaadin.spring.annotation.SpringComponent; |
24 | 24 |
import com.vaadin.ui.AbstractField; |
25 | 25 |
import com.vaadin.ui.Field; |
26 |
import com.vaadin.ui.Notification; |
|
27 |
import com.vaadin.ui.Notification.Type; |
|
26 | 28 |
|
27 | 29 |
import eu.etaxonomy.cdm.api.service.INameService; |
28 | 30 |
import eu.etaxonomy.cdm.model.agent.AgentBase; |
... | ... | |
79 | 81 |
public class TaxonNameEditorPresenter extends AbstractCdmDTOEditorPresenter<TaxonNameDTO, TaxonName, TaxonNamePopupEditorView> { |
80 | 82 |
|
81 | 83 |
|
82 |
private static final List<String> BASIONYM_INIT_STRATEGY = Arrays.asList(
|
|
84 |
private static final List<String> RELATED_NAME_INIT_STRATEGY = Arrays.asList(
|
|
83 | 85 |
"$", |
84 | 86 |
"relationsFromThisName", |
85 | 87 |
"relationsToThisName.type", |
... | ... | |
106 | 108 |
|
107 | 109 |
private CdmFilterablePagingProvider<TaxonName, TaxonName> relatedNamePagingProvider; |
108 | 110 |
|
111 |
private CdmFilterablePagingProvider<TaxonName, TaxonName> orthographicVariantNamePagingProvider; |
|
112 |
|
|
113 |
private Restriction<Reference> orthographicCorrectionRestriction; |
|
114 |
|
|
115 |
private Integer taxonNameId; |
|
116 |
|
|
109 | 117 |
/** |
110 | 118 |
* {@inheritDoc} |
111 | 119 |
*/ |
... | ... | |
139 | 147 |
nomReferencePagingProvider.setInitStrategy(REFERENCE_INIT_STRATEGY); |
140 | 148 |
getView().getNomReferenceCombobox().loadFrom(nomReferencePagingProvider, nomReferencePagingProvider, nomReferencePagingProvider.getPageSize()); |
141 | 149 |
getView().getNomReferenceCombobox().setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getNomReferenceCombobox())); |
150 |
getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>()); |
|
142 | 151 |
getView().getNomReferenceCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getNomReferenceCombobox(), this)); |
152 |
getView().getNomReferenceCombobox().getSelect().addValueChangeListener( e -> updateOrthographicCorrectionRestriction()); |
|
143 | 153 |
|
144 |
getView().getBasionymComboboxSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>()); |
|
145 | 154 |
|
146 | 155 |
relatedNamePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService()); |
147 |
relatedNamePagingProvider.setInitStrategy(BASIONYM_INIT_STRATEGY); |
|
156 |
relatedNamePagingProvider.setInitStrategy(RELATED_NAME_INIT_STRATEGY); |
|
157 |
getView().getBasionymComboboxSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>()); |
|
148 | 158 |
getView().getBasionymComboboxSelect().setPagingProviders(relatedNamePagingProvider, relatedNamePagingProvider, relatedNamePagingProvider.getPageSize(), this); |
149 | 159 |
|
150 | 160 |
getView().getReplacedSynonymsComboboxSelect().setCaptionGenerator( new CdmTitleCacheCaptionGenerator<TaxonName>()); |
151 |
// reusing the basionymPagingProvider for the replaced synonyms to benefit from caching |
|
152 | 161 |
getView().getReplacedSynonymsComboboxSelect().setPagingProviders(relatedNamePagingProvider, relatedNamePagingProvider, relatedNamePagingProvider.getPageSize(), this); |
153 | 162 |
|
154 |
getView().getValidationField().getValidatedNameComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>()); |
|
155 |
// reusing the basionymPagingProvider for the replaced synonyms to benefit from caching |
|
156 |
getView().getValidationField().getValidatedNameComboBox().loadFrom(relatedNamePagingProvider, relatedNamePagingProvider, relatedNamePagingProvider.getPageSize()); |
|
157 |
getView().getValidationField().getValidatedNameComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getValidatedNameComboBox(), this)); |
|
158 |
|
|
159 |
getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>()); |
|
160 | 163 |
CdmFilterablePagingProvider<Reference, Reference> icbnCodesPagingProvider = pagingProviderFactory.referencePagingProvider(); |
161 | 164 |
icbnCodesPagingProvider.setInitStrategy(REFERENCE_INIT_STRATEGY); |
162 | 165 |
// @formatter:off |
... | ... | |
167 | 170 |
"978-3-87429-425-6", // Melbourne Code |
168 | 171 |
"978-3-946583-16-5", // Shenzhen Code |
169 | 172 |
"0-85301-006-4" // ICZN 1999 |
170 |
// ICNB
|
|
171 |
}));
|
|
173 |
// ICNB |
|
174 |
})); |
|
172 | 175 |
// @formatter:on |
176 |
|
|
177 |
getView().getValidationField().getRelatedNameComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>()); |
|
178 |
getView().getValidationField().getRelatedNameComboBox().loadFrom(relatedNamePagingProvider, relatedNamePagingProvider, relatedNamePagingProvider.getPageSize()); |
|
179 |
getView().getValidationField().getRelatedNameComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getRelatedNameComboBox(), this)); |
|
173 | 180 |
getView().getValidationField().getCitatonComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>()); |
174 | 181 |
getView().getValidationField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider, icbnCodesPagingProvider.getPageSize()); |
175 | 182 |
getView().getValidationField().getCitatonComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getCitatonComboBox(), this)); |
176 | 183 |
|
184 |
getView().getOrthographicVariantField().getRelatedNameComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>()); |
|
185 |
getView().getOrthographicVariantField().getRelatedNameComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getOrthographicVariantField().getRelatedNameComboBox(), this)); |
|
186 |
getView().getOrthographicVariantField().getRelatedNameComboBox().loadFrom(relatedNamePagingProvider, relatedNamePagingProvider, relatedNamePagingProvider.getPageSize()); |
|
187 |
// The Mode TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION will be handled in the updateOrthographicCorrectionRestriction() method |
|
188 |
getView().getOrthographicVariantField().getCitatonComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>()); |
|
189 |
getView().getOrthographicVariantField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider, icbnCodesPagingProvider.getPageSize()); |
|
190 |
getView().getOrthographicVariantField().getCitatonComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getOrthographicVariantField().getCitatonComboBox(), this)); |
|
191 |
|
|
192 |
|
|
177 | 193 |
getView().getAnnotationsField().setAnnotationTypeItemContainer(selectFieldFactory.buildTermItemContainer( |
178 | 194 |
AnnotationType.EDITORIAL().getUuid(), AnnotationType.TECHNICAL().getUuid())); |
179 | 195 |
} |
180 | 196 |
|
181 |
/** |
|
182 |
* {@inheritDoc} |
|
183 |
*/ |
|
197 |
@Override |
|
198 |
protected void adaptDataProviders() { |
|
199 |
updateOrthographicCorrectionRestriction(); |
|
200 |
} |
|
201 |
|
|
202 |
private void updateOrthographicCorrectionRestriction() { |
|
203 |
|
|
204 |
if(getView().isModeEnabled(TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION)){ |
|
205 |
if(orthographicVariantNamePagingProvider == null){ |
|
206 |
orthographicVariantNamePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService()); |
|
207 |
orthographicVariantNamePagingProvider.setInitStrategy(RELATED_NAME_INIT_STRATEGY); |
|
208 |
orthographicVariantNamePagingProvider.addRestriction(new Restriction<>("id", Operator.AND_NOT, null, taxonNameId)); |
|
209 |
getView().getOrthographicVariantField().getRelatedNameComboBox().loadFrom(orthographicVariantNamePagingProvider, orthographicVariantNamePagingProvider, orthographicVariantNamePagingProvider.getPageSize()); |
|
210 |
} |
|
211 |
Reference nomReference = getView().getNomReferenceCombobox().getValue(); |
|
212 |
if(nomReference == null && orthographicCorrectionRestriction != null){ |
|
213 |
orthographicVariantNamePagingProvider.getRestrictions().remove(orthographicCorrectionRestriction); |
|
214 |
} else { |
|
215 |
if(orthographicCorrectionRestriction == null){ |
|
216 |
orthographicCorrectionRestriction = new Restriction<>("nomenclaturalReference", Operator.AND, null, nomReference); |
|
217 |
orthographicVariantNamePagingProvider.addRestriction(orthographicCorrectionRestriction); |
|
218 |
} else{ |
|
219 |
orthographicCorrectionRestriction.setValues(Arrays.asList(nomReference)); |
|
220 |
} |
|
221 |
} |
|
222 |
getView().getOrthographicVariantField().getRelatedNameComboBox().getSelect().refresh(); |
|
223 |
} |
|
224 |
} |
|
225 |
|
|
184 | 226 |
@Override |
185 | 227 |
protected TaxonName loadCdmEntity(UUID identifier) { |
186 | 228 |
|
... | ... | |
255 | 297 |
|
256 | 298 |
} |
257 | 299 |
|
258 |
relatedNamePagingProvider.addRestriction(new Restriction<>("id", Operator.AND_NOT, null, Integer.valueOf(taxonName.getId()))); |
|
300 |
taxonNameId = Integer.valueOf(taxonName.getId()); |
|
301 |
relatedNamePagingProvider.addRestriction(new Restriction<>("id", Operator.AND_NOT, null, taxonNameId)); |
|
259 | 302 |
|
260 | 303 |
return taxonName; |
261 | 304 |
} |
... | ... | |
518 | 561 |
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget()); |
519 | 562 |
|
520 | 563 |
if(boundPropertyId != null){ |
521 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){ |
|
564 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms") || boundPropertyId.matches("orthographicVariant.otherName")){
|
|
522 | 565 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event); |
523 | 566 |
namePopup.withDeleteButton(true); |
524 | 567 |
getView().getModesActive().stream() |
525 | 568 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
526 | 569 |
.forEach(m -> namePopup.enableMode(m)); |
570 |
if(boundPropertyId.matches("orthographicVariant.otherName") && getView().isModeEnabled(TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION)){ |
|
571 |
namePopup.enableMode(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY); |
|
572 |
} |
|
527 | 573 |
namePopup.loadInEditor(event.getEntityUuid()); |
528 | 574 |
} |
529 | 575 |
} |
... | ... | |
560 | 606 |
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget()); |
561 | 607 |
|
562 | 608 |
if(boundPropertyId != null){ |
563 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){ |
|
609 |
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms") || boundPropertyId.matches("orthographicVariant.otherName")){
|
|
564 | 610 |
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event); |
565 | 611 |
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE)); |
566 | 612 |
namePopup.withDeleteButton(true); |
567 | 613 |
getView().getModesActive().stream() |
568 | 614 |
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m)) |
569 | 615 |
.forEach(m -> namePopup.enableMode(m)); |
616 |
Reference nomrefPreset = null; |
|
617 |
if(boundPropertyId.matches("orthographicVariant.otherName") && getView().isModeEnabled(TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION)){ |
|
618 |
namePopup.enableMode(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY); |
|
619 |
nomrefPreset = (Reference)((AbstractPopupEditor<TaxonNameDTO, TaxonNameEditorPresenter>)getView()).getBean().getNomenclaturalReference(); |
|
620 |
if(nomrefPreset != null){ |
|
621 |
// show warning and skip |
|
622 |
Notification.show("The nomenclatural reference needs to be set before creating a new ortographic correction is possible.", Type.HUMANIZED_MESSAGE); |
|
623 |
try { |
|
624 |
namePopup.destroy(); |
|
625 |
} catch (Exception e) { |
|
626 |
throw new RuntimeException(e); |
|
627 |
} |
|
628 |
return; |
|
629 |
} |
|
630 |
} |
|
570 | 631 |
namePopup.loadInEditor(null); |
632 |
if(nomrefPreset != null){ |
|
633 |
namePopup.getNomReferenceCombobox().setValue(nomrefPreset); |
|
634 |
} |
|
571 | 635 |
} |
572 | 636 |
} |
573 | 637 |
} |
Also available in: Unified diff
fix #7899 orthographic variant and corrections implemented in taxon name popup editor