Project

General

Profile

Download (24.8 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.permission.AccessRestrictedView;
44
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
45
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
46
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
47
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
48
import eu.etaxonomy.vaadin.component.SwitchableTextField;
49
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
50
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
51
import eu.etaxonomy.vaadin.event.EditorActionType;
52
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
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().getUuid(),
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 CdmEditDeletePermissionTester());
312
        basionymsComboboxSelect.setEditActionListener(e -> {
313

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

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

    
333

    
334

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

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

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

    
347
        setAdvancedMode(false);
348

    
349
    }
350

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

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

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

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

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

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

    
417
    }
418

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

    
425
        TaxonName taxonName = getBean();
426

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

    
435

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

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

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

    
455
        }
456

    
457
        updateFieldVisibility();
458

    
459
    }
460

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

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

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

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

    
519
        return lastInferredAuthorshipState;
520
    }
521

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

    
528
        // TODO use getField() instead and remove field references
529

    
530
        TaxonName taxonName = getBean();
531
        Rank rank = taxonName.getRank();
532

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

    
537
        basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
538
        exBasionymAuthorshipField.setVisible(withBasionym);
539
        basionymsComboboxSelect.setVisible(withBasionym);
540

    
541
        combinationAuthorshipField.setVisible(isInferredCombinationAuthorship != null && !isInferredCombinationAuthorship);
542
        if(BooleanUtils.isTrue(basionymToggle.getValue())){
543
            basionymAuthorshipField.setVisible(isInferredBasionymAuthorship != null && !isInferredBasionymAuthorship);
544
            exBasionymAuthorshipField.setVisible(isInferredExBasionymAuthorship != null && !isInferredExBasionymAuthorship);
545
        }
546

    
547
//        if(taxonName != null){
548
//            if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
549
//            }
550
//        }
551

    
552
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
553
        specificEpithetField.setVisible(isSpeciesOrBelow);
554
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
555
        genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
556
        exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
557
    }
558

    
559
    @Override
560
    public void cancel() {
561
        authorshipUpdateListeners.keySet().forEach(field -> field.removeValueChangeListener(authorshipUpdateListeners.get(field)));
562
        super.cancel();
563
    }
564

    
565
    /**
566
     * {@inheritDoc}
567
     */
568
    @Override
569
    public boolean allowAnonymousAccess() {
570
        return false;
571
    }
572

    
573
    /**
574
     * {@inheritDoc}
575
     */
576
    @Override
577
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
578
        return null;
579
    }
580

    
581
    /**
582
     * {@inheritDoc}
583
     */
584
    @Override
585
    public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
586
        return nomReferenceCombobox;
587
    }
588

    
589
    /**
590
     * {@inheritDoc}
591
     */
592
    @Override
593
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymComboboxSelect() {
594
        return basionymsComboboxSelect;
595
    }
596

    
597
    /**
598
     * {@inheritDoc}
599
     */
600
    @Override
601
    public ListSelect getRankSelect() {
602
        return rankSelect;
603
    }
604

    
605
    /**
606
     * @return the exBasionymAuthorshipField
607
     */
608
    @Override
609
    public TeamOrPersonField getExBasionymAuthorshipField() {
610
        return exBasionymAuthorshipField;
611
    }
612

    
613
    /**
614
     * @return the basionymAuthorshipField
615
     */
616
    @Override
617
    public TeamOrPersonField getBasionymAuthorshipField() {
618
        return basionymAuthorshipField;
619
    }
620

    
621
    /**
622
     * @return the combinationAuthorshipField
623
     */
624
    @Override
625
    public TeamOrPersonField getCombinationAuthorshipField() {
626
        return combinationAuthorshipField;
627
    }
628

    
629
    /**
630
     * @return the exCombinationAuthorshipField
631
     */
632
    @Override
633
    public TeamOrPersonField getExCombinationAuthorshipField() {
634
        return exCombinationAuthorshipField;
635
    }
636

    
637
    @Override
638
    public void enableMode(TaxonNamePopupEditorMode mode){
639
            modesActive.add(mode);
640
    }
641

    
642
    @Override
643
    public boolean isModeEnabled(TaxonNamePopupEditorMode mode){
644
        return modesActive.contains(mode);
645
    }
646

    
647
    @Override
648
    public void disableMode(TaxonNamePopupEditorMode mode){
649
        modesActive.remove(mode);
650
    }
651

    
652
    @Override
653
    public EnumSet<TaxonNamePopupEditorMode> getModesActive(){
654
        return modesActive;
655
    }
656

    
657
    @Override
658
    public CheckBox getBasionymToggle() {
659
        return basionymToggle;
660
    }
661

    
662
    /**
663
     * {@inheritDoc}
664
     */
665
    @Override
666
    public void setReadOnly(boolean readOnly) {
667
        boolean basionymToggleReadonly = basionymToggle.isReadOnly();
668
        boolean validationToggleReadonly = validationToggle.isReadOnly();
669
        super.setReadOnly(readOnly);
670
        // preserve old readonly states if they were true
671
        if(basionymToggleReadonly){
672
            basionymToggle.setReadOnly(true);
673
        }
674
        if(validationToggleReadonly){
675
            validationToggle.setReadOnly(true);
676
        }
677
    }
678

    
679

    
680

    
681

    
682
}
(10-10/13)