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
|
|
14
|
import org.springframework.security.core.GrantedAuthority;
|
15
|
|
16
|
import com.vaadin.shared.ui.label.ContentMode;
|
17
|
import com.vaadin.ui.Alignment;
|
18
|
import com.vaadin.ui.CheckBox;
|
19
|
import com.vaadin.ui.GridLayout;
|
20
|
import com.vaadin.ui.Label;
|
21
|
import com.vaadin.ui.ListSelect;
|
22
|
import com.vaadin.ui.TextField;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
29
|
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
|
30
|
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
|
31
|
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
|
32
|
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
|
33
|
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
|
34
|
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
|
35
|
import eu.etaxonomy.vaadin.component.SwitchableTextField;
|
36
|
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
|
37
|
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
|
38
|
import eu.etaxonomy.vaadin.event.EditorActionType;
|
39
|
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
|
40
|
import eu.etaxonomy.vaadin.permission.EditPermissionTester;
|
41
|
|
42
|
/**
|
43
|
* @author a.kohlbecker
|
44
|
* @since May 22, 2017
|
45
|
*
|
46
|
*/
|
47
|
public class TaxonNamePopupEditor extends AbstractCdmPopupEditor<TaxonName, TaxonNameEditorPresenter> implements TaxonNamePopupEditorView, AccessRestrictedView {
|
48
|
|
49
|
private static final long serialVersionUID = -7037436241474466359L;
|
50
|
|
51
|
private final static int GRID_COLS = 4;
|
52
|
|
53
|
private final static int GRID_ROWS = 13;
|
54
|
|
55
|
private static final boolean HAS_BASIONYM_DEFAULT = false;
|
56
|
|
57
|
private TextField genusOrUninomialField;
|
58
|
|
59
|
private TextField infraGenericEpithetField;
|
60
|
|
61
|
private TextField specificEpithetField;
|
62
|
|
63
|
private TextField infraSpecificEpithetField;
|
64
|
|
65
|
private SwitchableTextField fullTitleCacheFiled;
|
66
|
|
67
|
private SwitchableTextField protectedNameCacheField;
|
68
|
|
69
|
private ToOneRelatedEntityCombobox<Reference> nomReferenceCombobox;
|
70
|
|
71
|
private TextField nomenclaturalReferenceDetail;
|
72
|
|
73
|
private TeamOrPersonField exBasionymAuthorshipField;
|
74
|
|
75
|
private TeamOrPersonField basionymAuthorshipField;
|
76
|
|
77
|
private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymsComboboxSelect;
|
78
|
|
79
|
private CheckBox basionymToggle;
|
80
|
|
81
|
private CheckBox validationToggle;
|
82
|
|
83
|
private ListSelect rankSelect;
|
84
|
|
85
|
private TeamOrPersonField combinationAuthorshipField;
|
86
|
|
87
|
private TeamOrPersonField exCombinationAuthorshipField;
|
88
|
|
89
|
private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class);
|
90
|
|
91
|
/**
|
92
|
* @param layout
|
93
|
* @param dtoType
|
94
|
*/
|
95
|
public TaxonNamePopupEditor() {
|
96
|
super(new GridLayout(GRID_COLS, GRID_ROWS), TaxonName.class);
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* {@inheritDoc}
|
101
|
*/
|
102
|
@Override
|
103
|
public String getWindowCaption() {
|
104
|
return "Name editor";
|
105
|
}
|
106
|
|
107
|
|
108
|
|
109
|
/**
|
110
|
* {@inheritDoc}
|
111
|
*/
|
112
|
@Override
|
113
|
public int getWindowPixelWidth() {
|
114
|
return 700;
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* {@inheritDoc}
|
119
|
*/
|
120
|
@Override
|
121
|
public void focusFirst() {
|
122
|
// titleField.focus();
|
123
|
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* {@inheritDoc}
|
128
|
*/
|
129
|
@Override
|
130
|
protected String getDefaultComponentStyles() {
|
131
|
return "tiny";
|
132
|
}
|
133
|
|
134
|
/**
|
135
|
* {@inheritDoc}
|
136
|
*/
|
137
|
@Override
|
138
|
protected void initContent() {
|
139
|
|
140
|
GridLayout grid = (GridLayout)getFieldLayout();
|
141
|
grid.setSizeFull();
|
142
|
grid.setSpacing(true);
|
143
|
grid.setColumnExpandRatio(0, 0.3f);
|
144
|
grid.setColumnExpandRatio(1, 0.3f);
|
145
|
grid.setColumnExpandRatio(2, 0.3f);
|
146
|
grid.setColumnExpandRatio(3, 0.0f);
|
147
|
|
148
|
/*
|
149
|
- nameType: preset, needs to be set in the presenter for new names
|
150
|
- appendedPhrase: -> TODO field
|
151
|
- nomenclaturalMicroReference: -> TODO field
|
152
|
- nomenclaturalReference -> field but disabled for REGISTRY
|
153
|
- rank -> SelectField which determines the visiblity of the other fields
|
154
|
|
155
|
- fullTitleCache + protectedFullTitleCache -> SwitchableTextField : ADVANCED_MODE
|
156
|
- nameCache + protectedNameCache -> SwitchableTextField : ADVANCED_MODE
|
157
|
|
158
|
- homotypicalGroup -> hidden
|
159
|
- typeDesignations -> hidden
|
160
|
- descriptions -> hidden
|
161
|
- taxonBases -> hidden
|
162
|
- registrations -> hidden
|
163
|
|
164
|
- relationsFromThisName-> TODO implement later
|
165
|
- relationsToThisName -> TODO implement later
|
166
|
|
167
|
- genusOrUninomial -> textField
|
168
|
- infraGenericEpithet -> textField
|
169
|
- specificEpithet -> textField
|
170
|
- infraSpecificEpithet -> textField
|
171
|
|
172
|
- authorshipCache + protectedAuthorshipCache -> SwitchableTextField : only ADVANCED_MODE and disabled for REGISTRY
|
173
|
- basionymAuthorship -> field but disabled for REGISTRY, basionym is set as nameRelationShip
|
174
|
- combinationAuthorship -> field but disabled for REGISTRY author team of the reference
|
175
|
- exCombinationAuthorship -> textField
|
176
|
- exBasionymAuthorship -> textField
|
177
|
|
178
|
- status -> TODO field
|
179
|
- monomHybrid -> TODO implement hybrids later
|
180
|
- binomHybrid -> TODO implement hybrids later
|
181
|
- trinomHybrid -> TODO implement hybrids later
|
182
|
|
183
|
- hybridParentRelations -> TODO implement hybrids later
|
184
|
- hybridChildRelations -> TODO implement hybrids later
|
185
|
- hybridFormula -> TODO implement hybrids later
|
186
|
|
187
|
** ViralName attributes **
|
188
|
- acronym
|
189
|
|
190
|
** BacterialName attributes **
|
191
|
- subGenusAuthorship
|
192
|
- nameApprobation
|
193
|
- breed
|
194
|
- publicationYear
|
195
|
- originalPublicationYear
|
196
|
- cultivarName
|
197
|
*/
|
198
|
|
199
|
int row = 0;
|
200
|
|
201
|
rankSelect = new ListSelect("Rank");
|
202
|
rankSelect.setNullSelectionAllowed(false);
|
203
|
rankSelect.setRows(1);
|
204
|
rankSelect.setWidth(100, Unit.PERCENTAGE);
|
205
|
rankSelect.addValueChangeListener(e -> updateFieldVisibility((Rank)e.getProperty().getValue()));
|
206
|
addField(rankSelect, "rank", 0, row, 1, row);
|
207
|
grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT);
|
208
|
|
209
|
basionymToggle = new CheckBox("With basionym");
|
210
|
basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
|
211
|
basionymToggle.addValueChangeListener(e -> {
|
212
|
boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
|
213
|
enableBasionymFields(enable);
|
214
|
});
|
215
|
basionymToggle.setStyleName(getDefaultComponentStyles());
|
216
|
grid.addComponent(basionymToggle, 2, row, 3, row);
|
217
|
grid.setComponentAlignment(basionymToggle, Alignment.BOTTOM_LEFT);
|
218
|
|
219
|
row++;
|
220
|
validationToggle = new CheckBox("With validation");
|
221
|
validationToggle.addValueChangeListener(e -> {
|
222
|
boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
|
223
|
exCombinationAuthorshipField.setVisible(enable);
|
224
|
});
|
225
|
grid.addComponent(validationToggle, 2, row, 3, row);
|
226
|
grid.setComponentAlignment(validationToggle, Alignment.BOTTOM_LEFT);
|
227
|
|
228
|
row++;
|
229
|
// fullTitleCache
|
230
|
fullTitleCacheFiled = addSwitchableTextField("Full title cache", "fullTitleCache", "protectedFullTitleCache", 0, row, GRID_COLS-1, row);
|
231
|
fullTitleCacheFiled.setWidth(100, Unit.PERCENTAGE);
|
232
|
row++;
|
233
|
protectedNameCacheField = addSwitchableTextField("Name cache", "nameCache", "protectedNameCache", 0, row, GRID_COLS-1, row);
|
234
|
protectedNameCacheField.setWidth(100, Unit.PERCENTAGE);
|
235
|
row++;
|
236
|
genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
|
237
|
genusOrUninomialField.setWidth(200, Unit.PIXELS);
|
238
|
infraGenericEpithetField = addTextField("Infrageneric epithet", "infraGenericEpithet", 2, row, 3, row);
|
239
|
infraGenericEpithetField.setWidth(200, Unit.PIXELS);
|
240
|
row++;
|
241
|
specificEpithetField = addTextField("Specific epithet", "specificEpithet", 0, row, 1, row);
|
242
|
specificEpithetField.setWidth(200, Unit.PIXELS);
|
243
|
infraSpecificEpithetField = addTextField("Infraspecific epithet", "infraSpecificEpithet", 2, row, 3, row);
|
244
|
infraSpecificEpithetField.setWidth(200, Unit.PIXELS);
|
245
|
|
246
|
row++;
|
247
|
grid.addComponent(new Label("Hint: <i>Edit nomenclatural authors in the nomenclatural reference.</i>", ContentMode.HTML), 0, row, 3, row);
|
248
|
|
249
|
row++;
|
250
|
combinationAuthorshipField = new TeamOrPersonField("combination author(s)");
|
251
|
combinationAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
252
|
addField(combinationAuthorshipField, "combinationAuthorship", 0, row, GRID_COLS-1, row);
|
253
|
|
254
|
row++;
|
255
|
nomReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("Nomenclatural reference", Reference.class);
|
256
|
nomReferenceCombobox.addClickListenerAddEntity(e -> getEventBus().publishEvent(
|
257
|
new ReferenceEditorAction(EditorActionType.ADD, null, nomReferenceCombobox, this)
|
258
|
));
|
259
|
nomReferenceCombobox.addClickListenerEditEntity(e -> {
|
260
|
if(nomReferenceCombobox.getValue() != null){
|
261
|
getEventBus().publishEvent(
|
262
|
new ReferenceEditorAction(
|
263
|
EditorActionType.EDIT,
|
264
|
nomReferenceCombobox.getValue().getId(),
|
265
|
nomReferenceCombobox,
|
266
|
this)
|
267
|
);
|
268
|
}
|
269
|
});
|
270
|
// nomReferenceCombobox.setWidth(300, Unit.PIXELS);
|
271
|
nomReferenceCombobox.setWidth("100%");
|
272
|
addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 2, row);
|
273
|
nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
|
274
|
nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
|
275
|
|
276
|
row++;
|
277
|
exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)");
|
278
|
exCombinationAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
279
|
addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
|
280
|
|
281
|
// Basionym
|
282
|
row++;
|
283
|
basionymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
|
284
|
basionymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
|
285
|
addField(basionymsComboboxSelect, "basionyms", 0, row, 3, row);
|
286
|
basionymsComboboxSelect.setWidth(100, Unit.PERCENTAGE);
|
287
|
basionymsComboboxSelect.withEditButton(true);
|
288
|
basionymsComboboxSelect.setEditPermissionTester(new EditPermissionTester() {
|
289
|
|
290
|
@Override
|
291
|
public boolean userHasEditPermission(Object bean) {
|
292
|
return UserHelper.fromSession().userHasPermission((CdmBase)bean, CRUD.UPDATE, CRUD.DELETE);
|
293
|
}
|
294
|
});
|
295
|
basionymsComboboxSelect.setEditActionListener(e -> {
|
296
|
|
297
|
Object fieldValue = e.getSource().getValue();
|
298
|
Integer beanId = null;
|
299
|
if(fieldValue != null){
|
300
|
beanId = ((CdmBase)fieldValue).getId();
|
301
|
|
302
|
}
|
303
|
eventBus.publishEvent(new TaxonNameEditorAction(e.getAction(), beanId, e.getSource(), this));
|
304
|
});
|
305
|
grid.setComponentAlignment(basionymsComboboxSelect, Alignment.TOP_RIGHT);
|
306
|
row++;
|
307
|
basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)");
|
308
|
basionymAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
309
|
addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
|
310
|
row++;
|
311
|
exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)");
|
312
|
exBasionymAuthorshipField.setWidth(100, Unit.PERCENTAGE);
|
313
|
addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
|
314
|
|
315
|
|
316
|
|
317
|
setAdvancedModeEnabled(true);
|
318
|
enableBasionymFields(HAS_BASIONYM_DEFAULT);
|
319
|
registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
|
320
|
registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
|
321
|
registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
|
322
|
registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
|
323
|
registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
|
324
|
setAdvancedMode(false);
|
325
|
|
326
|
}
|
327
|
|
328
|
/**
|
329
|
* @param value
|
330
|
* @return
|
331
|
*/
|
332
|
private void enableBasionymFields(boolean enable) {
|
333
|
|
334
|
|
335
|
basionymAuthorshipField.setVisible(enable);
|
336
|
exBasionymAuthorshipField.setVisible(enable);
|
337
|
basionymsComboboxSelect.setVisible(enable);
|
338
|
TaxonName taxonName = getBean();
|
339
|
|
340
|
if(taxonName != null){
|
341
|
if(modesActive.contains(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
|
342
|
basionymAuthorshipField.setVisible(taxonName.getBasionymAuthorship() != null);
|
343
|
exBasionymAuthorshipField.setVisible(taxonName.getExBasionymAuthorship() != null);
|
344
|
}
|
345
|
updateFieldVisibility(taxonName.getRank());
|
346
|
}
|
347
|
}
|
348
|
|
349
|
/**
|
350
|
* @param rank
|
351
|
* @return
|
352
|
*/
|
353
|
private void updateFieldVisibility(Rank rank) {
|
354
|
boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
|
355
|
// TODO use getField() instead and remove field references
|
356
|
infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
|
357
|
specificEpithetField.setVisible(isSpeciesOrBelow);
|
358
|
infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
|
359
|
genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
|
360
|
exCombinationAuthorshipField.setVisible(isSpeciesOrBelow);
|
361
|
}
|
362
|
|
363
|
@Override
|
364
|
protected void afterItemDataSourceSet() {
|
365
|
TaxonName taxonName = getBean();
|
366
|
boolean showBasionymSection = taxonName.getBasionyms().size() > 0
|
367
|
|| taxonName.getBasionymAuthorship() != null
|
368
|
|| taxonName.getExBasionymAuthorship() != null;
|
369
|
basionymToggle.setValue(showBasionymSection);
|
370
|
basionymToggle.setReadOnly(showBasionymSection);
|
371
|
|
372
|
boolean showExAuthors = taxonName.getExCombinationAuthorship() != null;
|
373
|
validationToggle.setValue(showExAuthors);
|
374
|
validationToggle.setReadOnly(showExAuthors);
|
375
|
|
376
|
if(isModeEnabled(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
|
377
|
combinationAuthorshipField.setVisible(taxonName.getCombinationAuthorship() != null);
|
378
|
}
|
379
|
if(isModeEnabled(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly) && getBean().getNomenclaturalReference() != null) {
|
380
|
nomReferenceCombobox.setCaption("Selection limited to nomenclatural reference and sections");
|
381
|
}
|
382
|
|
383
|
}
|
384
|
|
385
|
/**
|
386
|
* {@inheritDoc}
|
387
|
*/
|
388
|
@Override
|
389
|
public boolean allowAnonymousAccess() {
|
390
|
return false;
|
391
|
}
|
392
|
|
393
|
/**
|
394
|
* {@inheritDoc}
|
395
|
*/
|
396
|
@Override
|
397
|
public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
|
398
|
return null;
|
399
|
}
|
400
|
|
401
|
/**
|
402
|
* {@inheritDoc}
|
403
|
*/
|
404
|
@Override
|
405
|
public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
|
406
|
return nomReferenceCombobox;
|
407
|
}
|
408
|
|
409
|
/**
|
410
|
* {@inheritDoc}
|
411
|
*/
|
412
|
@Override
|
413
|
public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymComboboxSelect() {
|
414
|
return basionymsComboboxSelect;
|
415
|
}
|
416
|
|
417
|
/**
|
418
|
* {@inheritDoc}
|
419
|
*/
|
420
|
@Override
|
421
|
public ListSelect getRankSelect() {
|
422
|
return rankSelect;
|
423
|
}
|
424
|
|
425
|
/**
|
426
|
* @return the exBasionymAuthorshipField
|
427
|
*/
|
428
|
@Override
|
429
|
public TeamOrPersonField getExBasionymAuthorshipField() {
|
430
|
return exBasionymAuthorshipField;
|
431
|
}
|
432
|
|
433
|
/**
|
434
|
* @return the basionymAuthorshipField
|
435
|
*/
|
436
|
@Override
|
437
|
public TeamOrPersonField getBasionymAuthorshipField() {
|
438
|
return basionymAuthorshipField;
|
439
|
}
|
440
|
|
441
|
/**
|
442
|
* @return the combinationAuthorshipField
|
443
|
*/
|
444
|
@Override
|
445
|
public TeamOrPersonField getCombinationAuthorshipField() {
|
446
|
return combinationAuthorshipField;
|
447
|
}
|
448
|
|
449
|
/**
|
450
|
* @return the exCombinationAuthorshipField
|
451
|
*/
|
452
|
@Override
|
453
|
public TeamOrPersonField getExCombinationAuthorshipField() {
|
454
|
return exCombinationAuthorshipField;
|
455
|
}
|
456
|
|
457
|
@Override
|
458
|
public void enableMode(TaxonNamePopupEditorMode mode){
|
459
|
modesActive.add(mode);
|
460
|
}
|
461
|
|
462
|
@Override
|
463
|
public boolean isModeEnabled(TaxonNamePopupEditorMode mode){
|
464
|
return modesActive.contains(mode);
|
465
|
}
|
466
|
|
467
|
@Override
|
468
|
public void disableMode(TaxonNamePopupEditorMode mode){
|
469
|
modesActive.remove(mode);
|
470
|
}
|
471
|
|
472
|
@Override
|
473
|
public EnumSet<TaxonNamePopupEditorMode> getModesActive(){
|
474
|
return modesActive;
|
475
|
}
|
476
|
|
477
|
@Override
|
478
|
public CheckBox getBasionymToggle() {
|
479
|
return basionymToggle;
|
480
|
}
|
481
|
|
482
|
/**
|
483
|
* {@inheritDoc}
|
484
|
*/
|
485
|
@Override
|
486
|
public void setReadOnly(boolean readOnly) {
|
487
|
boolean basionymToggleReadonly = basionymToggle.isReadOnly();
|
488
|
boolean validationToggleReadonly = validationToggle.isReadOnly();
|
489
|
super.setReadOnly(readOnly);
|
490
|
// preserve old readonly states if they were true
|
491
|
if(basionymToggleReadonly){
|
492
|
basionymToggle.setReadOnly(true);
|
493
|
}
|
494
|
if(validationToggleReadonly){
|
495
|
validationToggle.setReadOnly(true);
|
496
|
}
|
497
|
}
|
498
|
|
499
|
|
500
|
|
501
|
|
502
|
}
|