Project

General

Profile

Download (25.2 KB) Statistics
| Branch: | Tag: | Revision:
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

    
23
import com.vaadin.data.Property;
24
import com.vaadin.data.Property.ValueChangeListener;
25
import com.vaadin.shared.ui.label.ContentMode;
26
import com.vaadin.spring.annotation.SpringComponent;
27
import com.vaadin.ui.AbstractField;
28
import com.vaadin.ui.Alignment;
29
import com.vaadin.ui.CheckBox;
30
import com.vaadin.ui.GridLayout;
31
import com.vaadin.ui.Label;
32
import com.vaadin.ui.ListSelect;
33
import com.vaadin.ui.TextField;
34

    
35
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
36
import eu.etaxonomy.cdm.model.common.CdmBase;
37
import eu.etaxonomy.cdm.model.name.Rank;
38
import eu.etaxonomy.cdm.model.name.TaxonName;
39
import eu.etaxonomy.cdm.model.reference.Reference;
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.model.name.TaxonNameDTO;
44
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
45
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
46
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
47
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
48
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
49
import eu.etaxonomy.vaadin.component.SwitchableTextField;
50
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
51
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
52
import eu.etaxonomy.vaadin.event.EditorActionType;
53
import eu.etaxonomy.vaadin.mvp.AbstractCdmDTOPopupEditor;
54

    
55
/**
56
 * @author a.kohlbecker
57
 * @since May 22, 2017
58
 *
59
 */
60
@SpringComponent
61
@Scope("prototype")
62
public class TaxonNamePopupEditor extends AbstractCdmDTOPopupEditor<TaxonNameDTO, TaxonName, TaxonNameEditorPresenter> implements TaxonNamePopupEditorView, AccessRestrictedView {
63

    
64
    private static final long serialVersionUID = -7037436241474466359L;
65

    
66
    private final static int GRID_COLS = 4;
67

    
68
    private final static int GRID_ROWS = 13;
69

    
70
    private static final boolean HAS_BASIONYM_DEFAULT = false;
71

    
72
    private TextField genusOrUninomialField;
73

    
74
    private TextField infraGenericEpithetField;
75

    
76
    private TextField specificEpithetField;
77

    
78
    private TextField infraSpecificEpithetField;
79

    
80
    private SwitchableTextField fullTitleCacheFiled;
81

    
82
    private SwitchableTextField protectedNameCacheField;
83

    
84
    private ToOneRelatedEntityCombobox<Reference> nomReferenceCombobox;
85

    
86
    private TextField nomenclaturalReferenceDetail;
87

    
88
    private TeamOrPersonField exBasionymAuthorshipField;
89

    
90
    private TeamOrPersonField basionymAuthorshipField;
91

    
92
    private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymsComboboxSelect;
93

    
94
    private CheckBox basionymToggle;
95

    
96
    private CheckBox validationToggle;
97

    
98
    private ListSelect rankSelect;
99

    
100
    private TeamOrPersonField combinationAuthorshipField;
101

    
102
    private TeamOrPersonField exCombinationAuthorshipField;
103

    
104
    private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class);
105

    
106
    private Boolean isInferredCombinationAuthorship = null;
107

    
108
    private Boolean isInferredBasionymAuthorship = null;
109

    
110
    private Boolean isInferredExBasionymAuthorship = null;
111

    
112
    private Map<AbstractField, Property.ValueChangeListener> authorshipUpdateListeners = new HashMap<>();
113

    
114
    /**
115
     * @param layout
116
     * @param dtoType
117
     */
118
    public TaxonNamePopupEditor() {
119
        super(new GridLayout(GRID_COLS, GRID_ROWS), TaxonNameDTO.class);
120
    }
121

    
122
    /**
123
     * {@inheritDoc}
124
     */
125
    @Override
126
    public String getWindowCaption() {
127
        return "Name editor";
128
    }
129

    
130

    
131

    
132
    /**
133
     * {@inheritDoc}
134
     */
135
    @Override
136
    public int getWindowWidth() {
137
        return 800;
138
    }
139

    
140
    /**
141
     * {@inheritDoc}
142
     */
143
    @Override
144
    public void focusFirst() {
145
        // titleField.focus();
146

    
147
    }
