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.Collection;
|
12
|
import java.util.EnumSet;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.commons.lang3.BooleanUtils;
|
19
|
import org.apache.log4j.Level;
|
20
|
import org.springframework.context.annotation.Scope;
|
21
|
import org.springframework.security.core.GrantedAuthority;
|
22
|
import org.vaadin.viritin.fields.LazyComboBox;
|
23
|
|
24
|
import com.vaadin.data.Property;
|
25
|
import com.vaadin.data.Property.ValueChangeListener;
|
26
|
import com.vaadin.shared.ui.label.ContentMode;
|
27
|
import com.vaadin.spring.annotation.SpringComponent;
|
28
|
import com.vaadin.ui.AbstractField;
|
29
|
import com.vaadin.ui.Alignment;
|
30
|
import com.vaadin.ui.CheckBox;
|
31
|
import com.vaadin.ui.GridLayout;
|
32
|
import com.vaadin.ui.Label;
|
33
|
import com.vaadin.ui.ListSelect;
|
34
|
import com.vaadin.ui.TextField;
|
35
|
|
36
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
37
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
38
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
39
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
40
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
41
|
import eu.etaxonomy.cdm.model.name.Rank;
|
42
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
43
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
44
|
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
|
45
|
import eu.etaxonomy.cdm.vaadin.component.common.FilterableAnnotationsField;
|
46
|
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
|
47
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
48
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
49
|
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
|
50
|
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
|
51
|
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
|
52
|
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
|
53
|
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUIDefaults;
|
54
|
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
|
55
|
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
|
56
|
import eu.etaxonomy.vaadin.component.NameRelationField;
|
57
|
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
|
58
|
import eu.etaxonomy.vaadin.component.SwitchableTextField;
|
59
|
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
|
60
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
61
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
62
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOPopupEditor;
|
63
|
|
64
|
/**
|
65
|
* @author a.kohlbecker
|
66
|
* @since May 22, 2017
|
67
|
*
|
68
|
*/
|
69
|
@SpringComponent
|
70
|
@Scope("prototype")
|
71
|
public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO, TaxonName, TaxonNameEditorPresenter>
|
72
|
implements TaxonNamePopupEditorView, AccessRestrictedView{
|
73
|
|
74
|
private static final long serialVersionUID = -7037436241474466359L;
|
75
|
|
76
|
private final static int GRID_COLS = 4;
|
77
|
|
78
|
private final static int GRID_ROWS = 17;
|
79
|
|
80
|
private static final boolean HAS_BASIONYM_DEFAULT = false;
|
81
|
|
82
|
private AbstractField<String> genusOrUninomialField;
|
83
|
|
84
|
private AbstractField<String> infraGenericEpithetField;
|
85
|
|
86
|
private AbstractField<String> specificEpithetField;
|
87
|
|
88
|
private AbstractField<String> infraSpecificEpithetField;
|
89
|
|
90
|
private SwitchableTextField fullTitleCacheFiled;
|
91
|
|
92
|
private SwitchableTextField protectedNameCacheField;
|
93
|
|
94
|
private ToOneRelatedEntityCombobox<Reference> nomReferenceCombobox;
|
95
|
|
96
|
private TextField nomenclaturalReferenceDetail;
|
97
|
|
98
|
private TeamOrPersonField exBasionymAuthorshipField;
|
99
|
|
100
|
private TeamOrPersonField basionymAuthorshipField;
|
101
|
|
102
|
private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymsComboboxSelect;
|
103
|
|
104
|
private ToManyRelatedEntitiesComboboxSelect<TaxonName> replacedSynonymsComboboxSelect;
|
105
|
|
106
|
private NameRelationField validationField;
|
107
|
|
108
|
private CheckBox basionymToggle;
|
109
|
|
110
|
private CheckBox replacedSynonymsToggle;
|
111
|
|
112
|
private CheckBox validationToggle;
|
113
|
|
114
|
private ListSelect rankSelect;
|
115
|
|
116
|
private TeamOrPersonField combinationAuthorshipField;
|
117
|
|
118
|
private TeamOrPersonField exCombinationAuthorshipField;
|
119
|
|
120
|
private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class);
|
121
|
|
122
|
private Boolean isInferredCombinationAuthorship = null;
|
123
|
|
124
|
private Boolean isInferredBasionymAuthorship = null;
|
125
|
|
126
|
private Boolean isInferredExBasionymAuthorship = null;
|
127
|
|
128
|
private Map<AbstractField, Property.ValueChangeListener> authorshipUpdateListeners = new HashMap<>();
|
129
|
|
130
|
private Boolean isInferredExCombinationAuthorship;
|
131
|
|
132
|
private int specificEpithetFieldRow;
|
133
|
|
134
|
private ValueChangeListener updateFieldVisibilityListener = e -> updateFieldVisibility();
|
135
|
|
136
|
private FilterableAnnotationsField annotationsListField;
|
137
|
|
138
|
private AnnotationType[] editableAnotationTypes = RegistrationUIDefaults.EDITABLE_ANOTATION_TYPES;
|
139
|
|
140
|
private int genusOrUninomialRow;
|
141
|
|
142
|
/**
|
143
|
* By default AnnotationType.EDITORIAL() is enabled.
|
144
|
*
|
145
|
* @return the editableAnotationTypes
|
146
|
*/
|
147
|
@Override
|
148
|
public AnnotationType[] getEditableAnotationTypes() {
|
149
|
return editableAnotationTypes;
|
150
|
}
|
151
|
|
152
|
/**
|
153
|
* By default AnnotationType.EDITORIAL() is enabled.
|
154
|
*
|
155
|
*
|
156
|
* @param editableAnotationTypes the editableAnotationTypes to set
|
157
|
*/
|
158
|
@Override
|
159
|
public void setEditableAnotationTypes(AnnotationType ... editableAnotationTypes) {
|
160
|
this.editableAnotationTypes = editableAnotationTypes;
|
161
|
}
|
162
|
|
163
|
/**
|
164
|
* @param layout
|
165
|
* @param dtoType
|
166
|
*/
|
167
|
public TaxonNamePopupEditor() {
|
168
|
super(new GridLayout(GRID_COLS, GRID_ROWS), TaxonNameDTO.class);
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* {@inheritDoc}
|
173
|
*/
|
174
|
@Override
|
175
|
public String getWindowCaption() {
|
176
|
return "Name editor";
|
177
|
}
|
178
|
|
179
|
|
180
|
/**
|
181
|
* {@inheritDoc}
|
182
|
*/
|
183
|
@Override
|
184
|
public int getWindowWidth() {
|
185
|
return 800;
|
186
|
}
|
187
|
|
188
|
/**
|
189
|
* {@inheritDoc}
|
190
|
*/
|
191
|
@Override
|
192
|
public void focusFirst() {
|
193
|
// titleField.focus();
|
194
|
|
195
|
}
|
196
|
|
197
|
/**
|
198
|
* {@inheritDoc}
|
199
|
*/
|
200
|
@Override
|
201
|
protected String getDefaultComponentStyles() {
|
202
|
return "tiny";
|
203
|
}
|
204
|
|
205
|
/**
|
206
|
* {@inheritDoc}
|
207
|
*/
|
208
|
@Override
|
209
|
protected void initContent() {
|
210
|
|
211
|
GridLayout grid = (GridLayout)getFieldLayout();
|
212
|
grid.setSizeFull();
|
213
|
grid.setHideEmptyRowsAndColumns(true);
|
214
|
grid.setSpacing(true);
|
215
|
grid.setColumnExpandRatio(0, 0.3f);
|
216
|
grid.setColumnExpandRatio(1, 0.3f);
|
217
|
grid.setColumnExpandRatio(2, 0.3f);
|
218
|
grid.setColumnExpandRatio(3, 0.0f);
|
219
|
|
220
|
/*
|
221
|
- nameType: preset, needs to be set in the presenter for new names
|
222
|
- appendedPhrase: -> TODO field
|
223
|
- nomenclaturalMicroReference: -> TODO field
|
224
|
- nomenclaturalReference -> field but disabled for REGISTRY
|
225
|
- rank -> SelectField which determines the visiblity of the other fields
|
226
|
|
227
|
- fullTitleCache + protectedFullTitleCache -> SwitchableTextField : ADVANCED_MODE
|
228
|
- nameCache + protectedNameCache -> SwitchableTextField : ADVANCED_MODE
|
229
|
|
230
|
- homotypicalGroup -> hidden
|
231
|
- typeDesignations -> hidden
|
232
|
- descriptions -> hidden
|
233
|
- taxonBases -> hidden
|
234
|
- registrations -> hidden
|
235
|
|
236
|
- relationsFromThisName-> TODO implement later
|
237
|
- relationsToThisName -> TODO implement later
|
238
|
|
239
|
- genusOrUninomial -> textField
|
240
|
- infraGenericEpithet -> textField
|
241
|
- specificEpithet -> textField
|
242
|
- infraSpecificEpithet -> textField
|
243
|
|
244
|
- authorshipCache + protectedAuthorshipCache -> SwitchableTextField : only ADVANCED_MODE and disabled for REGISTRY
|
245
|
- basionymAuthorship -> field but disabled for REGISTRY, basionym is set as nameRelationShip
|
246
|
- combinationAuthorship -> field but disabled for REGISTRY author team of the reference
|
247
|
- exCombinationAuthorship -> textField
|
248
|
- exBasionymAuthorship -> textField
|
249
|
|
250
|
- status -> TODO field
|
251
|
- monomHybrid -> TODO implement hybrids later
|
252
|
- binomHybrid -> TODO implement hybrids later
|
253
|
- trinomHybrid -> TODO implement hybrids later
|
254
|
|
255
|
- hybridParentRelations -> TODO implement hybrids later
|
256
|
- hybridChildRelations -> TODO implement hybrids later
|
257
|
- hybridFormula -> TODO implement hybrids later
|
258
|
|
259
|
** ViralName attributes **
|
260
|
- acronym
|
261
|
|
262
|
** BacterialName attributes **
|
263
|
- subGenusAuthorship
|
264
|
- nameApprobation
|
265
|
- breed
|
266
|
- publicationYear
|
267
|
- originalPublicationYear
|
268
|
- cultivarName
|
269
|
*/
|
270
|
|
271
|
int row = 0;
|
272
|
|
273
|
rankSelect = new ListSelect("Rank");
|
274
|
rankSelect.setNullSelectionAllowed(false);
|
275
|
rankSelect.setRows(1);
|
276
|
rankSelect.setWidth(100, Unit.PERCENTAGE);
|
277
|
addField(rankSelect, "rank", 0, row, 1, row);
|
278
|
grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT);
|
279
|
|
280
|
basionymToggle = new CheckBox("With basionym");
|
281
|
basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
|
282
|
|
283
|
basionymToggle.setStyleName(getDefaultComponentStyles());
|
284
|
grid.addComponent(basionymToggle, 2, row, 3, row);
|
285
|
grid.setComponentAlignment(basionymToggle, Alignment.BOTTOM_LEFT);
|
286
|
|
287
|
row++;
|
288
|
replacedSynonymsToggle = new CheckBox("With replaced synonym");
|
289
|
grid.addComponent(replacedSynonymsToggle, 2, row, 3, row);
|
290
|
grid.setComponentAlignment(replacedSynonymsToggle, Alignment.BOTTOM_LEFT);
|
291
|
|
292
|
row++;
|
293
|
validationToggle = new CheckBox("Validation");
|
294
|
|
295
|
grid.addComponent(validationToggle, 2, row, 3, row);
|
296
|
grid.setComponentAlignment(validationToggle, Alignment.BOTTOM_LEFT);
|
297
|
|
298
|
row++;
|
299
|
// fullTitleCache
|
300
|
fullTitleCacheFiled = addSwitchableTextField("Full title cache", "fullTitleCache", "protectedFullTitleCache", 0, row, GRID_COLS-1, row);
|
301
|
fullTitleCacheFiled.setWidth(100, Unit.PERCENTAGE);
|
302
|
row++;
|
303
|
protectedNameCacheField = addSwitchableTextField("Name cache", "nameCache", "protectedNameCache", 0, row, GRID_COLS-1, row);
|
304
|
protectedNameCacheField.setWidth(100, Unit.PERCENTAGE);
|
305
|
row++;
|
306
|
genusOrUninomialRow = row;
|
307
|
genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
|
308
|
genusOrUninomialField.setWidth(200, Unit.PIXELS);
|
309
|
infraGenericEpithetField = addTextField("Infrageneric epithet", "infraGenericEpithet", 2, row, 3, row);
|
310
|
infraGenericEpithetField.setWidth(200, Unit.PIXELS);
|
311
|
row++;
|
312
|
specificEpithetFieldRow = row;
|
313
|
specificEpithetField = addTextField("Specific epithet", "specificEpithet", 0, row, 1, row);
|
314
|
specificEpithetField.setWidth(200, Unit.PIXELS);
|
315
|
infraSpecificEpithetField = addTextField("Infraspecific epithet", "infraSpecificEpithet", 2, row, 3, row);
|
316
|
infraSpecificEpithetField.setWidth(200, Unit.PIXELS);
|
317
|
|
318
|
row++;
|
319
|
grid.addComponent(new Label("Hint: <i>Edit nomenclatural authors in the nomenclatural reference.</i>", ContentMode.HTML), 0, row, 3, row);
|
320
|
|
321
|
row++;
|
322
|
combinationAuthorshipField = new TeamOrPersonField("Combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
323
|
combinationAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
324
|
addField(combinationAuthorshipField, "combinationAuthorship", 0, row, GRID_COLS-1, row);
|
325
|
|
326
|
row++;
|
327
|
nomReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("Nomenclatural reference", Reference.class);
|
328
|
nomReferenceCombobox.addClickListenerAddEntity(e -> getViewEventBus().publish(
|
329
|
this,
|
330
|
new ReferenceEditorAction(EditorActionType.ADD, null, nomReferenceCombobox, this)
|
331
|
));
|
332
|
nomReferenceCombobox.addClickListenerEditEntity(e -> {
|
333
|
if(nomReferenceCombobox.getValue() != null){
|
334
|
getViewEventBus().publish(this,
|
335
|
new ReferenceEditorAction(
|
336
|
EditorActionType.EDIT,
|
337
|
nomReferenceCombobox.getValue().getUuid(),
|
338
|
e.getButton(),
|
339
|
nomReferenceCombobox,
|
340
|
this)
|
341
|
);
|
342
|
}
|
343
|
});
|
344
|
logger.setLevel(Level.DEBUG);
|
345
|
// nomReferenceCombobox.getSelect().addValueChangeListener(e -> logger.debug("nomReferenceCombobox value changed #1"));
|
346
|
// nomReferenceCombobox.setWidth(300, Unit.PIXELS);
|
347
|
nomReferenceCombobox.setWidth("100%");
|
348
|
addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 2, row);
|
349
|
nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
|
350
|
nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
|
351
|
|
352
|
// --------------- Basionyms
|
353
|
row++;
|
354
|
basionymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
|
355
|
basionymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
|
356
|
addField(basionymsComboboxSelect, "basionyms", 0, row, 3, row);
|
357
|
basionymsComboboxSelect.setWidth(100, Unit.PERCENTAGE);
|
358
|
basionymsComboboxSelect.withEditButton(true);
|
359
|
basionymsComboboxSelect.setEditPermissionTester(new CdmEditDeletePermissionTester());
|
360
|
basionymsComboboxSelect.setEditActionListener(e -> {
|
361
|
|
362
|
Object fieldValue = e.getSource().getValue();
|
363
|
UUID beanUuid = null;
|
364
|
if(fieldValue != null){
|
365
|
beanUuid = ((CdmBase)fieldValue).getUuid();
|
366
|
|
367
|
}
|
368
|
ReloadableLazyComboBox<TaxonName> lazyCombobox = (ReloadableLazyComboBox<TaxonName>) e.getSource();
|
369
|
getViewEventBus().publish(this, new TaxonNameEditorAction(e.getAction(), beanUuid, null, lazyCombobox, this));
|
370
|
});
|
371
|
grid.setComponentAlignment(basionymsComboboxSelect, Alignment.TOP_RIGHT);
|
372
|
|
373
|
row++;
|
374
|
basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
375
|
basionymAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
376
|
addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
|
377
|
row++;
|
378
|
exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
379
|
exBasionymAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
380
|
addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
|
381
|
|
382
|
// --------------- ReplacedSynonyms
|
383
|
row++;
|
384
|
replacedSynonymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Replaced synonyms");
|
385
|
replacedSynonymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
|
386
|
addField(replacedSynonymsComboboxSelect, "replacedSynonyms", 0, row, 3, row);
|
387
|
replacedSynonymsComboboxSelect.setWidth(100, Unit.PERCENTAGE);
|
388
|
replacedSynonymsComboboxSelect.withEditButton(true);
|
389
|
replacedSynonymsComboboxSelect.setEditPermissionTester(new CdmEditDeletePermissionTester());
|
390
|
replacedSynonymsComboboxSelect.setEditActionListener(e -> {
|
391
|
|
392
|
Object fieldValue = e.getSource().getValue();
|
393
|
UUID beanUuid = null;
|
394
|
if(fieldValue != null){
|
395
|
beanUuid = ((CdmBase)fieldValue).getUuid();
|
396
|
|
397
|
}
|
398
|
ReloadableLazyComboBox<TaxonName> lazyCombobox = (ReloadableLazyComboBox<TaxonName>) e.getSource();
|
399
|
getViewEventBus().publish(this, new TaxonNameEditorAction(e.getAction(), beanUuid, null, lazyCombobox, this));
|
400
|
});
|
401
|
grid.setComponentAlignment(replacedSynonymsComboboxSelect, Alignment.TOP_RIGHT);
|
402
|
|
403
|
// --------------- Validation
|
404
|
row++;
|
405
|
validationField = new NameRelationField("Validation", Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
|
406
|
validationField.setWidth(100, Unit.PERCENTAGE);
|
407
|
ToOneRelatedEntityCombobox<TaxonName> validatedNameComboBox = validationField.getValidatedNameComboBox();
|
408
|
validatedNameComboBox.addClickListenerAddEntity(e -> getViewEventBus().publish(
|
409
|
this,
|
410
|
new TaxonNameEditorAction(EditorActionType.ADD, null, validatedNameComboBox, this)
|
411
|
));
|
412
|
validatedNameComboBox.addClickListenerEditEntity(e -> {
|
413
|
if(validatedNameComboBox.getValue() != null){
|
414
|
getViewEventBus().publish(this,
|
415
|
new TaxonNameEditorAction(
|
416
|
EditorActionType.EDIT,
|
417
|
validatedNameComboBox.getValue().getUuid(),
|
418
|
e.getButton(),
|
419
|
validatedNameComboBox,
|
420
|
this)
|
421
|
);
|
422
|
}
|
423
|
});
|
424
|
ToOneRelatedEntityCombobox<Reference> validationCitatonComboBox = validationField.getCitatonComboBox();
|
425
|
validationCitatonComboBox.addClickListenerAddEntity(e -> getViewEventBus().publish(
|
426
|
this,
|
427
|
new ReferenceEditorAction(EditorActionType.ADD, null, validationCitatonComboBox, this)
|
428
|
));
|
429
|
validationCitatonComboBox.addClickListenerEditEntity(e -> {
|
430
|
if(validationCitatonComboBox.getValue() != null){
|
431
|
getViewEventBus().publish(this,
|
432
|
new ReferenceEditorAction(
|
433
|
EditorActionType.EDIT,
|
434
|
validationCitatonComboBox.getValue().getUuid(),
|
435
|
e.getButton(),
|
436
|
validationCitatonComboBox,
|
437
|
this)
|
438
|
);
|
439
|
}
|
440
|
});
|
441
|
addField(validationField, "validationFor", 0, row, 3, row);
|
442
|
grid.setComponentAlignment(validationField, Alignment.TOP_RIGHT);
|
443
|
|
444
|
row++;
|
445
|
exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
446
|
exCombinationAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
447
|
addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
|
448
|
|
449
|
row++;
|
450
|
annotationsListField = new FilterableAnnotationsField("Editorial notes");
|
451
|
annotationsListField.setWidth(100, Unit.PERCENTAGE);
|
452
|
annotationsListField.setAnnotationTypesVisible(editableAnotationTypes);
|
453
|
addField(annotationsListField, "annotations", 0, row, GRID_COLS-1, row);
|
454
|
|
455
|
// -----------------------------------------------------------------------------
|
456
|
|
457
|
setAdvancedModeEnabled(true);
|
458
|
registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
|
459
|
|
460
|
registerAdvancedModeComponents(combinationAuthorshipField);
|
461
|
registerAdvancedModeComponents(basionymAuthorshipField);
|
462
|
registerAdvancedModeComponents(exBasionymAuthorshipField);
|
463
|
registerAdvancedModeComponents(exCombinationAuthorshipField);
|
464
|
|
465
|
registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
|
466
|
registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
|
467
|
registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
|
468
|
registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
|
469
|
|
470
|
setAdvancedMode(false);
|
471
|
|
472
|
}
|
473
|
|
474
|
protected TeamOrPersonBase inferBasiomynAuthors() {
|
475
|
List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
|
476
|
if(!basionyms.isEmpty() && basionyms.get(0) != null){
|
477
|
TaxonName basionym = basionyms.get(0);
|
478
|
if(basionym.getCombinationAuthorship() != null){
|
479
|
return basionym.getCombinationAuthorship();
|
480
|
} else if(basionym.getNomenclaturalReference() != null){
|
481
|
return basionym.getNomenclaturalReference().getAuthorship();
|
482
|
}
|
483
|
}
|
484
|
return null;
|
485
|
}
|
486
|
|
487
|
protected TeamOrPersonBase inferExBasiomynAuthors() {
|
488
|
List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
|
489
|
if(!basionyms.isEmpty() && basionyms.get(0) != null){
|
490
|
TaxonName basionym = basionyms.get(0);
|
491
|
return basionym.getExCombinationAuthorship();
|
492
|
}
|
493
|
return null;
|
494
|
}
|
495
|
|
496
|
protected TeamOrPersonBase inferCombinationAuthors() {
|
497
|
Reference nomRef = nomReferenceCombobox.getValue();
|
498
|
if(nomRef != null) {
|
499
|
return nomRef.getAuthorship();
|
500
|
}
|
501
|
return null;
|
502
|
}
|
503
|
|
504
|
protected TeamOrPersonBase inferExCombinationAuthors() {
|
505
|
NameRelationshipDTO nameRelationDTO = validationField.getValue();
|
506
|
if(nameRelationDTO != null && nameRelationDTO.getOtherName() != null){
|
507
|
TaxonName validatedName = nameRelationDTO.getOtherName();
|
508
|
if(validatedName.getCombinationAuthorship() != null) {
|
509
|
return validatedName.getCombinationAuthorship();
|
510
|
} else if(validatedName.getNomenclaturalReference() != null){
|
511
|
return validatedName.getNomenclaturalReference().getAuthorship();
|
512
|
}
|
513
|
}
|
514
|
return null;
|
515
|
}
|
516
|
|
517
|
@Override
|
518
|
protected void afterItemDataSourceSet() {
|
519
|
|
520
|
|
521
|
rankSelect.addValueChangeListener(updateFieldVisibilityListener);
|
522
|
basionymToggle.addValueChangeListener(e -> {
|
523
|
updateAuthorshipFields();
|
524
|
});
|
525
|
validationToggle.addValueChangeListener(e -> {
|
526
|
updateAuthorshipFields();
|
527
|
});
|
528
|
replacedSynonymsToggle.addValueChangeListener(e -> {
|
529
|
boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
|
530
|
replacedSynonymsComboboxSelect.setVisible(enable);
|
531
|
});
|
532
|
|
533
|
|
534
|
TaxonNameDTO taxonNameDTO = getBean();
|
535
|
boolean showBasionymSection = taxonNameDTO.getBasionyms().size() > 0
|
536
|
|| taxonNameDTO.getBasionymAuthorship() != null
|
537
|
|| taxonNameDTO.getExBasionymAuthorship() != null;
|
538
|
basionymToggle.setValue(showBasionymSection);
|
539
|
basionymToggle.setReadOnly(showBasionymSection);
|
540
|
|
541
|
boolean showReplacedSynonyms = taxonNameDTO.getReplacedSynonyms().size() > 0;
|
542
|
replacedSynonymsToggle.setValue(showReplacedSynonyms);
|
543
|
replacedSynonymsToggle.setReadOnly(showReplacedSynonyms);
|
544
|
replacedSynonymsComboboxSelect.setVisible(showReplacedSynonyms);
|
545
|
|
546
|
boolean showValidationSection = taxonNameDTO.getValidationFor() != null || taxonNameDTO.getExCombinationAuthorship() != null;
|
547
|
|
548
|
validationToggle.setValue(showValidationSection);
|
549
|
validationToggle.setReadOnly(showValidationSection);
|
550
|
// validationField.setVisible(showValidation);
|
551
|
// exCombinationAuthorshipField.setVisible(showExAuthors);
|
552
|
|
553
|
if(isModeEnabled(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
|
554
|
updateAuthorshipFields();
|
555
|
}
|
556
|
if(isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY) && getBean().getNomenclaturalReference() != null) {
|
557
|
nomReferenceCombobox.setCaption("Selection limited to nomenclatural reference and sections");
|
558
|
}
|
559
|
if(isModeEnabled(TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE)) {
|
560
|
if(combinationAuthorshipField.getValue() == null){
|
561
|
nomReferenceCombobox.setRequired(true);
|
562
|
} else {
|
563
|
combinationAuthorshipField.addValueChangeListener(e -> {
|
564
|
if(e.getProperty().getValue() == null){
|
565
|
nomReferenceCombobox.setRequired(true);
|
566
|
}
|
567
|
});
|
568
|
}
|
569
|
}
|
570
|
|
571
|
}
|
572
|
|
573
|
/**
|
574
|
* Updates all authorship fields if the an authorship field is empty this method attempts to infer the
|
575
|
* authors from the related nomenclatural reference or taxon name.
|
576
|
* <p>
|
577
|
* Finally the {@link #updateFieldVisibility()} is invoked.
|
578
|
*
|
579
|
* @param taxonName
|
580
|
*/
|
581
|
@Override
|
582
|
public void updateAuthorshipFields() {
|
583
|
|
584
|
TaxonNameDTO taxonName = getBean();
|
585
|
|
586
|
// ------------- CombinationAuthors
|
587
|
isInferredCombinationAuthorship = updateAuthorshipFieldData(
|
588
|
taxonName.getCombinationAuthorship(),
|
589
|
inferCombinationAuthors(),
|
590
|
combinationAuthorshipField,
|
591
|
nomReferenceCombobox.getSelect(),
|
592
|
isInferredCombinationAuthorship);
|
593
|
|
594
|
|
595
|
// ------------- Basionym and ExBasionymAuthors
|
596
|
if(BooleanUtils.isTrue(basionymToggle.getValue())){
|
597
|
|
598
|
isInferredBasionymAuthorship = updateAuthorshipFieldData(
|
599
|
taxonName.getBasionymAuthorship(),
|
600
|
inferBasiomynAuthors(),
|
601
|
basionymAuthorshipField,
|
602
|
basionymsComboboxSelect,
|
603
|
isInferredBasionymAuthorship
|
604
|
);
|
605
|
|
606
|
isInferredExBasionymAuthorship = updateAuthorshipFieldData(
|
607
|
taxonName.getExBasionymAuthorship(),
|
608
|
inferExBasiomynAuthors(),
|
609
|
exBasionymAuthorshipField,
|
610
|
basionymsComboboxSelect,
|
611
|
isInferredExBasionymAuthorship
|
612
|
);
|
613
|
|
614
|
}
|
615
|
|
616
|
// ------------- Validation and ExCombinationAuthors
|
617
|
isInferredExCombinationAuthorship = updateAuthorshipFieldData(
|
618
|
taxonName.getExCombinationAuthorship(),
|
619
|
inferExCombinationAuthors(),
|
620
|
exCombinationAuthorshipField,
|
621
|
validationField.getValidatedNameComboBox(),
|
622
|
isInferredExCombinationAuthorship
|
623
|
);
|
624
|
|
625
|
updateFieldVisibility();
|
626
|
|
627
|
}
|
628
|
|
629
|
// /**
|
630
|
// *
|
631
|
// */
|
632
|
// protected void updateAuthorshipFieldsVisibility() {
|
633
|
// combinationAuthorshipField.setVisible(!isInferredCombinationAuthorship);
|
634
|
// if(BooleanUtils.isTrue(basionymToggle.getValue())){
|
635
|
// basionymAuthorshipField.setVisible(!isInferredBasionymAuthorship);
|
636
|
// exBasionymAuthorshipField.setVisible(!isInferredExBasionymAuthorship);
|
637
|
// }
|
638
|
// }
|
639
|
|
640
|
/**
|
641
|
*
|
642
|
* @param authorship
|
643
|
* the value of the taxonName authorship field
|
644
|
* @param inferredAuthors
|
645
|
* the value inferred from other fields which may be set as authorship to the taxon name
|
646
|
* @param authorshipField
|
647
|
* the ui element to edit the taxonName authorship field
|
648
|
* @param updateTriggerField
|
649
|
* @param lastInferredAuthorshipState
|
650
|
* @return
|
651
|
*/
|
652
|
protected Boolean updateAuthorshipFieldData(TeamOrPersonBase<?> authorship, TeamOrPersonBase inferredAuthors,
|
653
|
TeamOrPersonField authorshipField, AbstractField updateTriggerField,
|
654
|
Boolean lastInferredAuthorshipState) {
|
655
|
|
656
|
if(authorship == null){
|
657
|
authorshipField.setValue(inferredAuthors);
|
658
|
lastInferredAuthorshipState = true;
|
659
|
} else {
|
660
|
boolean authorshipMatch = authorship == inferredAuthors;
|
661
|
if(lastInferredAuthorshipState == null){
|
662
|
// initialization of authorshipState, this comes only into account when the editor is just being initialized
|
663
|
lastInferredAuthorshipState = authorshipMatch;
|
664
|
}
|
665
|
if(!authorshipMatch && lastInferredAuthorshipState){
|
666
|
// update the combinationAuthorshipField to follow changes of the nomenclatural reference in case it was autofilled before
|
667
|
authorshipField.setValue(inferredAuthors);
|
668
|
lastInferredAuthorshipState = true;
|
669
|
}
|
670
|
}
|
671
|
|
672
|
if(updateTriggerField != null){
|
673
|
// IMPORTANT!
|
674
|
// this ChangeListener must be added at this very late point in the editor lifecycle so that it is called after
|
675
|
// the ToOneRelatedEntityReloader which may have been added to the updateTriggerField in the presenters handleViewEntered() method.
|
676
|
// Otherwise we risk multiple representation problems in the hibernate session
|
677
|
if(!authorshipUpdateListeners.containsKey(updateTriggerField)){
|
678
|
ValueChangeListener listener = e -> {
|
679
|
logger.debug(" value changed #2");
|
680
|
updateAuthorshipFields();
|
681
|
};
|
682
|
updateTriggerField.addValueChangeListener(listener);
|
683
|
authorshipUpdateListeners.put(updateTriggerField, listener);
|
684
|
}
|
685
|
}
|
686
|
|
687
|
return lastInferredAuthorshipState;
|
688
|
}
|
689
|
|
690
|
/**
|
691
|
* @param rank
|
692
|
* @return
|
693
|
*/
|
694
|
private void updateFieldVisibility() {
|
695
|
|
696
|
// TODO use getField() instead and remove field references
|
697
|
Rank rank = (Rank) rankSelect.getValue();
|
698
|
|
699
|
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
|
700
|
Boolean withBasionymSection = BooleanUtils.isTrue(basionymToggle.getValue());
|
701
|
Boolean withValidationSection = isSpeciesOrBelow && BooleanUtils.isTrue(validationToggle.getValue());
|
702
|
|
703
|
if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){
|
704
|
if(isSpeciesOrBelow) {
|
705
|
if(TextField.class.isAssignableFrom(genusOrUninomialField.getClass())){
|
706
|
genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, new LazyComboBox<String>(String.class), 0, genusOrUninomialRow, 1, genusOrUninomialRow);
|
707
|
}
|
708
|
} else {
|
709
|
if(LazyComboBox.class.isAssignableFrom(genusOrUninomialField.getClass())) {
|
710
|
genusOrUninomialField = replaceComponent("genusOrUninomial", genusOrUninomialField, new TextFieldNFix(), 0, genusOrUninomialRow, 1, genusOrUninomialRow);
|
711
|
}
|
712
|
}
|
713
|
}
|
714
|
|
715
|
if(isModeEnabled(TaxonNamePopupEditorMode.VALIDATE_AGAINST_HIGHER_NAME_PART)){
|
716
|
if(rank.isInfraSpecific()) {
|
717
|
if(TextField.class.isAssignableFrom(specificEpithetField.getClass())) {
|
718
|
specificEpithetField = replaceComponent("specificEpithet", specificEpithetField, new LazyComboBox<String>(String.class), 0, specificEpithetFieldRow, 1, specificEpithetFieldRow);
|
719
|
}
|
720
|
} else {
|
721
|
if(LazyComboBox.class.isAssignableFrom(specificEpithetField.getClass())) {
|
722
|
specificEpithetField = replaceComponent("specificEpithet", specificEpithetField, new TextFieldNFix(), 0, specificEpithetFieldRow, 1, specificEpithetFieldRow);
|
723
|
}
|
724
|
}
|
725
|
}
|
726
|
|
727
|
specificEpithetField.setVisible(isSpeciesOrBelow);
|
728
|
infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
|
729
|
infraGenericEpithetField.setVisible(rank.isInfraGeneric());
|
730
|
|
731
|
basionymsComboboxSelect.setVisible(withBasionymSection);
|
732
|
|
733
|
combinationAuthorshipField.setVisible(isInferredCombinationAuthorship != null && !isInferredCombinationAuthorship);
|
734
|
basionymAuthorshipField.setVisible(withBasionymSection && isInferredBasionymAuthorship != null && !isInferredBasionymAuthorship);
|
735
|
exBasionymAuthorshipField.setVisible(withBasionymSection && isInferredExBasionymAuthorship != null && !isInferredExBasionymAuthorship);
|
736
|
|
737
|
validationField.setVisible(withValidationSection);
|
738
|
exCombinationAuthorshipField.setVisible(withValidationSection && isInferredExCombinationAuthorship != null && !isInferredExCombinationAuthorship);
|
739
|
|
740
|
|
741
|
// if(taxonName != null){
|
742
|
// if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
|
743
|
// }
|
744
|
// }
|
745
|
|
746
|
infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
|
747
|
specificEpithetField.setVisible(isSpeciesOrBelow);
|
748
|
infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
|
749
|
genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
|
750
|
}
|
751
|
|
752
|
|
753
|
@Override
|
754
|
public void cancel() {
|
755
|
authorshipUpdateListeners.keySet().forEach(field -> field.removeValueChangeListener(authorshipUpdateListeners.get(field)));
|
756
|
rankSelect.removeValueChangeListener(updateFieldVisibilityListener);
|
757
|
super.cancel();
|
758
|
}
|
759
|
|
760
|
/**
|
761
|
* {@inheritDoc}
|
762
|
*/
|
763
|
@Override
|
764
|
public boolean allowAnonymousAccess() {
|
765
|
return false;
|
766
|
}
|
767
|
|
768
|
/**
|
769
|
* {@inheritDoc}
|
770
|
*/
|
771
|
@Override
|
772
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
773
|
return null;
|
774
|
}
|
775
|
|
776
|
/**
|
777
|
* {@inheritDoc}
|
778
|
*/
|
779
|
@Override
|
780
|
public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
|
781
|
return nomReferenceCombobox;
|
782
|
}
|
783
|
|
784
|
/**
|
785
|
* {@inheritDoc}
|
786
|
*/
|
787
|
@Override
|
788
|
public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymComboboxSelect() {
|
789
|
return basionymsComboboxSelect;
|
790
|
}
|
791
|
|
792
|
/**
|
793
|
* {@inheritDoc}
|
794
|
*/
|
795
|
@Override
|
796
|
public ToManyRelatedEntitiesComboboxSelect<TaxonName> getReplacedSynonymsComboboxSelect() {
|
797
|
return replacedSynonymsComboboxSelect;
|
798
|
}
|
799
|
|
800
|
/**
|
801
|
* {@inheritDoc}
|
802
|
*/
|
803
|
@Override
|
804
|
public ListSelect getRankSelect() {
|
805
|
return rankSelect;
|
806
|
}
|
807
|
|
808
|
/**
|
809
|
* {@inheritDoc}
|
810
|
*/
|
811
|
@Override
|
812
|
public AbstractField<String> getGenusOrUninomialField(){
|
813
|
return genusOrUninomialField;
|
814
|
}
|
815
|
|
816
|
/**
|
817
|
* @return the exBasionymAuthorshipField
|
818
|
*/
|
819
|
@Override
|
820
|
public TeamOrPersonField getExBasionymAuthorshipField() {
|
821
|
return exBasionymAuthorshipField;
|
822
|
}
|
823
|
|
824
|
/**
|
825
|
* @return the basionymAuthorshipField
|
826
|
*/
|
827
|
@Override
|
828
|
public TeamOrPersonField getBasionymAuthorshipField() {
|
829
|
return basionymAuthorshipField;
|
830
|
}
|
831
|
|
832
|
/**
|
833
|
* @return the combinationAuthorshipField
|
834
|
*/
|
835
|
@Override
|
836
|
public TeamOrPersonField getCombinationAuthorshipField() {
|
837
|
return combinationAuthorshipField;
|
838
|
}
|
839
|
|
840
|
/**
|
841
|
* @return the exCombinationAuthorshipField
|
842
|
*/
|
843
|
@Override
|
844
|
public TeamOrPersonField getExCombinationAuthorshipField() {
|
845
|
return exCombinationAuthorshipField;
|
846
|
}
|
847
|
|
848
|
@Override
|
849
|
public NameRelationField getValidationField(){
|
850
|
return validationField;
|
851
|
}
|
852
|
|
853
|
@Override
|
854
|
public void enableMode(TaxonNamePopupEditorMode mode){
|
855
|
modesActive.add(mode);
|
856
|
}
|
857
|
|
858
|
@Override
|
859
|
public boolean isModeEnabled(TaxonNamePopupEditorMode mode){
|
860
|
return modesActive.contains(mode);
|
861
|
}
|
862
|
|
863
|
@Override
|
864
|
public void disableMode(TaxonNamePopupEditorMode mode){
|
865
|
modesActive.remove(mode);
|
866
|
}
|
867
|
|
868
|
@Override
|
869
|
public EnumSet<TaxonNamePopupEditorMode> getModesActive(){
|
870
|
return modesActive;
|
871
|
}
|
872
|
|
873
|
@Override
|
874
|
public CheckBox getBasionymToggle() {
|
875
|
return basionymToggle;
|
876
|
}
|
877
|
|
878
|
@Override
|
879
|
public FilterableAnnotationsField getAnnotationsField() {
|
880
|
return annotationsListField;
|
881
|
}
|
882
|
|
883
|
/**
|
884
|
* {@inheritDoc}
|
885
|
*/
|
886
|
@Override
|
887
|
public void setReadOnly(boolean readOnly) {
|
888
|
boolean basionymToggleReadonly = basionymToggle.isReadOnly();
|
889
|
boolean validationToggleReadonly = validationToggle.isReadOnly();
|
890
|
super.setReadOnly(readOnly);
|
891
|
combinationAuthorshipField.setEditorReadOnly(readOnly);
|
892
|
exCombinationAuthorshipField.setEditorReadOnly(readOnly);
|
893
|
basionymAuthorshipField.setEditorReadOnly(readOnly);
|
894
|
exBasionymAuthorshipField.setEditorReadOnly(readOnly);
|
895
|
// preserve old readonly states if they were true
|
896
|
if(basionymToggleReadonly){
|
897
|
basionymToggle.setReadOnly(true);
|
898
|
}
|
899
|
if(validationToggleReadonly){
|
900
|
validationToggle.setReadOnly(true);
|
901
|
}
|
902
|
}
|
903
|
|
904
|
|
905
|
|
906
|
/**
|
907
|
* @return the infraGenericEpithetField
|
908
|
*/
|
909
|
@Override
|
910
|
public AbstractField<String> getInfraGenericEpithetField() {
|
911
|
return infraGenericEpithetField;
|
912
|
}
|
913
|
|
914
|
/**
|
915
|
* @return the specificEpithetField
|
916
|
*/
|
917
|
@Override
|
918
|
public AbstractField<String> getSpecificEpithetField() {
|
919
|
return specificEpithetField;
|
920
|
}
|
921
|
|
922
|
/**
|
923
|
* @return the infraSpecificEpithetField
|
924
|
*/
|
925
|
@Override
|
926
|
public AbstractField<String> getInfraSpecificEpithetField() {
|
927
|
return infraSpecificEpithetField;
|
928
|
}
|
929
|
|
930
|
|
931
|
}
|