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
|
|
17
|
import org.apache.commons.lang3.BooleanUtils;
|
18
|
import org.apache.log4j.Level;
|
19
|
import org.springframework.context.annotation.Scope;
|
20
|
import org.springframework.security.core.GrantedAuthority;
|
21
|
|
22
|
import com.vaadin.data.Property;
|
23
|
import com.vaadin.data.Property.ValueChangeListener;
|
24
|
import com.vaadin.shared.ui.label.ContentMode;
|
25
|
import com.vaadin.spring.annotation.SpringComponent;
|
26
|
import com.vaadin.ui.AbstractField;
|
27
|
import com.vaadin.ui.Alignment;
|
28
|
import com.vaadin.ui.CheckBox;
|
29
|
import com.vaadin.ui.GridLayout;
|
30
|
import com.vaadin.ui.Label;
|
31
|
import com.vaadin.ui.ListSelect;
|
32
|
import com.vaadin.ui.TextField;
|
33
|
|
34
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
35
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
36
|
import eu.etaxonomy.cdm.model.name.Rank;
|
37
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
38
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
39
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
40
|
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
|
41
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
42
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
43
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
44
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
45
|
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
|
46
|
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
|
47
|
import eu.etaxonomy.vaadin.component.SwitchableTextField;
|
48
|
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
|
49
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
50
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
51
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
|
52
|
import eu.etaxonomy.vaadin.permission.EditPermissionTester;
|
53
|
|
54
|
/**
|
55
|
* @author a.kohlbecker
|
56
|
* @since May 22, 2017
|
57
|
*
|
58
|
*/
|
59
|
@SpringComponent
|
60
|
@Scope("prototype")
|
61
|
public class TaxonNamePopupEditor extends AbstractCdmPopupEditor<TaxonName, TaxonNameEditorPresenter> implements TaxonNamePopupEditorView, AccessRestrictedView {
|
62
|
|
63
|
private static final long serialVersionUID = -7037436241474466359L;
|
64
|
|
65
|
private final static int GRID_COLS = 4;
|
66
|
|
67
|
private final static int GRID_ROWS = 13;
|
68
|
|
69
|
private static final boolean HAS_BASIONYM_DEFAULT = false;
|
70
|
|
71
|
private TextField genusOrUninomialField;
|
72
|
|
73
|
private TextField infraGenericEpithetField;
|
74
|
|
75
|
private TextField specificEpithetField;
|
76
|
|
77
|
private TextField infraSpecificEpithetField;
|
78
|
|
79
|
private SwitchableTextField fullTitleCacheFiled;
|
80
|
|
81
|
private SwitchableTextField protectedNameCacheField;
|
82
|
|
83
|
private ToOneRelatedEntityCombobox<Reference> nomReferenceCombobox;
|
84
|
|
85
|
private TextField nomenclaturalReferenceDetail;
|
86
|
|
87
|
private TeamOrPersonField exBasionymAuthorshipField;
|
88
|
|
89
|
private TeamOrPersonField basionymAuthorshipField;
|
90
|
|
91
|
private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymsComboboxSelect;
|
92
|
|
93
|
private CheckBox basionymToggle;
|
94
|
|
95
|
private CheckBox validationToggle;
|
96
|
|
97
|
private ListSelect rankSelect;
|
98
|
|
99
|
private TeamOrPersonField combinationAuthorshipField;
|
100
|
|
101
|
private TeamOrPersonField exCombinationAuthorshipField;
|
102
|
|
103
|
private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class);
|
104
|
|
105
|
private Boolean isInferredCombinationAuthorship = null;
|
106
|
|
107
|
private Boolean isInferredBasionymAuthorship = null;
|
108
|
|
109
|
private Boolean isInferredExBasionymAuthorship = null;
|
110
|
|
111
|
private Map<AbstractField, Property.ValueChangeListener> authorshipUpdateListeners = new HashMap<>();
|
112
|
|
113
|
/**
|
114
|
* @param layout
|
115
|
* @param dtoType
|
116
|
*/
|
117
|
public TaxonNamePopupEditor() {
|
118
|
super(new GridLayout(GRID_COLS, GRID_ROWS), TaxonName.class);
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* {@inheritDoc}
|
123
|
*/
|
124
|
@Override
|
125
|
public String getWindowCaption() {
|
126
|
return "Name editor";
|
127
|
}
|
128
|
|
129
|
|
130
|
|
131
|
/**
|
132
|
* {@inheritDoc}
|
133
|
*/
|
134
|
@Override
|
135
|
public int getWindowWidth() {
|
136
|
return 800;
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* {@inheritDoc}
|
141
|
*/
|
142
|
@Override
|
143
|
public void focusFirst() {
|
144
|
// titleField.focus();
|
145
|
|
146
|
}
|
147
|
|
148
|
/**
|
149
|
* {@inheritDoc}
|
150
|
*/
|
151
|
@Override
|
152
|
protected String getDefaultComponentStyles() {
|
153
|
return "tiny";
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* {@inheritDoc}
|
158
|
*/
|
159
|
@Override
|
160
|
protected void initContent() {
|
161
|
|
162
|
GridLayout grid = (GridLayout)getFieldLayout();
|
163
|
grid.setSizeFull();
|
164
|
grid.setHideEmptyRowsAndColumns(true);
|
165
|
grid.setSpacing(true);
|
166
|
grid.setColumnExpandRatio(0, 0.3f);
|
167
|
grid.setColumnExpandRatio(1, 0.3f);
|
168
|
grid.setColumnExpandRatio(2, 0.3f);
|
169
|
grid.setColumnExpandRatio(3, 0.0f);
|
170
|
|
171
|
/*
|
172
|
- nameType: preset, needs to be set in the presenter for new names
|
173
|
- appendedPhrase: -> TODO field
|
174
|
- nomenclaturalMicroReference: -> TODO field
|
175
|
- nomenclaturalReference -> field but disabled for REGISTRY
|
176
|
- rank -> SelectField which determines the visiblity of the other fields
|
177
|
|
178
|
- fullTitleCache + protectedFullTitleCache -> SwitchableTextField : ADVANCED_MODE
|
179
|
- nameCache + protectedNameCache -> SwitchableTextField : ADVANCED_MODE
|
180
|
|
181
|
- homotypicalGroup -> hidden
|
182
|
- typeDesignations -> hidden
|
183
|
- descriptions -> hidden
|
184
|
- taxonBases -> hidden
|
185
|
- registrations -> hidden
|
186
|
|
187
|
- relationsFromThisName-> TODO implement later
|
188
|
- relationsToThisName -> TODO implement later
|
189
|
|
190
|
- genusOrUninomial -> textField
|
191
|
- infraGenericEpithet -> textField
|
192
|
- specificEpithet -> textField
|
193
|
- infraSpecificEpithet -> textField
|
194
|
|
195
|
- authorshipCache + protectedAuthorshipCache -> SwitchableTextField : only ADVANCED_MODE and disabled for REGISTRY
|
196
|
- basionymAuthorship -> field but disabled for REGISTRY, basionym is set as nameRelationShip
|
197
|
- combinationAuthorship -> field but disabled for REGISTRY author team of the reference
|
198
|
- exCombinationAuthorship -> textField
|
199
|
- exBasionymAuthorship -> textField
|
200
|
|
201
|
- status -> TODO field
|
202
|
- monomHybrid -> TODO implement hybrids later
|
203
|
- binomHybrid -> TODO implement hybrids later
|
204
|
- trinomHybrid -> TODO implement hybrids later
|
205
|
|
206
|
- hybridParentRelations -> TODO implement hybrids later
|
207
|
- hybridChildRelations -> TODO implement hybrids later
|
208
|
- hybridFormula -> TODO implement hybrids later
|
209
|
|
210
|
** ViralName attributes **
|
211
|
- acronym
|
212
|
|
213
|
** BacterialName attributes **
|
214
|
- subGenusAuthorship
|
215
|
- nameApprobation
|
216
|
- breed
|
217
|
- publicationYear
|
218
|
- originalPublicationYear
|
219
|
- cultivarName
|
220
|
*/
|
221
|
|
222
|
int row = 0;
|
223
|
|
224
|
rankSelect = new ListSelect("Rank");
|
225
|
rankSelect.setNullSelectionAllowed(false);
|
226
|
rankSelect.setRows(1);
|
227
|
rankSelect.setWidth(100, Unit.PERCENTAGE);
|
228
|
rankSelect.addValueChangeListener(e -> updateFieldVisibility());
|
229
|
addField(rankSelect, "rank", 0, row, 1, row);
|
230
|
grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT);
|
231
|
|
232
|
basionymToggle = new CheckBox("With basionym");
|
233
|
basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
|
234
|
|
235
|
basionymToggle.setStyleName(getDefaultComponentStyles());
|
236
|
grid.addComponent(basionymToggle, 2, row, 3, row);
|
237
|
grid.setComponentAlignment(basionymToggle, Alignment.BOTTOM_LEFT);
|
238
|
|
239
|
row++;
|
240
|
validationToggle = new CheckBox("Validation");
|
241
|
validationToggle.addValueChangeListener(e -> {
|
242
|
boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
|
243
|
exCombinationAuthorshipField.setVisible(enable);
|
244
|
});
|
245
|
grid.addComponent(validationToggle, 2, row, 3, row);
|
246
|
grid.setComponentAlignment(validationToggle, Alignment.BOTTOM_LEFT);
|
247
|
|
248
|
row++;
|
249
|
// fullTitleCache
|
250
|
fullTitleCacheFiled = addSwitchableTextField("Full title cache", "fullTitleCache", "protectedFullTitleCache", 0, row, GRID_COLS-1, row);
|
251
|
fullTitleCacheFiled.setWidth(100, Unit.PERCENTAGE);
|
252
|
row++;
|
253
|
protectedNameCacheField = addSwitchableTextField("Name cache", "nameCache", "protectedNameCache", 0, row, GRID_COLS-1, row);
|
254
|
protectedNameCacheField.setWidth(100, Unit.PERCENTAGE);
|
255
|
row++;
|
256
|
genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
|
257
|
genusOrUninomialField.setWidth(200, Unit.PIXELS);
|
258
|
infraGenericEpithetField = addTextField("Infrageneric epithet", "infraGenericEpithet", 2, row, 3, row);
|
259
|
infraGenericEpithetField.setWidth(200, Unit.PIXELS);
|
260
|
row++;
|
261
|
specificEpithetField = addTextField("Specific epithet", "specificEpithet", 0, row, 1, row);
|
262
|
specificEpithetField.setWidth(200, Unit.PIXELS);
|
263
|
infraSpecificEpithetField = addTextField("Infraspecific epithet", "infraSpecificEpithet", 2, row, 3, row);
|
264
|
infraSpecificEpithetField.setWidth(200, Unit.PIXELS);
|
265
|
|
266
|
row++;
|
267
|
grid.addComponent(new Label("Hint: <i>Edit nomenclatural authors in the nomenclatural reference.</i>", ContentMode.HTML), 0, row, 3, row);
|
268
|
|
269
|
row++;
|
270
|
combinationAuthorshipField = new TeamOrPersonField("combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
271
|
combinationAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
272
|
addField(combinationAuthorshipField, "combinationAuthorship", 0, row, GRID_COLS-1, row);
|
273
|
|
274
|
row++;
|
275
|
nomReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("Nomenclatural reference", Reference.class);
|
276
|
nomReferenceCombobox.addClickListenerAddEntity(e -> getViewEventBus().publish(
|
277
|
this,
|
278
|
new ReferenceEditorAction(EditorActionType.ADD, null, nomReferenceCombobox, this)
|
279
|
));
|
280
|
nomReferenceCombobox.addClickListenerEditEntity(e -> {
|
281
|
if(nomReferenceCombobox.getValue() != null){
|
282
|
getViewEventBus().publish(this,
|
283
|
new ReferenceEditorAction(
|
284
|
EditorActionType.EDIT,
|
285
|
nomReferenceCombobox.getValue().getId(),
|
286
|
nomReferenceCombobox,
|
287
|
this)
|
288
|
);
|
289
|
}
|
290
|
});
|
291
|
logger.setLevel(Level.DEBUG);
|
292
|
nomReferenceCombobox.getSelect().addValueChangeListener(e -> logger.debug("nomReferenceCombobox value changed #1"));
|
293
|
// nomReferenceCombobox.setWidth(300, Unit.PIXELS);
|
294
|
nomReferenceCombobox.setWidth("100%");
|
295
|
addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 2, row);
|
296
|
nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
|
297
|
nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
|
298
|
|
299
|
row++;
|
300
|
exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
301
|
exCombinationAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
302
|
addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
|
303
|
|
304
|
// Basionym
|
305
|
row++;
|
306
|
basionymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
|
307
|
basionymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
|
308
|
addField(basionymsComboboxSelect, "basionyms", 0, row, 3, row);
|
309
|
basionymsComboboxSelect.setWidth(100, Unit.PERCENTAGE);
|
310
|
basionymsComboboxSelect.withEditButton(true);
|
311
|
basionymsComboboxSelect.setEditPermissionTester(new EditPermissionTester() {
|
312
|
|
313
|
@Override
|
314
|
public boolean userHasEditPermission(Object bean) {
|
315
|
return UserHelper.fromSession().userHasPermission((CdmBase)bean, CRUD.UPDATE, CRUD.DELETE);
|
316
|
}
|
317
|
});
|
318
|
basionymsComboboxSelect.setEditActionListener(e -> {
|
319
|
|
320
|
Object fieldValue = e.getSource().getValue();
|
321
|
Integer beanId = null;
|
322
|
if(fieldValue != null){
|
323
|
beanId = ((CdmBase)fieldValue).getId();
|
324
|
|
325
|
}
|
326
|
getViewEventBus().publish(this, new TaxonNameEditorAction(e.getAction(), beanId, e.getSource(), this));
|
327
|
});
|
328
|
grid.setComponentAlignment(basionymsComboboxSelect, Alignment.TOP_RIGHT);
|
329
|
row++;
|
330
|
basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
331
|
basionymAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
332
|
addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
|
333
|
row++;
|
334
|
exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
|
335
|
exBasionymAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
336
|
addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
|
337
|
|
338
|
|
339
|
|
340
|
setAdvancedModeEnabled(true);
|
341
|
registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
|
342
|
|
343
|
registerAdvancedModeComponents(combinationAuthorshipField);
|
344
|
registerAdvancedModeComponents(basionymAuthorshipField);
|
345
|
registerAdvancedModeComponents(exBasionymAuthorshipField);
|
346
|
|
347
|
registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
|
348
|
registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
|
349
|
registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
|
350
|
registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
|
351
|
|
352
|
setAdvancedMode(false);
|
353
|
|
354
|
}
|
355
|
|
356
|
protected TeamOrPersonBase inferBasiomynAuthors() {
|
357
|
List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
|
358
|
if(!basionyms.isEmpty()){
|
359
|
TaxonName basionym = basionyms.get(0);
|
360
|
if(basionym.getCombinationAuthorship() != null){
|
361
|
return basionym.getCombinationAuthorship();
|
362
|
} else if(basionym.getNomenclaturalReference() != null){
|
363
|
return basionym.getNomenclaturalReference().getAuthorship();
|
364
|
}
|
365
|
}
|
366
|
return null;
|
367
|
}
|
368
|
|
369
|
protected TeamOrPersonBase inferExBasiomynAuthors() {
|
370
|
List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
|
371
|
if(!basionyms.isEmpty()){
|
372
|
TaxonName basionym = basionyms.get(0);
|
373
|
return basionym.getExCombinationAuthorship();
|
374
|
}
|
375
|
return null;
|
376
|
}
|
377
|
|
378
|
protected TeamOrPersonBase inferCombinationAuthors() {
|
379
|
Reference nomRef = nomReferenceCombobox.getValue();
|
380
|
if(nomRef != null) {
|
381
|
return nomRef.getAuthorship();
|
382
|
}
|
383
|
return null;
|
384
|
}
|
385
|
|
386
|
@Override
|
387
|
protected void afterItemDataSourceSet() {
|
388
|
TaxonName taxonName = getBean();
|
389
|
boolean showBasionymSection = taxonName.getBasionyms().size() > 0
|
390
|
|| taxonName.getBasionymAuthorship() != null
|
391
|
|| taxonName.getExBasionymAuthorship() != null;
|
392
|
basionymToggle.setValue(showBasionymSection);
|
393
|
basionymToggle.setReadOnly(showBasionymSection);
|
394
|
basionymToggle.addValueChangeListener(e -> {
|
395
|
updateAuthorshipFields();
|
396
|
updateFieldVisibility();
|
397
|
});
|
398
|
|
399
|
boolean showExAuthors = taxonName.getExCombinationAuthorship() != null;
|
400
|
validationToggle.setValue(showExAuthors);
|
401
|
validationToggle.setReadOnly(showExAuthors);
|
402
|
exCombinationAuthorshipField.setVisible(showExAuthors);
|
403
|
|
404
|
if(isModeEnabled(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
|
405
|
updateAuthorshipFields();
|
406
|
}
|
407
|
if(isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY) && getBean().getNomenclaturalReference() != null) {
|
408
|
nomReferenceCombobox.setCaption("Selection limited to nomenclatural reference and sections");
|
409
|
}
|
410
|
if(isModeEnabled(TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE)) {
|
411
|
if(combinationAuthorshipField.getValue() == null){
|
412
|
nomReferenceCombobox.setRequired(true);
|
413
|
} else {
|
414
|
combinationAuthorshipField.addValueChangeListener(e -> {
|
415
|
if(e.getProperty().getValue() == null){
|
416
|
nomReferenceCombobox.setRequired(true);
|
417
|
}
|
418
|
});
|
419
|
}
|
420
|
}
|
421
|
|
422
|
}
|
423
|
|
424
|
/**
|
425
|
* @param taxonName
|
426
|
*/
|
427
|
@Override
|
428
|
public void updateAuthorshipFields() {
|
429
|
|
430
|
TaxonName taxonName = getBean();
|
431
|
|
432
|
// ------------- CombinationAuthors
|
433
|
isInferredCombinationAuthorship = updateAuthorshipFieldData(
|
434
|
taxonName.getCombinationAuthorship(),
|
435
|
inferCombinationAuthors(),
|
436
|
combinationAuthorshipField,
|
437
|
nomReferenceCombobox.getSelect(),
|
438
|
isInferredCombinationAuthorship);
|
439
|
|
440
|
|
441
|
// ------------- Basionym and ExBasionymAuthors
|
442
|
if(BooleanUtils.isTrue(basionymToggle.getValue())){
|
443
|
|
444
|
isInferredBasionymAuthorship = updateAuthorshipFieldData(
|
445
|
taxonName.getBasionymAuthorship(),
|
446
|
inferBasiomynAuthors(),
|
447
|
basionymAuthorshipField,
|
448
|
basionymsComboboxSelect,
|
449
|
isInferredBasionymAuthorship
|
450
|
);
|
451
|
|
452
|
isInferredExBasionymAuthorship = updateAuthorshipFieldData(
|
453
|
taxonName.getExBasionymAuthorship(),
|
454
|
inferExBasiomynAuthors(),
|
455
|
exBasionymAuthorshipField,
|
456
|
basionymsComboboxSelect,
|
457
|
isInferredExBasionymAuthorship
|
458
|
);
|
459
|
|
460
|
}
|
461
|
|
462
|
updateFieldVisibility();
|
463
|
|
464
|
}
|
465
|
|
466
|
// /**
|
467
|
// *
|
468
|
// */
|
469
|
// protected void updateAuthorshipFieldsVisibility() {
|
470
|
// combinationAuthorshipField.setVisible(!isInferredCombinationAuthorship);
|
471
|
// if(BooleanUtils.isTrue(basionymToggle.getValue())){
|
472
|
// basionymAuthorshipField.setVisible(!isInferredBasionymAuthorship);
|
473
|
// exBasionymAuthorshipField.setVisible(!isInferredExBasionymAuthorship);
|
474
|
// }
|
475
|
// }
|
476
|
|
477
|
/**
|
478
|
*
|
479
|
* @param authorship
|
480
|
* the value of the taxonName authorship field
|
481
|
* @param inferredAuthors
|
482
|
* the value inferred from other fields which may be set as authorship to the taxon name
|
483
|
* @param authorshipField
|
484
|
* the ui element to edit the taxonName authorship field
|
485
|
* @param updateTriggerField
|
486
|
* @param lastInferredAuthorshipState
|
487
|
* @return
|
488
|
*/
|
489
|
protected Boolean updateAuthorshipFieldData(TeamOrPersonBase<?> authorship, TeamOrPersonBase inferredAuthors,
|
490
|
TeamOrPersonField authorshipField, AbstractField updateTriggerField,
|
491
|
Boolean lastInferredAuthorshipState) {
|
492
|
|
493
|
if(authorship == null){
|
494
|
authorshipField.setValue(inferredAuthors);
|
495
|
lastInferredAuthorshipState = true;
|
496
|
} else {
|
497
|
boolean authorshipMatch = authorship == inferredAuthors;
|
498
|
if(lastInferredAuthorshipState == null){
|
499
|
// initialization of authorshipState, this comes only into account when the editor is just being initialized
|
500
|
lastInferredAuthorshipState = authorshipMatch;
|
501
|
}
|
502
|
if(!authorshipMatch && lastInferredAuthorshipState){
|
503
|
// update the combinationAuthorshipField to follow changes of the nomenclatural reference in case it was autofilled before
|
504
|
authorshipField.setValue(inferredAuthors);
|
505
|
lastInferredAuthorshipState = true;
|
506
|
}
|
507
|
}
|
508
|
|
509
|
if(updateTriggerField != null){
|
510
|
// IMPORTANT!
|
511
|
// this ChangeListener must be added at this very late point in the editor lifecycle so that it is called after
|
512
|
// the ToOneRelatedEntityReloader which may have been added to the updateTriggerField in the presenters handleViewEntered() method.
|
513
|
// Otherwise we risk multiple representation problems in the hibernate session
|
514
|
if(!authorshipUpdateListeners.containsKey(updateTriggerField)){
|
515
|
ValueChangeListener listener = e -> {
|
516
|
logger.debug(" value changed #2");
|
517
|
updateAuthorshipFields();
|
518
|
};
|
519
|
updateTriggerField.addValueChangeListener(listener);
|
520
|
authorshipUpdateListeners.put(updateTriggerField, listener);
|
521
|
}
|
522
|
}
|
523
|
|
524
|
return lastInferredAuthorshipState;
|
525
|
}
|
526
|
|
527
|
/**
|
528
|
* @param rank
|
529
|
* @return
|
530
|
*/
|
531
|
private void updateFieldVisibility() {
|
532
|
|
533
|
// TODO use getField() instead and remove field references
|
534
|
|
535
|
TaxonName taxonName = getBean();
|
536
|
Rank rank = taxonName.getRank();
|
537
|
|
538
|
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
|
539
|
Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue());
|
540
|
Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue());
|
541
|
|
542
|
basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
|
543
|
exBasionymAuthorshipField.setVisible(withBasionym);
|
544
|
basionymsComboboxSelect.setVisible(withBasionym);
|
545
|
|
546
|
combinationAuthorshipField.setVisible(isInferredCombinationAuthorship != null && !isInferredCombinationAuthorship);
|
547
|
if(BooleanUtils.isTrue(basionymToggle.getValue())){
|
548
|
basionymAuthorshipField.setVisible(isInferredBasionymAuthorship != null && !isInferredBasionymAuthorship);
|
549
|
exBasionymAuthorshipField.setVisible(isInferredExBasionymAuthorship != null && !isInferredExBasionymAuthorship);
|
550
|
}
|
551
|
|
552
|
// if(taxonName != null){
|
553
|
// if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
|
554
|
// }
|
555
|
// }
|
556
|
|
557
|
infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
|
558
|
specificEpithetField.setVisible(isSpeciesOrBelow);
|
559
|
infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
|
560
|
genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
|
561
|
exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
|
562
|
}
|
563
|
|
564
|
@Override
|
565
|
public void cancel() {
|
566
|
authorshipUpdateListeners.keySet().forEach(field -> field.removeValueChangeListener(authorshipUpdateListeners.get(field)));
|
567
|
super.cancel();
|
568
|
}
|
569
|
|
570
|
/**
|
571
|
* {@inheritDoc}
|
572
|
*/
|
573
|
@Override
|
574
|
public boolean allowAnonymousAccess() {
|
575
|
return false;
|
576
|
}
|
577
|
|
578
|
/**
|
579
|
* {@inheritDoc}
|
580
|
*/
|
581
|
@Override
|
582
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
583
|
return null;
|
584
|
}
|
585
|
|
586
|
/**
|
587
|
* {@inheritDoc}
|
588
|
*/
|
589
|
@Override
|
590
|
public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
|
591
|
return nomReferenceCombobox;
|
592
|
}
|
593
|
|
594
|
/**
|
595
|
* {@inheritDoc}
|
596
|
*/
|
597
|
@Override
|
598
|
public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymComboboxSelect() {
|
599
|
return basionymsComboboxSelect;
|
600
|
}
|
601
|
|
602
|
/**
|
603
|
* {@inheritDoc}
|
604
|
*/
|
605
|
@Override
|
606
|
public ListSelect getRankSelect() {
|
607
|
return rankSelect;
|
608
|
}
|
609
|
|
610
|
/**
|
611
|
* @return the exBasionymAuthorshipField
|
612
|
*/
|
613
|
@Override
|
614
|
public TeamOrPersonField getExBasionymAuthorshipField() {
|
615
|
return exBasionymAuthorshipField;
|
616
|
}
|
617
|
|
618
|
/**
|
619
|
* @return the basionymAuthorshipField
|
620
|
*/
|
621
|
@Override
|
622
|
public TeamOrPersonField getBasionymAuthorshipField() {
|
623
|
return basionymAuthorshipField;
|
624
|
}
|
625
|
|
626
|
/**
|
627
|
* @return the combinationAuthorshipField
|
628
|
*/
|
629
|
@Override
|
630
|
public TeamOrPersonField getCombinationAuthorshipField() {
|
631
|
return combinationAuthorshipField;
|
632
|
}
|
633
|
|
634
|
/**
|
635
|
* @return the exCombinationAuthorshipField
|
636
|
*/
|
637
|
@Override
|
638
|
public TeamOrPersonField getExCombinationAuthorshipField() {
|
639
|
return exCombinationAuthorshipField;
|
640
|
}
|
641
|
|
642
|
@Override
|
643
|
public void enableMode(TaxonNamePopupEditorMode mode){
|
644
|
modesActive.add(mode);
|
645
|
}
|
646
|
|
647
|
@Override
|
648
|
public boolean isModeEnabled(TaxonNamePopupEditorMode mode){
|
649
|
return modesActive.contains(mode);
|
650
|
}
|
651
|
|
652
|
@Override
|
653
|
public void disableMode(TaxonNamePopupEditorMode mode){
|
654
|
modesActive.remove(mode);
|
655
|
}
|
656
|
|
657
|
@Override
|
658
|
public EnumSet<TaxonNamePopupEditorMode> getModesActive(){
|
659
|
return modesActive;
|
660
|
}
|
661
|
|
662
|
@Override
|
663
|
public CheckBox getBasionymToggle() {
|
664
|
return basionymToggle;
|
665
|
}
|
666
|
|
667
|
/**
|
668
|
* {@inheritDoc}
|
669
|
*/
|
670
|
@Override
|
671
|
public void setReadOnly(boolean readOnly) {
|
672
|
boolean basionymToggleReadonly = basionymToggle.isReadOnly();
|
673
|
boolean validationToggleReadonly = validationToggle.isReadOnly();
|
674
|
super.setReadOnly(readOnly);
|
675
|
// preserve old readonly states if they were true
|
676
|
if(basionymToggleReadonly){
|
677
|
basionymToggle.setReadOnly(true);
|
678
|
}
|
679
|
if(validationToggleReadonly){
|
680
|
validationToggle.setReadOnly(true);
|
681
|
}
|
682
|
}
|
683
|
|
684
|
|
685
|
|
686
|
|
687
|
}
|