148

    
149
    /**
150
     * {@inheritDoc}
151
     */
152
    @Override
153
    protected String getDefaultComponentStyles() {
154
        return "tiny";
155
    }
156

    
157
    /**
158
     * {@inheritDoc}
159
     */
160
    @Override
161
    protected void initContent() {
162

    
163
        GridLayout grid = (GridLayout)getFieldLayout();
164
        grid.setSizeFull();
165
        grid.setHideEmptyRowsAndColumns(true);
166
        grid.setSpacing(true);
167
        grid.setColumnExpandRatio(0, 0.3f);
168
        grid.setColumnExpandRatio(1, 0.3f);
169
        grid.setColumnExpandRatio(2, 0.3f);
170
        grid.setColumnExpandRatio(3, 0.0f);
171

    
172
        /*
173
         - nameType: preset, needs to be set in the presenter for new names
174
         - appendedPhrase: -> TODO field
175
         - nomenclaturalMicroReference:  -> TODO field
176
         - nomenclaturalReference ->  field but disabled for REGISTRY
177
         - rank -> SelectField which determines the visiblity of the other fields
178

    
179
         - fullTitleCache + protectedFullTitleCache -> SwitchableTextField : ADVANCED_MODE
180
         - nameCache + protectedNameCache -> SwitchableTextField : ADVANCED_MODE
181

    
182
         - homotypicalGroup -> hidden
183
         - typeDesignations -> hidden
184
         - descriptions -> hidden
185
         - taxonBases -> hidden
186
         - registrations -> hidden
187

    
188
         - relationsFromThisName-> TODO implement later
189
         - relationsToThisName -> TODO implement later
190

    
191
         - genusOrUninomial -> textField
192
         - infraGenericEpithet  -> textField
193
         - specificEpithet  -> textField
194
         - infraSpecificEpithet  -> textField
195

    
196
         - authorshipCache + protectedAuthorshipCache -> SwitchableTextField : only ADVANCED_MODE and disabled for REGISTRY
197
         - basionymAuthorship -> field but disabled for REGISTRY, basionym is set as nameRelationShip
198
         - combinationAuthorship -> field but disabled for REGISTRY author team of the reference
199
         - exCombinationAuthorship -> textField
200
         - exBasionymAuthorship -> textField
201

    
202
         - status -> TODO field
203
         - monomHybrid -> TODO implement hybrids later
204
         - binomHybrid -> TODO implement hybrids later
205
         - trinomHybrid -> TODO implement hybrids later
206

    
207
         - hybridParentRelations -> TODO implement hybrids later
208
         - hybridChildRelations -> TODO implement hybrids later
209
         - hybridFormula -> TODO implement hybrids later
210

    
211
         ** ViralName attributes **
212
         - acronym
213

    
214
         ** BacterialName attributes **
215
         - subGenusAuthorship
216
         - nameApprobation
217
         - breed
218
         - publicationYear
219
         - originalPublicationYear
220
         - cultivarName
221
        */
222

    
223
        int row = 0;
224

    
225
        rankSelect = new ListSelect("Rank");
226
        rankSelect.setNullSelectionAllowed(false);
227
        rankSelect.setRows(1);
228
        rankSelect.setWidth(100, Unit.PERCENTAGE);
229
        rankSelect.addValueChangeListener(e -> updateFieldVisibility());
230
        addField(rankSelect, "rank", 0, row, 1, row);
231
        grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT);
232

    
233
        basionymToggle = new CheckBox("With basionym");
234
        basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
235

    
236
        basionymToggle.setStyleName(getDefaultComponentStyles());
237
        grid.addComponent(basionymToggle, 2, row, 3, row);
238
        grid.setComponentAlignment(basionymToggle, Alignment.BOTTOM_LEFT);
239

    
240
        row++;
241
        validationToggle = new CheckBox("Validation");
242
        validationToggle.addValueChangeListener(e -> {
243
                boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
244
                exCombinationAuthorshipField.setVisible(enable);
245
            });
246
        grid.addComponent(validationToggle, 2, row, 3, row);
247
        grid.setComponentAlignment(validationToggle, Alignment.BOTTOM_LEFT);
