1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.view.name;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.EnumSet;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Optional;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
|
21
|
import org.apache.commons.lang.StringUtils;
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.hibernate.criterion.Restrictions;
|
24
|
import org.springframework.context.annotation.Scope;
|
25
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
26
|
import org.vaadin.viritin.fields.AbstractElementCollection;
|
27
|
|
28
|
import com.vaadin.data.Property;
|
29
|
import com.vaadin.data.util.BeanItemContainer;
|
30
|
import com.vaadin.spring.annotation.SpringComponent;
|
31
|
import com.vaadin.ui.AbstractField;
|
32
|
import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
|
33
|
import com.vaadin.ui.Field;
|
34
|
|
35
|
import eu.etaxonomy.cdm.api.service.INameService;
|
36
|
import eu.etaxonomy.cdm.format.reference.ReferenceEllypsisFormatter;
|
37
|
import eu.etaxonomy.cdm.format.reference.ReferenceEllypsisFormatter.LabelType;
|
38
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
39
|
import eu.etaxonomy.cdm.model.agent.Person;
|
40
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
41
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
42
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
43
|
import eu.etaxonomy.cdm.model.common.Language;
|
44
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCodeEdition;
|
45
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
46
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
47
|
import eu.etaxonomy.cdm.model.name.Rank;
|
48
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
49
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
50
|
import eu.etaxonomy.cdm.model.permission.CRUD;
|
51
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
52
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
53
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
54
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
55
|
import eu.etaxonomy.cdm.model.term.TermType;
|
56
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction;
|
57
|
import eu.etaxonomy.cdm.persistence.dao.common.Restriction.Operator;
|
58
|
import eu.etaxonomy.cdm.persistence.dao.initializer.EntityInitStrategy;
|
59
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
60
|
import eu.etaxonomy.cdm.service.TaxonNameStringFilterablePagingProvider;
|
61
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
62
|
import eu.etaxonomy.cdm.service.initstrategies.AgentBaseInit;
|
63
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
|
64
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
65
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
66
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
67
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorActionStrRep;
|
68
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
|
69
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
70
|
import eu.etaxonomy.cdm.vaadin.model.name.NomenclaturalStatusDTO;
|
71
|
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
|
72
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
73
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
74
|
import eu.etaxonomy.cdm.vaadin.util.ReferenceEllypsisCaptionGenerator;
|
75
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
76
|
import eu.etaxonomy.cdm.vaadin.view.reference.RegistrationUiReferenceEditorFormConfigurator;
|
77
|
import eu.etaxonomy.vaadin.component.CompositeCustomField;
|
78
|
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
|
79
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
80
|
import eu.etaxonomy.vaadin.component.WeaklyRelatedEntityCombobox;
|
81
|
import eu.etaxonomy.vaadin.component.WeaklyRelatedEntityField;
|
82
|
import eu.etaxonomy.vaadin.event.FieldReplaceEvent;
|
83
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOEditorPresenter;
|
84
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
85
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
86
|
import eu.etaxonomy.vaadin.mvp.BoundField;
|
87
|
import eu.etaxonomy.vaadin.ui.view.PopupView;
|
88
|
import eu.etaxonomy.vaadin.util.PropertyIdPath;
|
89
|
|
90
|
/**
|
91
|
* @author a.kohlbecker
|
92
|
* @since May 22, 2017
|
93
|
*
|
94
|
*/
|
95
|
@SpringComponent
|
96
|
@Scope("prototype")
|
97
|
public class TaxonNameEditorPresenter
|
98
|
extends AbstractCdmDTOEditorPresenter<TaxonNameDTO, TaxonName, TaxonNamePopupEditorView> {
|
99
|
|
100
|
private static final long serialVersionUID = -3538980627079389221L;
|
101
|
|
102
|
private static final EnumSet<CRUD> SUB_EDITOR_CRUD = EnumSet.of(CRUD.UPDATE, CRUD.DELETE);
|
103
|
|
104
|
private static final List<String> RELATED_NAME_INIT_STRATEGY = Arrays.asList("$", "nomenclaturalSource.annotations",
|
105
|
"relationsFromThisName", "relationsToThisName.type", "homotypicalGroup.typifiedNames");
|
106
|
|
107
|
public static List<String> REFERENCE_INIT_STRATEGY = ReferenceEllypsisFormatter.INIT_STRATEGY;
|
108
|
|
109
|
private static final Logger logger = Logger.getLogger(TaxonNameEditorPresenter.class);
|
110
|
|
111
|
private CdmFilterablePagingProvider<Reference, Reference> nomReferencePagingProvider;
|
112
|
|
113
|
private Reference publishedUnit;
|
114
|
|
115
|
private BeanInstantiator<Reference> newReferenceInstantiator;
|
116
|
|
117
|
private Map<ReferencePopupEditor, NomenclaturalStatusRow> statusTypeReferencePopupEditorsRowMap = new HashMap<>();
|
118
|
|
119
|
private TaxonNameStringFilterablePagingProvider genusOrUninomialPartPagingProvider;
|
120
|
|
121
|
private TaxonNameStringFilterablePagingProvider specificEpithetPartPagingProvider;
|
122
|
|
123
|
private Property.ValueChangeListener refreshSpecificEpithetComboBoxListener;
|
124
|
|
125
|
private CdmFilterablePagingProvider<TaxonName, TaxonName> relatedNamePagingProvider;
|
126
|
|
127
|
private CdmFilterablePagingProvider<TaxonName, TaxonName> orthographicVariantNamePagingProvider;
|
128
|
|
129
|
private Restriction<Reference> orthographicCorrectionRestriction;
|
130
|
|
131
|
private Integer taxonNameId;
|
132
|
|
133
|
/**
|
134
|
* {@inheritDoc}
|
135
|
*/
|
136
|
@SuppressWarnings("serial")
|
137
|
@Override
|
138
|
public void handleViewEntered() {
|
139
|
|
140
|
super.handleViewEntered();
|
141
|
|
142
|
List<NomenclaturalCodeEdition> nomCodes = NomenclaturalCodeEdition
|
143
|
.forCode(RegistrationUIDefaults.NOMENCLATURAL_CODE);
|
144
|
BeanItemContainer<NomenclaturalCodeEdition> codeEditionItemContainer = cdmBeanItemContainerFactory
|
145
|
.buildEnumTermItemContainer(NomenclaturalCodeEdition.class,
|
146
|
nomCodes.toArray(new NomenclaturalCodeEdition[nomCodes.size()]));
|
147
|
|
148
|
getView().getRankSelect()
|
149
|
.setContainerDataSource(cdmBeanItemContainerFactory.buildTermItemContainer(TermType.Rank));
|
150
|
getView().getRankSelect().setItemCaptionPropertyId("label");
|
151
|
|
152
|
CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> termOrPersonPagingProvider = pagingProviderFactory
|
153
|
.teamOrPersonPagingProvider();
|
154
|
termOrPersonPagingProvider.setInitStrategy(AgentBaseInit.TEAM_OR_PERSON_INIT_STRATEGY);
|
155
|
CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider = pagingProviderFactory
|
156
|
.personPagingProvider();
|
157
|
|
158
|
getView().getCombinationAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
159
|
getView().getCombinationAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
160
|
|
161
|
getView().getExCombinationAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
162
|
getView().getExCombinationAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
163
|
|
164
|
getView().getBasionymAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
165
|
getView().getBasionymAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
166
|
|
167
|
getView().getExBasionymAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
168
|
getView().getExBasionymAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
169
|
|
170
|
nomReferencePagingProvider = pagingProviderFactory.referencePagingProvider();
|
171
|
nomReferencePagingProvider.setInitStrategy(REFERENCE_INIT_STRATEGY);
|
172
|
getView().getNomReferenceCombobox().loadFrom(nomReferencePagingProvider, nomReferencePagingProvider,
|
173
|
nomReferencePagingProvider.getPageSize());
|
174
|
getView().getNomReferenceCombobox().setNestedButtonStateUpdater(
|
175
|
new ToOneRelatedEntityButtonUpdater<Reference>(getView().getNomReferenceCombobox()));
|
176
|
getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(
|
177
|
LabelType.NOMENCLATURAL, getView().getNomReferenceCombobox().getSelect()));
|
178
|
getView().getNomReferenceCombobox().getSelect()
|
179
|
.addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getNomReferenceCombobox(), this));
|
180
|
getView().getNomReferenceCombobox().getSelect()
|
181
|
.addValueChangeListener(e -> updateOrthographicCorrectionRestriction());
|
182
|
|
183
|
CdmFilterablePagingProvider<Reference, Reference> icbnCodesPagingProvider = pagingProviderFactory
|
184
|
.referencePagingProvider();
|
185
|
// @formatter:off
|
186
|
// TODO use markers on references instead of isbn. The marker type
|
187
|
// MarkerType.NOMENCLATURAL_RELEVANT() has already prepared (#7466)
|
188
|
icbnCodesPagingProvider.getCriteria().add(Restrictions.in("isbn", new String[] {
|
189
|
"3-904144-22-7", // Saint Louis Code
|
190
|
"3-906166-48-1", // Vienna Code
|
191
|
"978-3-87429-425-6", // Melbourne Code
|
192
|
"978-3-946583-16-5", // Shenzhen Code
|
193
|
"0-85301-006-4" // ICZN 1999
|
194
|
// ICNB
|
195
|
}));
|
196
|
// @formatter:on
|
197
|
|
198
|
statusTypeReferencePopupEditorsRowMap.clear();
|
199
|
getView().getNomStatusCollectionField().addElementAddedListener(e -> addNomenclaturalStatus(e.getElement()));
|
200
|
getView().getNomStatusCollectionField()
|
201
|
.setEditorInstantiator(new AbstractElementCollection.Instantiator<NomenclaturalStatusRow>() {
|
202
|
|
203
|
@Override
|
204
|
public NomenclaturalStatusRow create() {
|
205
|
NomenclaturalStatusRow row = new NomenclaturalStatusRow();
|
206
|
|
207
|
BeanItemContainer<DefinedTermBase> statusTypeItemContainer = cdmBeanItemContainerFactory
|
208
|
.buildVocabularyTermsItemContainer(
|
209
|
NomenclaturalStatusType.ALTERNATIVE().getVocabulary().getUuid());
|
210
|
row.type.setContainerDataSource(statusTypeItemContainer);
|
211
|
row.type.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
|
212
|
for (DefinedTermBase term : statusTypeItemContainer.getItemIds()) {
|
213
|
row.type.setItemCaption(term,
|
214
|
term.getPreferredRepresentation(Language.DEFAULT()).getAbbreviatedLabel());
|
215
|
}
|
216
|
row.type.setNullSelectionAllowed(false);
|
217
|
|
218
|
row.citation.loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider,
|
219
|
icbnCodesPagingProvider.getPageSize());
|
220
|
row.citation.getSelect().setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(
|
221
|
LabelType.NOMENCLATURAL, row.citation.getSelect()));
|
222
|
row.citation.getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<Reference>(
|
223
|
row.citation.getSelect(), TaxonNameEditorPresenter.this));
|
224
|
row.citation.addClickListenerAddEntity(e -> doReferenceEditorAdd(row));
|
225
|
row.citation.addClickListenerEditEntity(e -> {
|
226
|
if (row.citation.getValue() != null) {
|
227
|
doReferenceEditorEdit(row);
|
228
|
}
|
229
|
});
|
230
|
row.codeEdition.setContainerDataSource(codeEditionItemContainer);
|
231
|
|
232
|
getView().applyDefaultComponentStyle(row.components());
|
233
|
|
234
|
return row;
|
235
|
}
|
236
|
});
|
237
|
|
238
|
relatedNamePagingProvider = pagingProviderFactory.taxonNamesWithoutOrthophicIncorrect();
|
239
|
relatedNamePagingProvider.setInitStrategy(RELATED_NAME_INIT_STRATEGY);
|
240
|
getView().getBasionymComboboxSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
241
|
getView().getBasionymComboboxSelect().setPagingProviders(relatedNamePagingProvider, relatedNamePagingProvider,
|
242
|
relatedNamePagingProvider.getPageSize(), this);
|
243
|
|
244
|
getView().getReplacedSynonymsComboboxSelect()
|
245
|
.setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
246
|
getView().getReplacedSynonymsComboboxSelect().setPagingProviders(relatedNamePagingProvider,
|
247
|
relatedNamePagingProvider, relatedNamePagingProvider.getPageSize(), this);
|
248
|
|
249
|
getView().getValidationField().getRelatedNameComboBox().getSelect()
|
250
|
.setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
251
|
getView().getValidationField().getRelatedNameComboBox().loadFrom(relatedNamePagingProvider,
|
252
|
relatedNamePagingProvider, relatedNamePagingProvider.getPageSize());
|
253
|
getView().getValidationField().getRelatedNameComboBox().getSelect().addValueChangeListener(
|
254
|
new ToOneRelatedEntityReloader<>(getView().getValidationField().getRelatedNameComboBox(), this));
|
255
|
getView().getValidationField().getCitatonComboBox().getSelect()
|
256
|
.setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC,
|
257
|
getView().getValidationField().getCitatonComboBox().getSelect()));
|
258
|
getView().getValidationField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider,
|
259
|
icbnCodesPagingProvider.getPageSize());
|
260
|
getView().getValidationField().getCitatonComboBox().getSelect().addValueChangeListener(
|
261
|
new ToOneRelatedEntityReloader<>(getView().getValidationField().getCitatonComboBox(), this));
|
262
|
getView().getValidationField().getCodeEditionSelect().setContainerDataSource(codeEditionItemContainer);
|
263
|
|
264
|
getView().getOrthographicVariantField().getRelatedNameComboBox().getSelect()
|
265
|
.setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
266
|
getView().getOrthographicVariantField().getRelatedNameComboBox().getSelect().addValueChangeListener(
|
267
|
new ToOneRelatedEntityReloader<>(getView().getOrthographicVariantField().getRelatedNameComboBox(),
|
268
|
this));
|
269
|
getView().getOrthographicVariantField().getRelatedNameComboBox().loadFrom(relatedNamePagingProvider,
|
270
|
relatedNamePagingProvider, relatedNamePagingProvider.getPageSize());
|
271
|
// The Mode TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION will be
|
272
|
// handled in the updateOrthographicCorrectionRestriction() method
|
273
|
getView().getOrthographicVariantField().getCitatonComboBox().getSelect()
|
274
|
.setCaptionGenerator(new ReferenceEllypsisCaptionGenerator(LabelType.BIBLIOGRAPHIC,
|
275
|
getView().getOrthographicVariantField().getCitatonComboBox().getSelect()));
|
276
|
getView().getOrthographicVariantField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider,
|
277
|
icbnCodesPagingProvider, icbnCodesPagingProvider.getPageSize());
|
278
|
getView().getOrthographicVariantField().getCitatonComboBox().getSelect().addValueChangeListener(
|
279
|
new ToOneRelatedEntityReloader<>(getView().getOrthographicVariantField().getCitatonComboBox(), this));
|
280
|
getView().getOrthographicVariantField().getCodeEditionSelect().setContainerDataSource(codeEditionItemContainer);
|
281
|
|
282
|
getView().getAnnotationsField().setAnnotationTypeItemContainer(cdmBeanItemContainerFactory
|
283
|
.buildVocabularyTermsItemContainer(AnnotationType.EDITORIAL().getVocabulary().getUuid()));
|
284
|
}
|
285
|
|
286
|
/**
|
287
|
* @param element
|
288
|
* @return
|
289
|
*/
|
290
|
@Deprecated
|
291
|
private void addNomenclaturalStatus(NomenclaturalStatusDTO element) {
|
292
|
// Nothing to do
|
293
|
}
|
294
|
|
295
|
@Override
|
296
|
protected void adaptDataProviders() {
|
297
|
updateOrthographicCorrectionRestriction();
|
298
|
}
|
299
|
|
300
|
private void updateOrthographicCorrectionRestriction() {
|
301
|
|
302
|
if (getView().isModeEnabled(TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION)) {
|
303
|
if (orthographicVariantNamePagingProvider == null) {
|
304
|
orthographicVariantNamePagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(
|
305
|
getRepo().getNameService());
|
306
|
orthographicVariantNamePagingProvider.setInitStrategy(RELATED_NAME_INIT_STRATEGY);
|
307
|
orthographicVariantNamePagingProvider
|
308
|
.addRestriction(new Restriction<>("id", Operator.AND_NOT, null, taxonNameId));
|
309
|
getView().getOrthographicVariantField().getRelatedNameComboBox().loadFrom(
|
310
|
orthographicVariantNamePagingProvider, orthographicVariantNamePagingProvider,
|
311
|
orthographicVariantNamePagingProvider.getPageSize());
|
312
|
}
|
313
|
Reference nomReference = getView().getNomReferenceCombobox().getValue();
|
314
|
if (nomReference == null && orthographicCorrectionRestriction != null) {
|
315
|
orthographicVariantNamePagingProvider.getRestrictions().remove(orthographicCorrectionRestriction);
|
316
|
} else {
|
317
|
if (orthographicCorrectionRestriction == null) {
|
318
|
orthographicCorrectionRestriction = new Restriction<>("nomenclaturalSource.citation", Operator.AND,
|
319
|
null, nomReference);
|
320
|
orthographicVariantNamePagingProvider.addRestriction(orthographicCorrectionRestriction);
|
321
|
} else {
|
322
|
orthographicCorrectionRestriction.setValues(Arrays.asList(nomReference));
|
323
|
}
|
324
|
}
|
325
|
getView().getOrthographicVariantField().getRelatedNameComboBox().getSelect().refresh();
|
326
|
}
|
327
|
}
|
328
|
|
329
|
@Override
|
330
|
protected TaxonName loadCdmEntity(UUID identifier) {
|
331
|
|
332
|
EntityInitStrategy initStrategy = new EntityInitStrategy(
|
333
|
Arrays.asList(
|
334
|
"$",
|
335
|
"annotations.type",
|
336
|
"annotations.*", // needed as log as we are using a table in FilterableAnnotationsField
|
337
|
"rank.vocabulary", // needed for comparing ranks
|
338
|
|
339
|
"nomenclaturalSource.citation",
|
340
|
"nomenclaturalSource.annotations", // needed to allow access in AnnotatableEntity.checkEmpty()
|
341
|
"nomenclaturalSource.markers", // needed to allow access in AnnotatableEntity.checkEmpty()
|
342
|
"nomenclaturalSource.links", // needed to allow access in OriginalSourceBase.checkEmpty()
|
343
|
|
344
|
"status.type",
|
345
|
"status.source.citation",
|
346
|
"status.source.annotations", // needed to allow access in AnnotatableEntity.checkEmpty()
|
347
|
"status.source.markers", // needed to allow access in AnnotatableEntity.checkEmpty()
|
348
|
"status.source.links", // needed to allow access in AnnotatableEntity.checkEmpty()
|
349
|
|
350
|
"combinationAuthorship",
|
351
|
"exCombinationAuthorship",
|
352
|
"basionymAuthorship",
|
353
|
"exBasionymAuthorship",
|
354
|
|
355
|
// basionyms: relationsToThisName.fromName
|
356
|
"relationsToThisName.type",
|
357
|
"relationsToThisName.fromName.rank",
|
358
|
"relationsToThisName.fromName.combinationAuthorship",
|
359
|
"relationsToThisName.fromName.exCombinationAuthorship",
|
360
|
"relationsToThisName.fromName.nomenclaturalSource.citation.authorship",
|
361
|
"relationsToThisName.fromName.nomenclaturalSource.citation.inReference.authorship",
|
362
|
"relationsToThisName.fromName.nomenclaturalSource.citation.inReference.inReference.inReference.authorship",
|
363
|
"relationsToThisName.fromName.nomenclaturalSource.annotations", // needed to allow access in OriginalSourceBase.checkEmpty()
|
364
|
"relationsToThisName.fromName.nomenclaturalSource.markers", // needed to allow access in OriginalSourceBase.checkEmpty()
|
365
|
"relationsToThisName.fromName.nomenclaturalSource.links", // needed to allow access in OriginalSourceBase.checkEmpty()
|
366
|
"relationsToThisName.fromName.relationsToThisName",
|
367
|
"relationsToThisName.fromName.relationsFromThisName",
|
368
|
"relationsToThisName.source.citation",
|
369
|
"relationsToThisName.source.annotations", // needed to allow access in OriginalSourceBase.checkEmpty()
|
370
|
"relationsToThisName.source.markers", // needed to allow access in OriginalSourceBase.checkEmpty()
|
371
|
"relationsToThisName.source.links", // needed to allow access in OriginalSourceBase.checkEmpty()
|
372
|
"relationsFromThisName",
|
373
|
"homotypicalGroup.typifiedNames"
|
374
|
)
|
375
|
);
|
376
|
initStrategy.extend("nomenclaturalSource.citation", ReferenceEllypsisFormatter.INIT_STRATEGY, false);
|
377
|
initStrategy.extend("status.citation", ReferenceEllypsisFormatter.INIT_STRATEGY, false);
|
378
|
initStrategy.extend("relationsToThisName.citation", ReferenceEllypsisFormatter.INIT_STRATEGY, false);
|
379
|
|
380
|
TaxonName taxonName;
|
381
|
if (identifier != null) {
|
382
|
taxonName = getRepo().getNameService().load(identifier, initStrategy.getPropertyPaths());
|
383
|
} else {
|
384
|
taxonName = createCdmEntity();
|
385
|
}
|
386
|
|
387
|
if (getView().isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY)) {
|
388
|
Reference nomRef = taxonName.getNomenclaturalReference();
|
389
|
|
390
|
// getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section));
|
391
|
publishedUnit = nomRef;
|
392
|
if (publishedUnit != null) {
|
393
|
while (publishedUnit.isOfType(ReferenceType.Section) && publishedUnit.getInReference() != null) {
|
394
|
publishedUnit = nomRef.getInReference();
|
395
|
}
|
396
|
// reduce available references to those which are sections of
|
397
|
// the publishedUnit and the publishedUnit itself
|
398
|
// nomReferencePagingProvider
|
399
|
nomReferencePagingProvider.getCriteria()
|
400
|
.add(Restrictions.or(
|
401
|
Restrictions.and(Restrictions.eq("inReference", publishedUnit),
|
402
|
Restrictions.eq("type", ReferenceType.Section)),
|
403
|
Restrictions.idEq(publishedUnit.getId())));
|
404
|
}
|
405
|
// and remove the empty option
|
406
|
getView().getNomReferenceCombobox().getSelect().setNullSelectionAllowed(false);
|
407
|
|
408
|
// new Reference only a sub sections of the publishedUnit
|
409
|
newReferenceInstantiator = new BeanInstantiator<Reference>() {
|
410
|
@Override
|
411
|
public Reference createNewBean() {
|
412
|
Reference newRef = ReferenceFactory.newSection();
|
413
|
newRef.setInReference(publishedUnit);
|
414
|
return newRef;
|
415
|
}
|
416
|
};
|
417
|
|
418
|
}
|
419
|
|
420
|
taxonNameId = Integer.valueOf(taxonName.getId());
|
421
|
relatedNamePagingProvider.addRestriction(new Restriction<>("id", Operator.AND_NOT, null, taxonNameId));
|
422
|
|
423
|
return taxonName;
|
424
|
}
|
425
|
|
426
|
@Override
|
427
|
protected TaxonNameDTO preSaveBean(TaxonNameDTO bean) {
|
428
|
// ---- sync the name.nomenclaturalStatus set with the modifications
|
429
|
Set<NomenclaturalStatus> removeCandidates = new HashSet<>(bean.cdmEntity().getStatus());
|
430
|
for (NomenclaturalStatusDTO statusDTO : bean.getStatus()) {
|
431
|
if (statusDTO.getId() > 0) {
|
432
|
Optional<NomenclaturalStatus> originalEntity = bean.cdmEntity().getStatus().stream()
|
433
|
.filter(s -> s.getId() == statusDTO.getId()).findFirst();
|
434
|
if (originalEntity.isPresent()) {
|
435
|
statusDTO.update(originalEntity.get());
|
436
|
removeCandidates.remove(originalEntity.get());
|
437
|
} else {
|
438
|
throw new RuntimeException("No original NomenclaturalStatus found for DTO with id="
|
439
|
+ statusDTO.getId() + ". Was the TaxonName modified otherwise when opened in the editor?");
|
440
|
}
|
441
|
} else {
|
442
|
// all new status with id = 0
|
443
|
bean.cdmEntity().addStatus(statusDTO.update(null));
|
444
|
}
|
445
|
}
|
446
|
for(NomenclaturalStatus toBeRemoved : removeCandidates) {
|
447
|
bean.cdmEntity().removeStatus(toBeRemoved);
|
448
|
}
|
449
|
return super.preSaveBean(bean);
|
450
|
}
|
451
|
|
452
|
/**
|
453
|
* {@inheritDoc}
|
454
|
*/
|
455
|
@Override
|
456
|
protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
|
457
|
if (crud != null) {
|
458
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(TaxonName.class,
|
459
|
identifier, crud, null);
|
460
|
}
|
461
|
|
462
|
}
|
463
|
|
464
|
/**
|
465
|
* {@inheritDoc}
|
466
|
*/
|
467
|
@Override
|
468
|
protected void guaranteePerEntityCRUDPermissions(TaxonName bean) {
|
469
|
if (crud != null) {
|
470
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
|
471
|
}
|
472
|
}
|
473
|
|
474
|
/**
|
475
|
* {@inheritDoc}
|
476
|
*/
|
477
|
@Override
|
478
|
protected INameService getService() {
|
479
|
return getRepo().getNameService();
|
480
|
}
|
481
|
|
482
|
public void doReferenceEditorAdd(NomenclaturalStatusRow row) {
|
483
|
|
484
|
ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
|
485
|
|
486
|
referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
|
487
|
referencePopupEditor.grantToCurrentUser(SUB_EDITOR_CRUD);
|
488
|
referencePopupEditor.withDeleteButton(true);
|
489
|
referencePopupEditor.loadInEditor(null);
|
490
|
|
491
|
statusTypeReferencePopupEditorsRowMap.put(referencePopupEditor, row);
|
492
|
}
|
493
|
|
494
|
public void doReferenceEditorEdit(NomenclaturalStatusRow row) {
|
495
|
|
496
|
ReferencePopupEditor referencePopupEditor = openPopupEditor(ReferencePopupEditor.class, null);
|
497
|
referencePopupEditor.withReferenceTypes(RegistrationUIDefaults.MEDIA_REFERENCE_TYPES);
|
498
|
referencePopupEditor.grantToCurrentUser(SUB_EDITOR_CRUD);
|
499
|
referencePopupEditor.withDeleteButton(true);
|
500
|
referencePopupEditor.loadInEditor(row.citation.getValue().getUuid());
|
501
|
|
502
|
statusTypeReferencePopupEditorsRowMap.put(referencePopupEditor, row);
|
503
|
}
|
504
|
|
505
|
/**
|
506
|
* @param referenceEditorPopup
|
507
|
*/
|
508
|
private void configureReferencePopupEditor(ReferencePopupEditor referenceEditorPopup, UUID referenceUUID) {
|
509
|
boolean nomRefSectionEditingOnly = getView()
|
510
|
.isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY);
|
511
|
if (nomRefSectionEditingOnly) {
|
512
|
referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
|
513
|
}
|
514
|
|
515
|
// TODO this should be configurable per UI -
|
516
|
// RegistrationUiReferenceEditorFormConfigurator as spring bean,
|
517
|
// different spring profiles
|
518
|
referenceEditorPopup.setEditorComponentsConfigurator(new RegistrationUiReferenceEditorFormConfigurator(
|
519
|
nomRefSectionEditingOnly && newReferenceInstantiator != null));
|
520
|
|
521
|
referenceEditorPopup.loadInEditor(referenceUUID);
|
522
|
if (!nomRefSectionEditingOnly) {
|
523
|
referenceEditorPopup.getTypeSelect().setValue(ReferenceType.Article);
|
524
|
}
|
525
|
}
|
526
|
|
527
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
528
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
529
|
|
530
|
if (getView() == null || event.getSourceView() != getView()) {
|
531
|
return;
|
532
|
}
|
533
|
|
534
|
ReferencePopupEditor referenceEditorPopup = openPopupEditor(ReferencePopupEditor.class, event);
|
535
|
|
536
|
referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
537
|
referenceEditorPopup.withDeleteButton(true);
|
538
|
configureReferencePopupEditor(referenceEditorPopup, null);
|
539
|
}
|
540
|
|
541
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
542
|
public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
|
543
|
|
544
|
if (!isFromOwnView(event)) {
|
545
|
return;
|
546
|
}
|
547
|
ReferencePopupEditor referenceEditorPopup = openPopupEditor(ReferencePopupEditor.class, event);
|
548
|
|
549
|
referenceEditorPopup.withDeleteButton(true);
|
550
|
configureReferencePopupEditor(referenceEditorPopup, event.getEntityUuid());
|
551
|
}
|
552
|
|
553
|
@EventBusListenerMethod
|
554
|
public void onFieldReplaceEvent(FieldReplaceEvent<String> event) {
|
555
|
|
556
|
PropertyIdPath boundPropertyIdPath = boundPropertyIdPath(event.getNewField());
|
557
|
if (boundPropertyIdPath != null) {
|
558
|
TaxonNameDTO taxonNamedto = ((AbstractPopupEditor<TaxonNameDTO, AbstractCdmDTOEditorPresenter<TaxonNameDTO, TaxonName, ?>>) getView())
|
559
|
.getBean();
|
560
|
if (boundPropertyIdPath.matches("specificEpithet")) {
|
561
|
AbstractField<String> genusOrUninomialField = getView().getGenusOrUninomialField();
|
562
|
if (event.getNewField() instanceof CompositeCustomField) {
|
563
|
if (specificEpithetPartPagingProvider == null) {
|
564
|
specificEpithetPartPagingProvider = new TaxonNameStringFilterablePagingProvider(
|
565
|
getRepo().getNameService(), Rank.SPECIES());
|
566
|
}
|
567
|
specificEpithetPartPagingProvider.listenToFields(genusOrUninomialField, null, null, null);
|
568
|
specificEpithetPartPagingProvider.excludeNames(taxonNamedto.cdmEntity());
|
569
|
specificEpithetPartPagingProvider.updateFromFields();
|
570
|
WeaklyRelatedEntityCombobox<TaxonName> specificEpithetField = (WeaklyRelatedEntityCombobox<TaxonName>) event
|
571
|
.getNewField();
|
572
|
refreshSpecificEpithetComboBoxListener = e -> {
|
573
|
specificEpithetField.getSelect().refresh();
|
574
|
specificEpithetField.setValue(null);
|
575
|
};
|
576
|
specificEpithetField.loadFrom(specificEpithetPartPagingProvider, specificEpithetPartPagingProvider,
|
577
|
specificEpithetPartPagingProvider.getPageSize());
|
578
|
specificEpithetField.setValue(event.getOldField().getValue());
|
579
|
specificEpithetField.reload();
|
580
|
genusOrUninomialField.addValueChangeListener(refreshSpecificEpithetComboBoxListener);
|
581
|
} else {
|
582
|
if (specificEpithetPartPagingProvider != null) {
|
583
|
specificEpithetPartPagingProvider.unlistenAllFields();
|
584
|
}
|
585
|
if (refreshSpecificEpithetComboBoxListener != null) {
|
586
|
genusOrUninomialField.removeValueChangeListener(refreshSpecificEpithetComboBoxListener);
|
587
|
refreshSpecificEpithetComboBoxListener = null;
|
588
|
}
|
589
|
}
|
590
|
} else if (boundPropertyIdPath.matches("genusOrUninomial")) {
|
591
|
if (event.getNewField() instanceof CompositeCustomField) {
|
592
|
if (genusOrUninomialPartPagingProvider == null) {
|
593
|
genusOrUninomialPartPagingProvider = new TaxonNameStringFilterablePagingProvider(
|
594
|
getRepo().getNameService());
|
595
|
}
|
596
|
genusOrUninomialPartPagingProvider.listenToFields(null, getView().getInfraGenericEpithetField(),
|
597
|
getView().getSpecificEpithetField(), getView().getInfraSpecificEpithetField());
|
598
|
genusOrUninomialPartPagingProvider.excludeNames(taxonNamedto.cdmEntity());
|
599
|
WeaklyRelatedEntityCombobox<TaxonName> genusOrUninomialField = (WeaklyRelatedEntityCombobox<TaxonName>) event
|
600
|
.getNewField();
|
601
|
genusOrUninomialField.loadFrom(genusOrUninomialPartPagingProvider,
|
602
|
genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider.getPageSize());
|
603
|
genusOrUninomialField.setValue(event.getOldField().getValue());
|
604
|
genusOrUninomialField.reload();
|
605
|
} else {
|
606
|
if (genusOrUninomialPartPagingProvider != null) {
|
607
|
genusOrUninomialPartPagingProvider.unlistenAllFields();
|
608
|
}
|
609
|
}
|
610
|
|
611
|
}
|
612
|
}
|
613
|
|
614
|
}
|
615
|
|
616
|
@EventBusListenerMethod
|
617
|
public void onEntityChangeEvent(EntityChangeEvent<?> event) {
|
618
|
|
619
|
if (event.getSourceView() instanceof AbstractPopupEditor) {
|
620
|
|
621
|
BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
|
622
|
|
623
|
if (boundTargetField != null) {
|
624
|
if (boundTargetField.matchesPropertyIdPath("genusOrUninomial")) {
|
625
|
if (event.isCreateOrModifiedType()) {
|
626
|
getCache().load(event.getEntity());
|
627
|
if (getView().getGenusOrUninomialField() instanceof WeaklyRelatedEntityCombobox) {
|
628
|
WeaklyRelatedEntityCombobox<TaxonName> weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox<TaxonName>) getView()
|
629
|
.getGenusOrUninomialField();
|
630
|
weaklyRelatedEntityCombobox.setValue(((TaxonName) event.getEntity()).getGenusOrUninomial());
|
631
|
// NOTE: in contrast to the ToOneRelatedEntityCombobox the .discard() does not
|
632
|
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload()
|
633
|
weaklyRelatedEntityCombobox.updateButtons();
|
634
|
}
|
635
|
}
|
636
|
} else if (boundTargetField.matchesPropertyIdPath("specificEpithet")) {
|
637
|
if (event.isCreateOrModifiedType()) {
|
638
|
getCache().load(event.getEntity());
|
639
|
if (getView().getSpecificEpithetField() instanceof WeaklyRelatedEntityCombobox) {
|
640
|
WeaklyRelatedEntityCombobox<TaxonName> weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox<TaxonName>) getView()
|
641
|
.getSpecificEpithetField();
|
642
|
getView().getSpecificEpithetField()
|
643
|
.setValue(((TaxonName) event.getEntity()).getSpecificEpithet());
|
644
|
weaklyRelatedEntityCombobox.reload();
|
645
|
// NOTE: in contrast to the ToOneRelatedEntityCombobox the .discard() does not
|
646
|
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload()
|
647
|
weaklyRelatedEntityCombobox.updateButtons();
|
648
|
}
|
649
|
}
|
650
|
} else if (boundTargetField.matchesPropertyIdPath("nomenclaturalReference")) {
|
651
|
if (event.isCreateOrModifiedType()) {
|
652
|
getCache().load(event.getEntity());
|
653
|
if (event.isCreatedType()) {
|
654
|
getView().getNomReferenceCombobox().setValue((Reference) event.getEntity());
|
655
|
} else {
|
656
|
getView().getNomReferenceCombobox().reload(); // refreshSelectedValue(modifiedReference);
|
657
|
}
|
658
|
getView().getCombinationAuthorshipField().discard(); //refresh from the datasource
|
659
|
getView().updateAuthorshipFields();
|
660
|
}
|
661
|
} else if (boundTargetField.matchesPropertyIdPath("validationFor.otherName")
|
662
|
|| boundTargetField.matchesPropertyIdPath("orthographicVariant.otherName")) {
|
663
|
ReloadableLazyComboBox<TaxonName> otherNameField = asReloadableLazyComboBox(
|
664
|
boundTargetField.getField(TaxonName.class));
|
665
|
TaxonName otherName = (TaxonName) event.getEntity();
|
666
|
if (event.isCreateOrModifiedType()) {
|
667
|
getCache().load(otherName);
|
668
|
if (event.isCreatedType()) {
|
669
|
// TODO use reloadWith((TaxonName)
|
670
|
// event.getEntity()); also in this case?
|
671
|
otherNameField.setValue(otherName);
|
672
|
} else {
|
673
|
otherNameField.reloadWith(otherName);
|
674
|
}
|
675
|
|
676
|
} else if (event.isRemovedType()) {
|
677
|
otherNameField.setValue(null);
|
678
|
}
|
679
|
} else if (boundTargetField.matchesPropertyIdPath("basionyms")) {
|
680
|
ReloadableLazyComboBox<TaxonName> basionymSourceField = asReloadableLazyComboBox(
|
681
|
boundTargetField.getField(TaxonName.class));
|
682
|
if (event.isCreateOrModifiedType()) {
|
683
|
getCache().load(event.getEntity());
|
684
|
if (event.isCreatedType()) {
|
685
|
// TODO use reloadWith((TaxonName)
|
686
|
// event.getEntity()); also in this case?
|
687
|
basionymSourceField.setValue((TaxonName) event.getEntity());
|
688
|
} else {
|
689
|
basionymSourceField.reloadWith((TaxonName) event.getEntity());
|
690
|
}
|
691
|
getView().getBasionymAuthorshipField().discard(); //refresh from the datasource
|
692
|
getView().getExBasionymAuthorshipField().discard(); //refresh from the datasource
|
693
|
getView().updateAuthorshipFields();
|
694
|
} else if (event.isRemovedType()) {
|
695
|
basionymSourceField.setValue(null);
|
696
|
getView().updateAuthorshipFields();
|
697
|
}
|
698
|
} else if (boundTargetField.matchesPropertyIdPath("replacedSynonyms")) {
|
699
|
ReloadableLazyComboBox<TaxonName> replacedSynonyms = asReloadableLazyComboBox(
|
700
|
boundTargetField.getField(TaxonName.class));
|
701
|
if (event.isCreateOrModifiedType()) {
|
702
|
getCache().load(event.getEntity());
|
703
|
if (event.isCreatedType()) {
|
704
|
// TODO use reloadWith((TaxonName)
|
705
|
// event.getEntity()); also in this case?
|
706
|
replacedSynonyms.setValue((TaxonName) event.getEntity());
|
707
|
} else {
|
708
|
replacedSynonyms.reloadWith((TaxonName) event.getEntity());
|
709
|
}
|
710
|
getView().getExCombinationAuthorshipField().discard(); //refresh from the datasource
|
711
|
getView().updateAuthorshipFields();
|
712
|
} else if (event.isRemovedType()) {
|
713
|
replacedSynonyms.setValue(null);
|
714
|
getView().updateAuthorshipFields();
|
715
|
}
|
716
|
}
|
717
|
|
718
|
}
|
719
|
}
|
720
|
}
|
721
|
|
722
|
protected <CDM extends CdmBase> ReloadableLazyComboBox<CDM> asReloadableLazyComboBox(Field<CDM> field) {
|
723
|
|
724
|
if (field instanceof ToOneRelatedEntityCombobox) {
|
725
|
field = ((ToOneRelatedEntityCombobox<CDM>) field).getSelect();
|
726
|
}
|
727
|
return (ReloadableLazyComboBox<CDM>) field;
|
728
|
}
|
729
|
|
730
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
731
|
public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
|
732
|
|
733
|
if (getView() == null || event.getSourceView() != getView()) {
|
734
|
return;
|
735
|
}
|
736
|
|
737
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
738
|
|
739
|
if (boundPropertyId != null) {
|
740
|
if (boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms")
|
741
|
|| boundPropertyId.matches("replacedSynonyms")
|
742
|
|| boundPropertyId.matches("orthographicVariant.otherName")) {
|
743
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
744
|
namePopup.withDeleteButton(true);
|
745
|
getView().getModesActive().stream()
|
746
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
747
|
.forEach(m -> namePopup.enableMode(m));
|
748
|
if (boundPropertyId.matches("orthographicVariant.otherName")
|
749
|
&& getView().isModeEnabled(TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION)) {
|
750
|
namePopup.enableMode(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY);
|
751
|
namePopup.disableMode(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART);
|
752
|
namePopup.getOrthographicVariantToggle().setVisible(false);
|
753
|
}
|
754
|
namePopup.loadInEditor(event.getEntityUuid());
|
755
|
}
|
756
|
}
|
757
|
}
|
758
|
|
759
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
760
|
public void onTaxonNameEditorActionStrRepEdit(TaxonNameEditorActionStrRep event) {
|
761
|
|
762
|
if (getView() == null || event.getSourceView() != getView()) {
|
763
|
return;
|
764
|
}
|
765
|
|
766
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
767
|
|
768
|
if (boundPropertyId != null) {
|
769
|
if (boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")) {
|
770
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
771
|
namePopup.withDeleteButton(true);
|
772
|
getView().getModesActive().stream()
|
773
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
774
|
.forEach(m -> namePopup.enableMode(m));
|
775
|
namePopup.loadInEditor(event.getEntityUuid());
|
776
|
}
|
777
|
}
|
778
|
}
|
779
|
|
780
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
781
|
public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
|
782
|
|
783
|
if (getView() == null || event.getSourceView() != getView()) {
|
784
|
return;
|
785
|
}
|
786
|
|
787
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
788
|
|
789
|
if (boundPropertyId != null) {
|
790
|
if (boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms")
|
791
|
|| boundPropertyId.matches("replacedSynonyms")
|
792
|
|| boundPropertyId.matches("orthographicVariant.otherName")) {
|
793
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
794
|
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
795
|
namePopup.withDeleteButton(true);
|
796
|
getView().getModesActive().stream()
|
797
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
798
|
.forEach(m -> namePopup.enableMode(m));
|
799
|
if (boundPropertyId.matches("orthographicVariant.otherName")
|
800
|
&& getView().isModeEnabled(TaxonNamePopupEditorMode.ORTHOGRAPHIC_CORRECTION)) {
|
801
|
namePopup.enableMode(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY);
|
802
|
namePopup.disableMode(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART);
|
803
|
Reference nomrefPreset = (Reference) ((AbstractPopupEditor<TaxonNameDTO, TaxonNameEditorPresenter>) getView())
|
804
|
.getBean().getNomenclaturalReference();
|
805
|
namePopup.setCdmEntityInstantiator(new BeanInstantiator<TaxonName>() {
|
806
|
|
807
|
@Override
|
808
|
public TaxonName createNewBean() {
|
809
|
TaxonName newTaxonName = TaxonNameFactory
|
810
|
.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
|
811
|
newTaxonName.setNomenclaturalReference(getRepo().getReferenceService()
|
812
|
.load(nomrefPreset.getUuid(), TaxonNameEditorPresenter.REFERENCE_INIT_STRATEGY));
|
813
|
return newTaxonName;
|
814
|
}
|
815
|
});
|
816
|
namePopup.getOrthographicVariantToggle().setVisible(false);
|
817
|
}
|
818
|
namePopup.loadInEditor(null);
|
819
|
}
|
820
|
}
|
821
|
}
|
822
|
|
823
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
824
|
public void onTaxonNameEditorActionStrRepAdd(TaxonNameEditorActionStrRep event) {
|
825
|
|
826
|
if (getView() == null || event.getSourceView() != getView()) {
|
827
|
return;
|
828
|
}
|
829
|
|
830
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
831
|
|
832
|
if (boundPropertyId != null) {
|
833
|
if (boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")) {
|
834
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
835
|
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
836
|
namePopup.withDeleteButton(true);
|
837
|
getView().getModesActive().stream()
|
838
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
839
|
.forEach(m -> namePopup.enableMode(m));
|
840
|
namePopup.loadInEditor(null);
|
841
|
if (boundPropertyId.matches("genusOrUninomial")) {
|
842
|
namePopup.getRankSelect().setValue(Rank.GENUS());
|
843
|
}
|
844
|
if (boundPropertyId.matches("specificEpithet")) {
|
845
|
namePopup.getGenusOrUninomialField().setValue(getView().getGenusOrUninomialField().getValue());
|
846
|
namePopup.getRankSelect().setValue(Rank.SPECIES());
|
847
|
}
|
848
|
if (WeaklyRelatedEntityField.class.isAssignableFrom(event.getTarget().getClass())) {
|
849
|
WeaklyRelatedEntityField<TaxonName> taxoNameField = (WeaklyRelatedEntityField<TaxonName>) event
|
850
|
.getTarget();
|
851
|
if (!taxoNameField.isValueInOptions()) {
|
852
|
String nameString = event.getTarget().getValue();
|
853
|
if (StringUtils.isNotEmpty(nameString)) {
|
854
|
if (boundPropertyId.matches("genusOrUninomial")) {
|
855
|
namePopup.getGenusOrUninomialField().setValue(nameString);
|
856
|
}
|
857
|
if (boundPropertyId.matches("specificEpithet")) {
|
858
|
namePopup.getSpecificEpithetField().setValue(nameString);
|
859
|
}
|
860
|
}
|
861
|
}
|
862
|
}
|
863
|
}
|
864
|
}
|
865
|
}
|
866
|
|
867
|
/**
|
868
|
* {@inheritDoc}
|
869
|
*/
|
870
|
@Override
|
871
|
protected TaxonNameDTO createDTODecorator(TaxonName cdmEntitiy) {
|
872
|
return new TaxonNameDTO(cdmEntitiy);
|
873
|
}
|
874
|
|
875
|
/**
|
876
|
* {@inheritDoc}
|
877
|
*/
|
878
|
@Override
|
879
|
protected BeanInstantiator<TaxonName> defaultCdmEntityInstantiator() {
|
880
|
return new BeanInstantiator<TaxonName>() {
|
881
|
|
882
|
@Override
|
883
|
public TaxonName createNewBean() {
|
884
|
return TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
|
885
|
}
|
886
|
};
|
887
|
}
|
888
|
|
889
|
}
|