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.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.lang.StringUtils;
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.hibernate.criterion.Restrictions;
|
19
|
import org.springframework.context.annotation.Scope;
|
20
|
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
21
|
|
22
|
import com.vaadin.data.Property;
|
23
|
import com.vaadin.spring.annotation.SpringComponent;
|
24
|
import com.vaadin.ui.AbstractField;
|
25
|
import com.vaadin.ui.Field;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.INameService;
|
28
|
import eu.etaxonomy.cdm.model.agent.AgentBase;
|
29
|
import eu.etaxonomy.cdm.model.agent.Person;
|
30
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
31
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
32
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
33
|
import eu.etaxonomy.cdm.model.common.TermType;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
36
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
37
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
38
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
39
|
import eu.etaxonomy.cdm.model.reference.ReferenceType;
|
40
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
41
|
import eu.etaxonomy.cdm.service.CdmFilterablePagingProvider;
|
42
|
import eu.etaxonomy.cdm.service.TaxonNameStringFilterablePagingProvider;
|
43
|
import eu.etaxonomy.cdm.service.UserHelperAccess;
|
44
|
import eu.etaxonomy.cdm.service.initstrategies.AgentBaseInit;
|
45
|
import eu.etaxonomy.cdm.vaadin.component.CdmBeanItemContainerFactory;
|
46
|
import eu.etaxonomy.cdm.vaadin.event.EditorActionTypeFilter;
|
47
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent;
|
48
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
49
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
50
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorActionStrRep;
|
51
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
|
52
|
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
|
53
|
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
|
54
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
55
|
import eu.etaxonomy.cdm.vaadin.util.CdmTitleCacheCaptionGenerator;
|
56
|
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
|
57
|
import eu.etaxonomy.vaadin.component.CompositeCustomField;
|
58
|
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
|
59
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
60
|
import eu.etaxonomy.vaadin.component.WeaklyRelatedEntityCombobox;
|
61
|
import eu.etaxonomy.vaadin.component.WeaklyRelatedEntityField;
|
62
|
import eu.etaxonomy.vaadin.event.FieldReplaceEvent;
|
63
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOEditorPresenter;
|
64
|
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
|
65
|
import eu.etaxonomy.vaadin.mvp.BeanInstantiator;
|
66
|
import eu.etaxonomy.vaadin.mvp.BoundField;
|
67
|
import eu.etaxonomy.vaadin.ui.view.PopupView;
|
68
|
import eu.etaxonomy.vaadin.util.PropertyIdPath;
|
69
|
|
70
|
/**
|
71
|
* @author a.kohlbecker
|
72
|
* @since May 22, 2017
|
73
|
*
|
74
|
*/
|
75
|
@SpringComponent
|
76
|
@Scope("prototype")
|
77
|
public class TaxonNameEditorPresenter extends AbstractCdmDTOEditorPresenter<TaxonNameDTO, TaxonName, TaxonNamePopupEditorView> {
|
78
|
|
79
|
|
80
|
private static final List<String> BASIONYM_INIT_STRATEGY = Arrays.asList(
|
81
|
"$",
|
82
|
"relationsFromThisName",
|
83
|
"relationsToThisName.type",
|
84
|
"homotypicalGroup.typifiedNames"
|
85
|
);
|
86
|
|
87
|
public static final List<String> REFERENCE_INIT_STRATEGY = Arrays.asList("authorship", "inReference.authorship", "inReference.inReference.authorship", "inReference.inReference.inReference.authorship");
|
88
|
|
89
|
private static final long serialVersionUID = -3538980627079389221L;
|
90
|
|
91
|
private static final Logger logger = Logger.getLogger(TaxonNameEditorPresenter.class);
|
92
|
|
93
|
private CdmFilterablePagingProvider<Reference, Reference> nomReferencePagingProvider;
|
94
|
|
95
|
private Reference publishedUnit;
|
96
|
|
97
|
private BeanInstantiator<Reference> newReferenceInstantiator;
|
98
|
|
99
|
private TaxonNameStringFilterablePagingProvider genusOrUninomialPartPagingProvider;
|
100
|
|
101
|
private TaxonNameStringFilterablePagingProvider specificEpithetPartPagingProvider;
|
102
|
|
103
|
private Property.ValueChangeListener refreshSpecificEpithetComboBoxListener;
|
104
|
|
105
|
/**
|
106
|
* {@inheritDoc}
|
107
|
*/
|
108
|
@Override
|
109
|
public void handleViewEntered() {
|
110
|
|
111
|
super.handleViewEntered();
|
112
|
|
113
|
CdmBeanItemContainerFactory selectFieldFactory = new CdmBeanItemContainerFactory(getRepo());
|
114
|
getView().getRankSelect().setContainerDataSource(selectFieldFactory.buildBeanItemContainer(TermType.Rank));
|
115
|
getView().getRankSelect().setItemCaptionPropertyId("label");
|
116
|
|
117
|
CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase> termOrPersonPagingProvider = new CdmFilterablePagingProvider<AgentBase, TeamOrPersonBase>(getRepo().getAgentService(), TeamOrPersonBase.class);
|
118
|
termOrPersonPagingProvider.setInitStrategy(AgentBaseInit.TEAM_OR_PERSON_INIT_STRATEGY);
|
119
|
CdmFilterablePagingProvider<AgentBase, Person> personPagingProvider = new CdmFilterablePagingProvider<AgentBase, Person>(getRepo().getAgentService(), Person.class);
|
120
|
|
121
|
getView().getCombinationAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
122
|
getView().getCombinationAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
123
|
|
124
|
getView().getExCombinationAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
125
|
getView().getExCombinationAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
126
|
|
127
|
getView().getBasionymAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
128
|
getView().getBasionymAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
129
|
|
130
|
getView().getExBasionymAuthorshipField().setFilterableTeamPagingProvider(termOrPersonPagingProvider, this);
|
131
|
getView().getExBasionymAuthorshipField().setFilterablePersonPagingProvider(personPagingProvider, this);
|
132
|
|
133
|
getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
|
134
|
nomReferencePagingProvider = pagingProviderFactory.referencePagingProvider();
|
135
|
nomReferencePagingProvider.setInitStrategy(REFERENCE_INIT_STRATEGY);
|
136
|
getView().getNomReferenceCombobox().loadFrom(nomReferencePagingProvider, nomReferencePagingProvider, nomReferencePagingProvider.getPageSize());
|
137
|
getView().getNomReferenceCombobox().setNestedButtonStateUpdater(new ToOneRelatedEntityButtonUpdater<Reference>(getView().getNomReferenceCombobox()));
|
138
|
getView().getNomReferenceCombobox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getNomReferenceCombobox(), this));
|
139
|
|
140
|
getView().getBasionymComboboxSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
141
|
|
142
|
CdmFilterablePagingProvider<TaxonName, TaxonName> basionymPagingProvider = new CdmFilterablePagingProvider<TaxonName, TaxonName>(getRepo().getNameService());
|
143
|
basionymPagingProvider.setInitStrategy(BASIONYM_INIT_STRATEGY);
|
144
|
getView().getBasionymComboboxSelect().setPagingProviders(basionymPagingProvider, basionymPagingProvider, basionymPagingProvider.getPageSize(), this);
|
145
|
|
146
|
getView().getReplacedSynonymsComboboxSelect().setCaptionGenerator( new CdmTitleCacheCaptionGenerator<TaxonName>());
|
147
|
// reusing the basionymPagingProvider for the replaced synonyms to benefit from caching
|
148
|
getView().getReplacedSynonymsComboboxSelect().setPagingProviders(basionymPagingProvider, basionymPagingProvider, basionymPagingProvider.getPageSize(), this);
|
149
|
|
150
|
getView().getValidationField().getValidatedNameComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
|
151
|
// reusing the basionymPagingProvider for the replaced synonyms to benefit from caching
|
152
|
getView().getValidationField().getValidatedNameComboBox().loadFrom(basionymPagingProvider, basionymPagingProvider, basionymPagingProvider.getPageSize());
|
153
|
getView().getValidationField().getValidatedNameComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getValidatedNameComboBox(), this));
|
154
|
|
155
|
getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
|
156
|
CdmFilterablePagingProvider<Reference, Reference> icbnCodesPagingProvider = pagingProviderFactory.referencePagingProvider();
|
157
|
icbnCodesPagingProvider.setInitStrategy(REFERENCE_INIT_STRATEGY);
|
158
|
// @formatter:off
|
159
|
// TODO use markers on references instead of isbn. The marker type MarkerType.NOMENCLATURAL_RELEVANT() has already prepared (#7466)
|
160
|
icbnCodesPagingProvider.getCriteria().add(Restrictions.in("isbn", new String[]{
|
161
|
"3-904144-22-7", // Saint Louis Code
|
162
|
"3-906166-48-1", // Vienna Code
|
163
|
"978-3-87429-425-6", // Melbourne Code
|
164
|
"978-3-946583-16-5", // Shenzhen Code
|
165
|
"0-85301-006-4" // ICZN 1999
|
166
|
// ICNB
|
167
|
}));
|
168
|
// @formatter:on
|
169
|
getView().getValidationField().getCitatonComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
|
170
|
getView().getValidationField().getCitatonComboBox().loadFrom(icbnCodesPagingProvider, icbnCodesPagingProvider, icbnCodesPagingProvider.getPageSize());
|
171
|
getView().getValidationField().getCitatonComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getCitatonComboBox(), this));
|
172
|
|
173
|
getView().getAnnotationsField().setAnnotationTypeItemContainer(selectFieldFactory.buildTermItemContainer(
|
174
|
AnnotationType.EDITORIAL().getUuid(), AnnotationType.TECHNICAL().getUuid()));
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* {@inheritDoc}
|
179
|
*/
|
180
|
@Override
|
181
|
protected TaxonName loadCdmEntity(UUID identifier) {
|
182
|
|
183
|
List<String> initStrategy = Arrays.asList(
|
184
|
"$",
|
185
|
"annotations.type",
|
186
|
"annotations.*", // needed as log as we are using a table in FilterableAnnotationsField
|
187
|
"rank.vocabulary", // needed for comparing ranks
|
188
|
|
189
|
"nomenclaturalReference.authorship",
|
190
|
"nomenclaturalReference.inReference.authorship",
|
191
|
"nomenclaturalReference.inReference.inReference.authorship",
|
192
|
"nomenclaturalReference.inReference.inReference.inReference.authorship",
|
193
|
|
194
|
"status.type",
|
195
|
|
196
|
"combinationAuthorship",
|
197
|
"exCombinationAuthorship",
|
198
|
"basionymAuthorship",
|
199
|
"exBasionymAuthorship",
|
200
|
|
201
|
// basionyms: relationsToThisName.fromName
|
202
|
"relationsToThisName.type",
|
203
|
"relationsToThisName.fromName.rank",
|
204
|
"relationsToThisName.fromName.combinationAuthorship",
|
205
|
"relationsToThisName.fromName.exCombinationAuthorship",
|
206
|
"relationsToThisName.fromName.nomenclaturalReference.authorship",
|
207
|
"relationsToThisName.fromName.nomenclaturalReference.inReference.authorship",
|
208
|
"relationsToThisName.fromName.nomenclaturalReference.inReference.inReference.inReference.authorship",
|
209
|
"relationsToThisName.fromName.relationsToThisName",
|
210
|
"relationsToThisName.fromName.relationsFromThisName",
|
211
|
"relationsToThisName.citation",
|
212
|
|
213
|
"relationsFromThisName",
|
214
|
"homotypicalGroup.typifiedNames"
|
215
|
);
|
216
|
|
217
|
TaxonName taxonName;
|
218
|
if(identifier != null){
|
219
|
taxonName = getRepo().getNameService().load(identifier, initStrategy);
|
220
|
} else {
|
221
|
taxonName = createCdmEntity();
|
222
|
}
|
223
|
|
224
|
if(getView().isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY)){
|
225
|
Reference nomRef = taxonName.getNomenclaturalReference();
|
226
|
|
227
|
//getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section));
|
228
|
publishedUnit = nomRef;
|
229
|
while(publishedUnit.isOfType(ReferenceType.Section) && publishedUnit.getInReference() != null){
|
230
|
publishedUnit = nomRef.getInReference();
|
231
|
}
|
232
|
// reduce available references to those which are sections of the publishedUnit and the publishedUnit itself
|
233
|
// nomReferencePagingProvider
|
234
|
nomReferencePagingProvider.getCriteria().add(Restrictions.or(
|
235
|
Restrictions.and(Restrictions.eq("inReference", publishedUnit), Restrictions.eq("type", ReferenceType.Section)),
|
236
|
Restrictions.idEq(publishedUnit.getId())
|
237
|
)
|
238
|
);
|
239
|
// and remove the empty option
|
240
|
getView().getNomReferenceCombobox().getSelect().setNullSelectionAllowed(false);
|
241
|
|
242
|
// new Reference only a sub sections of the publishedUnit
|
243
|
newReferenceInstantiator = new BeanInstantiator<Reference>() {
|
244
|
@Override
|
245
|
public Reference createNewBean() {
|
246
|
Reference newRef = ReferenceFactory.newSection();
|
247
|
newRef.setInReference(publishedUnit);
|
248
|
return newRef;
|
249
|
}
|
250
|
};
|
251
|
|
252
|
}
|
253
|
return taxonName;
|
254
|
}
|
255
|
|
256
|
/**
|
257
|
* {@inheritDoc}
|
258
|
*/
|
259
|
@Override
|
260
|
protected void guaranteePerEntityCRUDPermissions(UUID identifier) {
|
261
|
if(crud != null){
|
262
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(TaxonName.class, identifier, crud, null);
|
263
|
}
|
264
|
|
265
|
}
|
266
|
|
267
|
/**
|
268
|
* {@inheritDoc}
|
269
|
*/
|
270
|
@Override
|
271
|
protected void guaranteePerEntityCRUDPermissions(TaxonName bean) {
|
272
|
if(crud != null){
|
273
|
newAuthorityCreated = UserHelperAccess.userHelper().createAuthorityForCurrentUser(bean, crud, null);
|
274
|
}
|
275
|
}
|
276
|
|
277
|
/**
|
278
|
* {@inheritDoc}
|
279
|
*/
|
280
|
@Override
|
281
|
protected INameService getService() {
|
282
|
return getRepo().getNameService();
|
283
|
}
|
284
|
|
285
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
286
|
public void onReferenceEditorActionAdd(ReferenceEditorAction event) {
|
287
|
|
288
|
if(getView() == null || event.getSourceView() != getView() ){
|
289
|
return;
|
290
|
}
|
291
|
|
292
|
ReferencePopupEditor referenceEditorPopup = openPopupEditor(ReferencePopupEditor.class, event);
|
293
|
|
294
|
referenceEditorPopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
295
|
referenceEditorPopup.withDeleteButton(true);
|
296
|
referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
|
297
|
referenceEditorPopup.loadInEditor(null);
|
298
|
if(newReferenceInstantiator != null){
|
299
|
// this is a bit clumsy, we actually need to inject something like a view configurer
|
300
|
// which can enable, disable fields
|
301
|
referenceEditorPopup.getInReferenceCombobox().setEnabled(false);
|
302
|
referenceEditorPopup.getTypeSelect().setEnabled(false);
|
303
|
}
|
304
|
}
|
305
|
|
306
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
307
|
public void onReferenceEditorActionEdit(ReferenceEditorAction event) {
|
308
|
|
309
|
|
310
|
if(!isFromOwnView(event)){
|
311
|
return;
|
312
|
}
|
313
|
ReferencePopupEditor referenceEditorPopup = openPopupEditor(ReferencePopupEditor.class, event);
|
314
|
|
315
|
referenceEditorPopup.withDeleteButton(true);
|
316
|
referenceEditorPopup.setBeanInstantiator(newReferenceInstantiator);
|
317
|
referenceEditorPopup.loadInEditor(event.getEntityUuid());
|
318
|
if(newReferenceInstantiator != null){
|
319
|
// this is a bit clumsy, we actually need to inject something like a view configurator
|
320
|
// which can enable, disable fields
|
321
|
referenceEditorPopup.getInReferenceCombobox().setEnabled(false);
|
322
|
referenceEditorPopup.getTypeSelect().setEnabled(false);
|
323
|
}
|
324
|
}
|
325
|
|
326
|
@EventBusListenerMethod
|
327
|
public void onFieldReplaceEvent(FieldReplaceEvent<String> event){
|
328
|
|
329
|
PropertyIdPath boundPropertyIdPath = boundPropertyIdPath(event.getNewField());
|
330
|
if(boundPropertyIdPath != null){
|
331
|
TaxonNameDTO taxonNamedto = ((AbstractPopupEditor<TaxonNameDTO, AbstractCdmDTOEditorPresenter<TaxonNameDTO, TaxonName,?>>)getView()).getBean();
|
332
|
if(boundPropertyIdPath.matches("specificEpithet")){
|
333
|
AbstractField<String> genusOrUninomialField = getView().getGenusOrUninomialField();
|
334
|
if(event.getNewField() instanceof CompositeCustomField){
|
335
|
if(specificEpithetPartPagingProvider == null){
|
336
|
specificEpithetPartPagingProvider = new TaxonNameStringFilterablePagingProvider(getRepo().getNameService(), Rank.SPECIES());
|
337
|
}
|
338
|
specificEpithetPartPagingProvider.listenToFields(
|
339
|
genusOrUninomialField,
|
340
|
null, null, null);
|
341
|
specificEpithetPartPagingProvider.excludeNames(taxonNamedto.cdmEntity());
|
342
|
specificEpithetPartPagingProvider.updateFromFields();
|
343
|
WeaklyRelatedEntityCombobox<TaxonName> specificEpithetField = (WeaklyRelatedEntityCombobox<TaxonName>)event.getNewField();
|
344
|
refreshSpecificEpithetComboBoxListener = e -> { specificEpithetField.getSelect().refresh(); specificEpithetField.setValue(null);};
|
345
|
specificEpithetField.loadFrom(specificEpithetPartPagingProvider, specificEpithetPartPagingProvider, specificEpithetPartPagingProvider.getPageSize());
|
346
|
specificEpithetField.setValue(event.getOldField().getValue());
|
347
|
specificEpithetField.reload();
|
348
|
genusOrUninomialField.addValueChangeListener(refreshSpecificEpithetComboBoxListener);
|
349
|
} else {
|
350
|
if(specificEpithetPartPagingProvider != null){
|
351
|
specificEpithetPartPagingProvider.unlistenAllFields();
|
352
|
}
|
353
|
if(refreshSpecificEpithetComboBoxListener != null){
|
354
|
genusOrUninomialField.removeValueChangeListener(refreshSpecificEpithetComboBoxListener);
|
355
|
refreshSpecificEpithetComboBoxListener = null;
|
356
|
}
|
357
|
}
|
358
|
} else if(boundPropertyIdPath.matches("genusOrUninomial")) {
|
359
|
if(event.getNewField() instanceof CompositeCustomField){
|
360
|
if(genusOrUninomialPartPagingProvider == null){
|
361
|
genusOrUninomialPartPagingProvider = new TaxonNameStringFilterablePagingProvider(getRepo().getNameService());
|
362
|
}
|
363
|
genusOrUninomialPartPagingProvider.listenToFields(
|
364
|
null,
|
365
|
getView().getInfraGenericEpithetField(),
|
366
|
getView().getSpecificEpithetField(),
|
367
|
getView().getInfraSpecificEpithetField()
|
368
|
);
|
369
|
genusOrUninomialPartPagingProvider.excludeNames(taxonNamedto.cdmEntity());
|
370
|
WeaklyRelatedEntityCombobox<TaxonName> genusOrUninomialField = (WeaklyRelatedEntityCombobox<TaxonName>)event.getNewField();
|
371
|
genusOrUninomialField.loadFrom(genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider, genusOrUninomialPartPagingProvider.getPageSize());
|
372
|
genusOrUninomialField.setValue(event.getOldField().getValue());
|
373
|
genusOrUninomialField.reload();
|
374
|
}else {
|
375
|
if(genusOrUninomialPartPagingProvider != null){
|
376
|
genusOrUninomialPartPagingProvider.unlistenAllFields();
|
377
|
}
|
378
|
}
|
379
|
|
380
|
}
|
381
|
}
|
382
|
|
383
|
}
|
384
|
|
385
|
@EventBusListenerMethod
|
386
|
public void onEntityChangeEvent(EntityChangeEvent<?> event){
|
387
|
|
388
|
if(event.getSourceView() instanceof AbstractPopupEditor) {
|
389
|
|
390
|
BoundField boundTargetField = boundTargetField((PopupView) event.getSourceView());
|
391
|
|
392
|
if(boundTargetField != null){
|
393
|
if(boundTargetField.matchesPropertyIdPath("genusOrUninomial")){
|
394
|
if(event.isCreateOrModifiedType()){
|
395
|
getCache().load(event.getEntity());
|
396
|
if(getView().getGenusOrUninomialField() instanceof WeaklyRelatedEntityCombobox){
|
397
|
WeaklyRelatedEntityCombobox<TaxonName> weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox<TaxonName>)getView().getGenusOrUninomialField();
|
398
|
if(event.isCreatedType()){
|
399
|
weaklyRelatedEntityCombobox.setValue(((TaxonName)event.getEntity()).getGenusOrUninomial());
|
400
|
weaklyRelatedEntityCombobox.reload();
|
401
|
} else {
|
402
|
weaklyRelatedEntityCombobox.reload();
|
403
|
}
|
404
|
// NOTE: in constrast to the ToOneRelatedEntityCombobox the .discard() does not
|
405
|
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload()
|
406
|
weaklyRelatedEntityCombobox.updateButtons();
|
407
|
}
|
408
|
}
|
409
|
} else
|
410
|
if(boundTargetField.matchesPropertyIdPath("specificEpithet")){
|
411
|
if(event.isCreateOrModifiedType()){
|
412
|
getCache().load(event.getEntity());
|
413
|
|
414
|
if(getView().getSpecificEpithetField() instanceof WeaklyRelatedEntityCombobox){
|
415
|
WeaklyRelatedEntityCombobox weaklyRelatedEntityCombobox = (WeaklyRelatedEntityCombobox)getView().getSpecificEpithetField();
|
416
|
if(event.isCreatedType()){
|
417
|
getView().getSpecificEpithetField().setValue(((TaxonName)event.getEntity()).getSpecificEpithet());
|
418
|
weaklyRelatedEntityCombobox.reload();
|
419
|
} else {
|
420
|
weaklyRelatedEntityCombobox.reload();
|
421
|
}
|
422
|
// NOTE: in constrast to the ToOneRelatedEntityCombobox the .discard() does not
|
423
|
// work here since no datasource is bound to the field, see weaklyRelatedEntityCombobox.reload()
|
424
|
weaklyRelatedEntityCombobox.updateButtons();
|
425
|
}
|
426
|
}
|
427
|
} else
|
428
|
if(boundTargetField.matchesPropertyIdPath("nomenclaturalReference")){
|
429
|
if(event.isCreateOrModifiedType()){
|
430
|
getCache().load(event.getEntity());
|
431
|
if(event.isCreatedType()){
|
432
|
getView().getNomReferenceCombobox().setValue((Reference) event.getEntity());
|
433
|
} else {
|
434
|
getView().getNomReferenceCombobox().reload(); // refreshSelectedValue(modifiedReference);
|
435
|
}
|
436
|
getView().getCombinationAuthorshipField().discard(); //refresh from the datasource
|
437
|
getView().updateAuthorshipFields();
|
438
|
}
|
439
|
} else
|
440
|
if(boundTargetField.matchesPropertyIdPath("validationFor.otherName")){
|
441
|
ReloadableLazyComboBox<TaxonName> otherNameField = asReloadableLazyComboBox(boundTargetField.getField(TaxonName.class));
|
442
|
if(event.isCreateOrModifiedType()){
|
443
|
getCache().load(event.getEntity());
|
444
|
if(event.isCreatedType()){
|
445
|
otherNameField.setValue((TaxonName) event.getEntity());
|
446
|
} else {
|
447
|
otherNameField.reload();
|
448
|
}
|
449
|
} else
|
450
|
if(event.isRemovedType()){
|
451
|
otherNameField.setValue(null);
|
452
|
}
|
453
|
} else
|
454
|
if(boundTargetField.matchesPropertyIdPath("basionyms")){
|
455
|
ReloadableLazyComboBox<TaxonName> basionymSourceField = asReloadableLazyComboBox(boundTargetField.getField(TaxonName.class));
|
456
|
if(event.isCreateOrModifiedType()){
|
457
|
getCache().load(event.getEntity());
|
458
|
if(event.isCreatedType()){
|
459
|
basionymSourceField .setValue((TaxonName) event.getEntity());
|
460
|
} else {
|
461
|
basionymSourceField.reload();
|
462
|
}
|
463
|
getView().getBasionymAuthorshipField().discard(); //refresh from the datasource
|
464
|
getView().getExBasionymAuthorshipField().discard(); //refresh from the datasource
|
465
|
getView().updateAuthorshipFields();
|
466
|
} else
|
467
|
if(event.isRemovedType()){
|
468
|
basionymSourceField.setValue(null);
|
469
|
getView().updateAuthorshipFields();
|
470
|
}
|
471
|
} else
|
472
|
if(boundTargetField.matchesPropertyIdPath("replacedSynonyms")){
|
473
|
ReloadableLazyComboBox<TaxonName> replacedSynonyms = asReloadableLazyComboBox(boundTargetField.getField(TaxonName.class));
|
474
|
if(event.isCreateOrModifiedType()){
|
475
|
getCache().load(event.getEntity());
|
476
|
if(event.isCreatedType()){
|
477
|
replacedSynonyms .setValue((TaxonName) event.getEntity());
|
478
|
} else {
|
479
|
replacedSynonyms.reload();
|
480
|
}
|
481
|
getView().getExCombinationAuthorshipField().discard(); //refresh from the datasource
|
482
|
getView().updateAuthorshipFields();
|
483
|
} else
|
484
|
if(event.isRemovedType()){
|
485
|
replacedSynonyms.setValue(null);
|
486
|
getView().updateAuthorshipFields();
|
487
|
}
|
488
|
}
|
489
|
|
490
|
}
|
491
|
}
|
492
|
}
|
493
|
|
494
|
protected <CDM extends CdmBase> ReloadableLazyComboBox<CDM> asReloadableLazyComboBox(Field<CDM> field){
|
495
|
|
496
|
if(field instanceof ToOneRelatedEntityCombobox){
|
497
|
field = ((ToOneRelatedEntityCombobox<CDM>)field).getSelect();
|
498
|
}
|
499
|
return (ReloadableLazyComboBox<CDM>)field;
|
500
|
}
|
501
|
|
502
|
|
503
|
|
504
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
505
|
public void onTaxonNameEditorActionEdit(TaxonNameEditorAction event) {
|
506
|
|
507
|
if(getView() == null || event.getSourceView() != getView() ){
|
508
|
return;
|
509
|
}
|
510
|
|
511
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
512
|
|
513
|
if(boundPropertyId != null){
|
514
|
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){
|
515
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
516
|
namePopup.withDeleteButton(true);
|
517
|
getView().getModesActive().stream()
|
518
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
519
|
.forEach(m -> namePopup.enableMode(m));
|
520
|
namePopup.loadInEditor(event.getEntityUuid());
|
521
|
}
|
522
|
}
|
523
|
}
|
524
|
|
525
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Edit.class)
|
526
|
public void onTaxonNameEditorActionStrRepEdit(TaxonNameEditorActionStrRep event) {
|
527
|
|
528
|
if(getView() == null || event.getSourceView() != getView() ){
|
529
|
return;
|
530
|
}
|
531
|
|
532
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
533
|
|
534
|
if(boundPropertyId != null){
|
535
|
if(boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")){
|
536
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
537
|
namePopup.withDeleteButton(true);
|
538
|
getView().getModesActive().stream()
|
539
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
540
|
.forEach(m -> namePopup.enableMode(m));
|
541
|
namePopup.loadInEditor(event.getEntityUuid());
|
542
|
}
|
543
|
}
|
544
|
}
|
545
|
|
546
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
547
|
public void onTaxonNameEditorActionAdd(TaxonNameEditorAction event) {
|
548
|
|
549
|
if(getView() == null || event.getSourceView() != getView() ){
|
550
|
return;
|
551
|
}
|
552
|
|
553
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
554
|
|
555
|
if(boundPropertyId != null){
|
556
|
if(boundPropertyId.matches("validationFor.otherName") || boundPropertyId.matches("basionyms") || boundPropertyId.matches("replacedSynonyms")){
|
557
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
558
|
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
559
|
namePopup.withDeleteButton(true);
|
560
|
getView().getModesActive().stream()
|
561
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
562
|
.forEach(m -> namePopup.enableMode(m));
|
563
|
namePopup.loadInEditor(null);
|
564
|
}
|
565
|
}
|
566
|
}
|
567
|
|
568
|
@EventBusListenerMethod(filter = EditorActionTypeFilter.Add.class)
|
569
|
public void onTaxonNameEditorActionStrRepAdd(TaxonNameEditorActionStrRep event) {
|
570
|
|
571
|
if(getView() == null || event.getSourceView() != getView() ){
|
572
|
return;
|
573
|
}
|
574
|
|
575
|
PropertyIdPath boundPropertyId = boundPropertyIdPath(event.getTarget());
|
576
|
|
577
|
if(boundPropertyId != null){
|
578
|
if(boundPropertyId.matches("genusOrUninomial") || boundPropertyId.matches("specificEpithet")){
|
579
|
TaxonNamePopupEditor namePopup = openPopupEditor(TaxonNamePopupEditor.class, event);
|
580
|
namePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
|
581
|
namePopup.withDeleteButton(true);
|
582
|
getView().getModesActive().stream()
|
583
|
.filter(m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
|
584
|
.forEach(m -> namePopup.enableMode(m));
|
585
|
namePopup.loadInEditor(null);
|
586
|
if(boundPropertyId.matches("genusOrUninomial")){
|
587
|
namePopup.getRankSelect().setValue(Rank.GENUS());
|
588
|
}
|
589
|
if(boundPropertyId.matches("specificEpithet")){
|
590
|
namePopup.getGenusOrUninomialField().setValue(getView().getGenusOrUninomialField().getValue());
|
591
|
namePopup.getRankSelect().setValue(Rank.SPECIES());
|
592
|
}
|
593
|
if(WeaklyRelatedEntityField.class.isAssignableFrom(event.getTarget().getClass())){
|
594
|
WeaklyRelatedEntityField<TaxonName> taxoNameField = (WeaklyRelatedEntityField<TaxonName>)event.getTarget();
|
595
|
if(!taxoNameField.isValueInOptions()){
|
596
|
String nameString = event.getTarget().getValue();
|
597
|
if(StringUtils.isNotEmpty(nameString)){
|
598
|
if(boundPropertyId.matches("genusOrUninomial")){
|
599
|
namePopup.getGenusOrUninomialField().setValue(nameString);
|
600
|
}
|
601
|
if(boundPropertyId.matches("specificEpithet")){
|
602
|
namePopup.getSpecificEpithetField().setValue(nameString);
|
603
|
}
|
604
|
}
|
605
|
}
|
606
|
}
|
607
|
}
|
608
|
}
|
609
|
}
|
610
|
|
611
|
/**
|
612
|
* {@inheritDoc}
|
613
|
*/
|
614
|
@Override
|
615
|
protected TaxonNameDTO createDTODecorator(TaxonName cdmEntitiy) {
|
616
|
return new TaxonNameDTO(cdmEntitiy);
|
617
|
}
|
618
|
|
619
|
/**
|
620
|
* {@inheritDoc}
|
621
|
*/
|
622
|
@Override
|
623
|
protected BeanInstantiator<TaxonName> defaultCdmEntityInstantiator() {
|
624
|
return new BeanInstantiator<TaxonName>() {
|
625
|
|
626
|
@Override
|
627
|
public TaxonName createNewBean() {
|
628
|
return TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
|
629
|
}
|
630
|
};
|
631
|
}
|
632
|
|
633
|
|
634
|
|
635
|
|
636
|
}
|