248

    
249
        row++;
250
        // fullTitleCache
251
        fullTitleCacheFiled = addSwitchableTextField("Full title cache", "fullTitleCache", "protectedFullTitleCache", 0, row, GRID_COLS-1, row);
252
        fullTitleCacheFiled.setWidth(100, Unit.PERCENTAGE);
253
        row++;
254
        protectedNameCacheField = addSwitchableTextField("Name cache", "nameCache", "protectedNameCache", 0, row, GRID_COLS-1, row);
255
        protectedNameCacheField.setWidth(100, Unit.PERCENTAGE);
256
        row++;
257
        genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
258
        genusOrUninomialField.setWidth(200, Unit.PIXELS);
259
        infraGenericEpithetField = addTextField("Infrageneric epithet", "infraGenericEpithet", 2, row, 3, row);
260
        infraGenericEpithetField.setWidth(200, Unit.PIXELS);
261
        row++;
262
        specificEpithetField = addTextField("Specific epithet", "specificEpithet", 0, row, 1, row);
263
        specificEpithetField.setWidth(200, Unit.PIXELS);
264
        infraSpecificEpithetField = addTextField("Infraspecific epithet", "infraSpecificEpithet", 2, row, 3, row);
265
        infraSpecificEpithetField.setWidth(200, Unit.PIXELS);
266

    
267
        row++;
268
        grid.addComponent(new Label("Hint: <i>Edit nomenclatural authors in the nomenclatural reference.</i>", ContentMode.HTML), 0, row, 3, row);
269

    
270
        row++;
271
        combinationAuthorshipField = new TeamOrPersonField("Combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
272
        combinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
273
        addField(combinationAuthorshipField, "combinationAuthorship", 0, row, GRID_COLS-1, row);
274

    
275
        row++;
276
        nomReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("Nomenclatural reference", Reference.class);
277
        nomReferenceCombobox.addClickListenerAddEntity(e -> getViewEventBus().publish(
278
                this,
279
                new ReferenceEditorAction(EditorActionType.ADD, null, nomReferenceCombobox, this)
280
                ));
281
        nomReferenceCombobox.addClickListenerEditEntity(e -> {
282
            if(nomReferenceCombobox.getValue() != null){
283
                getViewEventBus().publish(this,
284
                    new ReferenceEditorAction(
285
                            EditorActionType.EDIT,
286
                            nomReferenceCombobox.getValue().getUuid(),
287
                            nomReferenceCombobox,
288
                            this)
289
                );
290
            }
291
            });
292
        logger.setLevel(Level.DEBUG);
293
        nomReferenceCombobox.getSelect().addValueChangeListener(e -> logger.debug("nomReferenceCombobox value changed #1"));
294
        // nomReferenceCombobox.setWidth(300, Unit.PIXELS);
295
        nomReferenceCombobox.setWidth("100%");
296
        addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 2, row);
297
        nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
298
        nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
299

    
300
        row++;
301
        exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
302
        exCombinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
303
        addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
304

    
305
        // Basionym
306
        row++;
307
        basionymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
308
        basionymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
309
        addField(basionymsComboboxSelect, "basionyms", 0, row, 3, row);
310
        basionymsComboboxSelect.setWidth(100, Unit.PERCENTAGE);
311
        basionymsComboboxSelect.withEditButton(true);
312
        basionymsComboboxSelect.setEditPermissionTester(new CdmEditDeletePermissionTester());
313
        basionymsComboboxSelect.setEditActionListener(e -> {
314

    
315
            Object fieldValue = e.getSource().getValue();
316
            UUID beanUuid = null;
317
            if(fieldValue != null){
318
                beanUuid = ((CdmBase)fieldValue).getUuid();
319

    
320
            }
321
            ReloadableLazyComboBox<TaxonName>  lazyCombobox = (ReloadableLazyComboBox<TaxonName>) e.getSource();
322
            getViewEventBus().publish(this, new TaxonNameEditorAction(e.getAction(), beanUuid, lazyCombobox, this));
323
        });
324
        grid.setComponentAlignment(basionymsComboboxSelect, Alignment.TOP_RIGHT);
325
        row++;
326
        basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
327
        basionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
328
        addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
