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