329
        row++;
330
        exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
331
        exBasionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
332
        addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
333

    
334

    
335

    
336
        setAdvancedModeEnabled(true);
337
        registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
338

    
339
        registerAdvancedModeComponents(combinationAuthorshipField);
340
        registerAdvancedModeComponents(basionymAuthorshipField);
341
        registerAdvancedModeComponents(exBasionymAuthorshipField);
342

    
343
        registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
344
        registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
345
        registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
346
        registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
347

    
348
        setAdvancedMode(false);
349

    
350
    }
351

    
352
    protected TeamOrPersonBase inferBasiomynAuthors() {
353
        List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
354
        if(!basionyms.isEmpty()){
355
            TaxonName basionym = basionyms.get(0);
356
            if(basionym.getCombinationAuthorship() != null){
357
                return basionym.getCombinationAuthorship();
358
            } else if(basionym.getNomenclaturalReference() != null){
359
                return basionym.getNomenclaturalReference().getAuthorship();
360
            }
361
        }
362
        return null;
363
    }
364

    
365
    protected TeamOrPersonBase inferExBasiomynAuthors() {
366
        List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
367
        if(!basionyms.isEmpty()){
368
            TaxonName basionym = basionyms.get(0);
369
                return basionym.getExCombinationAuthorship();
370
        }
371
        return null;
372
    }
373

    
374
    protected TeamOrPersonBase inferCombinationAuthors() {
375
        Reference nomRef = nomReferenceCombobox.getValue();
376
        if(nomRef != null) {
377
            return nomRef.getAuthorship();
378
        }
379
        return null;
380
    }
381

    
382
    @Override
383
    protected void afterItemDataSourceSet() {
384
        TaxonNameDTO taxonName = getBean();
385
        boolean showBasionymSection = taxonName.getBasionyms().size() > 0
386
                || taxonName.getBasionymAuthorship() != null
387
                || taxonName.getExBasionymAuthorship() != null;
388
        basionymToggle.setValue(showBasionymSection);
389
        basionymToggle.setReadOnly(showBasionymSection);
390
        basionymToggle.addValueChangeListener(e -> {
391
            updateAuthorshipFields();
392
            updateFieldVisibility();
393
        });
394

    
395
        boolean showExAuthors = taxonName.getExCombinationAuthorship() != null;
396
        validationToggle.setValue(showExAuthors);
397
        validationToggle.setReadOnly(showExAuthors);
398
        exCombinationAuthorshipField.setVisible(showExAuthors);
399

    
400
        if(isModeEnabled(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
401
            updateAuthorshipFields();
402
        }
403
        if(isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY) && getBean().getNomenclaturalReference() != null) {
404
            nomReferenceCombobox.setCaption("Selection limited to nomenclatural reference and sections");
405
        }
406
        if(isModeEnabled(TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE)) {
407
            if(combinationAuthorshipField.getValue() == null){
408
                nomReferenceCombobox.setRequired(true);
409
            } else {
410
                combinationAuthorshipField.addValueChangeListener(e -> {
411
                    if(e.getProperty().getValue() == null){
412
                        nomReferenceCombobox.setRequired(true);
413
                    }
414
                });
415
            }
416
        }
417

    
418
    }
419

    
420
    /**
421
     * @param taxonName
422
     */
423
    @Override
424
    public void updateAuthorshipFields() {
425

    
426
        TaxonNameDTO taxonName = getBean();
427

    
428
        // ------------- CombinationAuthors
429
        isInferredCombinationAuthorship = updateAuthorshipFieldData(
430
                taxonName.getCombinationAuthorship(),
431
                inferCombinationAuthors(),
432
                combinationAuthorshipField,
433
                nomReferenceCombobox.getSelect(),
434
                isInferredCombinationAuthorship);
435

    
436

    
437
        // ------------- Basionym and ExBasionymAuthors
438
        if(BooleanUtils.isTrue(basionymToggle.getValue())){
439

    
440
            isInferredBasionymAuthorship = updateAuthorshipFieldData(
441
                    taxonName.getBasionymAuthorship(),
442
                    inferBasiomynAuthors(),
443
                    basionymAuthorshipField,
444
                    basionymsComboboxSelect,
445
                    isInferredBasionymAuthorship
446
                    );
447

    
448
            isInferredExBasionymAuthorship = updateAuthorshipFieldData(
449
                    taxonName.getExBasionymAuthorship(),
450
                    inferExBasiomynAuthors(),
451
                    exBasionymAuthorshipField,
452
                    basionymsComboboxSelect,
453
                    isInferredExBasionymAuthorship
454
                    );
455

    
456
        }
457

    
458
        updateFieldVisibility();
459

    
460
    }
461

    
462
//    /**
463
//     *
464
//     */
465
//    protected void updateAuthorshipFieldsVisibility() {
466
//        combinationAuthorshipField.setVisible(!isInferredCombinationAuthorship);
467
//        if(BooleanUtils.isTrue(basionymToggle.getValue())){
468
//            basionymAuthorshipField.setVisible(!isInferredBasionymAuthorship);
469
//            exBasionymAuthorshipField.setVisible(!isInferredExBasionymAuthorship);
470
//        }
471
//    }
472

    
473
    /**
474
     *
475
     * @param authorship
476
     *    the value of the taxonName authorship field
477
     * @param inferredAuthors
478
     *    the value inferred from other fields which may be set as authorship to the taxon name
479
     * @param authorshipField
480
     *    the ui element to edit the taxonName authorship field
481
     * @param updateTriggerField
482
     * @param lastInferredAuthorshipState
483
     * @return
484
     */
485
    protected Boolean updateAuthorshipFieldData(TeamOrPersonBase<?> authorship, TeamOrPersonBase inferredAuthors,
486
            TeamOrPersonField authorshipField, AbstractField updateTriggerField,
487
            Boolean lastInferredAuthorshipState) {
488

    
489
        if(authorship == null){
490
            authorshipField.setValue(inferredAuthors);
491
            lastInferredAuthorshipState = true;
492
        } else {
493
            boolean authorshipMatch = authorship == inferredAuthors;
494
            if(lastInferredAuthorshipState == null){
495
                // initialization of authorshipState, this comes only into account when the editor is just being initialized
496
                lastInferredAuthorshipState = authorshipMatch;
497
            }
498
            if(!authorshipMatch && lastInferredAuthorshipState){
499
                // update the combinationAuthorshipField to follow changes of the nomenclatural reference in case it was autofilled before
500
                authorshipField.setValue(inferredAuthors);
501
                lastInferredAuthorshipState = true;
502
            }
503
        }
504

    
505
        if(updateTriggerField != null){
506
            // IMPORTANT!
507
            // this ChangeListener must be added at this very late point in the editor lifecycle so that it is called after
508
            // the ToOneRelatedEntityReloader which may have been added to the updateTriggerField in the presenters handleViewEntered() method.
509
            // Otherwise we risk multiple representation problems in the hibernate session
510
            if(!authorshipUpdateListeners.containsKey(updateTriggerField)){
511
                ValueChangeListener listener = e ->  {
512
                    logger.debug(" value changed #2");
513
                    updateAuthorshipFields();
514
                };
515
                updateTriggerField.addValueChangeListener(listener);
516
                authorshipUpdateListeners.put(updateTriggerField, listener);
517
            }
518
        }
519

    
520
        return lastInferredAuthorshipState;
521
    }
522

    
523
    /**
524
     * @param rank
525
     * @return
526
     */
527
    private void updateFieldVisibility() {
528

    
529
        // TODO use getField() instead and remove field references
530
        Rank rank = (Rank) rankSelect.getValue();
531

    
532
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
533
        Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue());
534
        Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue());
535

    
536
        specificEpithetField.setVisible(isSpeciesOrBelow);
537
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
538
        infraGenericEpithetField.setVisible(rank.isInfraGeneric());
539

    
540

    
541
        basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
542
        exBasionymAuthorshipField.setVisible(withBasionym);
543
        basionymsComboboxSelect.setVisible(withBasionym);
544

    
545
        combinationAuthorshipField.setVisible(isInferredCombinationAuthorship != null && !isInferredCombinationAuthorship);
546
        if(BooleanUtils.isTrue(basionymToggle.getValue())){
547
            basionymAuthorshipField.setVisible(isInferredBasionymAuthorship != null && !isInferredBasionymAuthorship);
548
            exBasionymAuthorshipField.setVisible(isInferredExBasionymAuthorship != null && !isInferredExBasionymAuthorship);
549
        }
550

    
551
//        if(taxonName != null){
552
//            if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
553
//            }
554
//        }
555

    
556
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
557
        specificEpithetField.setVisible(isSpeciesOrBelow);
558
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
559
        genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
560
        exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
561
    }
562

    
563
    @Override
564
    public void cancel() {
565
        authorshipUpdateListeners.keySet().forEach(field -> field.removeValueChangeListener(authorshipUpdateListeners.get(field)));
566
        super.cancel();
567
    }
568

    
569
    /**
570
     * {@inheritDoc}
571
     */
572
    @Override
573
    public boolean allowAnonymousAccess() {
574
        return false;
575
    }
576

    
577
    /**
578
     * {@inheritDoc}
579
     */
580
    @Override
581
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
582
        return null;
583
    }
584

    
585
    /**
586
     * {@inheritDoc}
587
     */
588
    @Override
589
    public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
590
        return nomReferenceCombobox;
591
    }
592

    
593
    /**
594
     * {@inheritDoc}
595
     */
596
    @Override
597
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymComboboxSelect() {
598
        return basionymsComboboxSelect;
599
    }
600

    
601
    /**
602
     * {@inheritDoc}
603
     */
604
    @Override
605
    public ListSelect getRankSelect() {
606
        return rankSelect;
607
    }
608

    
609
    /**
610
     * @return the exBasionymAuthorshipField
611
     */
612
    @Override
613
    public TeamOrPersonField getExBasionymAuthorshipField() {
614
        return exBasionymAuthorshipField;
615
    }
616

    
617
    /**
618
     * @return the basionymAuthorshipField
619
     */
620
    @Override
621
    public TeamOrPersonField getBasionymAuthorshipField() {
622
        return basionymAuthorshipField;
623
    }
624

    
625
    /**
626
     * @return the combinationAuthorshipField
627
     */
628
    @Override
629
    public TeamOrPersonField getCombinationAuthorshipField() {
630
        return combinationAuthorshipField;
631
    }
632

    
633
    /**
634
     * @return the exCombinationAuthorshipField
635
     */
636
    @Override
637
    public TeamOrPersonField getExCombinationAuthorshipField() {
638
        return exCombinationAuthorshipField;
639
    }
640

    
641
    @Override
642
    public void enableMode(TaxonNamePopupEditorMode mode){
643
            modesActive.add(mode);
644
    }
645

    
646
    @Override
647
    public boolean isModeEnabled(TaxonNamePopupEditorMode mode){
648
        return modesActive.contains(mode);
649
    }
650

    
651
    @Override
652
    public void disableMode(TaxonNamePopupEditorMode mode){
653
        modesActive.remove(mode);
654
    }
655

    
656
    @Override
657
    public EnumSet<TaxonNamePopupEditorMode> getModesActive(){
658
        return modesActive;
659
    }
660

    
661
    @Override
662
    public CheckBox getBasionymToggle() {
663
        return basionymToggle;
664
    }
665

    
666
    /**
667
     * {@inheritDoc}
668
     */
669
    @Override
670
    public void setReadOnly(boolean readOnly) {
671
        boolean basionymToggleReadonly = basionymToggle.isReadOnly();
672
        boolean validationToggleReadonly = validationToggle.isReadOnly();
673
        super.setReadOnly(readOnly);
674
        combinationAuthorshipField.setEditorReadOnly(readOnly);
675
        exCombinationAuthorshipField.setEditorReadOnly(readOnly);
676
        basionymAuthorshipField.setEditorReadOnly(readOnly);
677
        exBasionymAuthorshipField.setEditorReadOnly(readOnly);
678
        // preserve old readonly states if they were true
679
        if(basionymToggleReadonly){
680
            basionymToggle.setReadOnly(true);
681
        }
682
        if(validationToggleReadonly){
683
            validationToggle.setReadOnly(true);
684
        }
685
    }
686

    
687

    
688

    
689

    
690
}
(10-10/13)