Project

General

Profile

Download (24.9 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.persistence.hibernate.permission.CRUD;
41
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
42
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
43
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
44
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
45
import eu.etaxonomy.cdm.vaadin.security.UserHelper;
46
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
47
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
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
import eu.etaxonomy.vaadin.permission.EditPermissionTester;
54

    
55
/**
56
 * @author a.kohlbecker
57
 * @since May 22, 2017
58
 *
59
 */
60
@SpringComponent
61
@Scope("prototype")
62
public class TaxonNamePopupEditor extends AbstractCdmPopupEditor<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), TaxonName.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 EditPermissionTester() {
313

    
314
            @Override
315
            public boolean userHasEditPermission(Object bean) {
316
                return  UserHelper.fromSession().userHasPermission((CdmBase)bean, CRUD.UPDATE, CRUD.DELETE);
317
            }
318
        });
319
        basionymsComboboxSelect.setEditActionListener(e -> {
320

    
321
            Object fieldValue = e.getSource().getValue();
322
            UUID beanUuid = null;
323
            if(fieldValue != null){
324
                beanUuid = ((CdmBase)fieldValue).getUuid();
325

    
326
            }
327
            getViewEventBus().publish(this, new TaxonNameEditorAction(e.getAction(), beanUuid, e.getSource(), this));
328
        });
329
        grid.setComponentAlignment(basionymsComboboxSelect, Alignment.TOP_RIGHT);
330
        row++;
331
        basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
332
        basionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
333
        addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
334
        row++;
335
        exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
336
        exBasionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
337
        addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
338

    
339

    
340

    
341
        setAdvancedModeEnabled(true);
342
        registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
343

    
344
        registerAdvancedModeComponents(combinationAuthorshipField);
345
        registerAdvancedModeComponents(basionymAuthorshipField);
346
        registerAdvancedModeComponents(exBasionymAuthorshipField);
347

    
348
        registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
349
        registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
350
        registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
351
        registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
352

    
353
        setAdvancedMode(false);
354

    
355
    }
356

    
357
    protected TeamOrPersonBase inferBasiomynAuthors() {
358
        List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
359
        if(!basionyms.isEmpty()){
360
            TaxonName basionym = basionyms.get(0);
361
            if(basionym.getCombinationAuthorship() != null){
362
                return basionym.getCombinationAuthorship();
363
            } else if(basionym.getNomenclaturalReference() != null){
364
                return basionym.getNomenclaturalReference().getAuthorship();
365
            }
366
        }
367
        return null;
368
    }
369

    
370
    protected TeamOrPersonBase inferExBasiomynAuthors() {
371
        List<TaxonName> basionyms = basionymsComboboxSelect.getValue();
372
        if(!basionyms.isEmpty()){
373
            TaxonName basionym = basionyms.get(0);
374
                return basionym.getExCombinationAuthorship();
375
        }
376
        return null;
377
    }
378

    
379
    protected TeamOrPersonBase inferCombinationAuthors() {
380
        Reference nomRef = nomReferenceCombobox.getValue();
381
        if(nomRef != null) {
382
            return nomRef.getAuthorship();
383
        }
384
        return null;
385
    }
386

    
387
    @Override
388
    protected void afterItemDataSourceSet() {
389
        TaxonName taxonName = getBean();
390
        boolean showBasionymSection = taxonName.getBasionyms().size() > 0
391
                || taxonName.getBasionymAuthorship() != null
392
                || taxonName.getExBasionymAuthorship() != null;
393
        basionymToggle.setValue(showBasionymSection);
394
        basionymToggle.setReadOnly(showBasionymSection);
395
        basionymToggle.addValueChangeListener(e -> {
396
            updateAuthorshipFields();
397
            updateFieldVisibility();
398
        });
399

    
400
        boolean showExAuthors = taxonName.getExCombinationAuthorship() != null;
401
        validationToggle.setValue(showExAuthors);
402
        validationToggle.setReadOnly(showExAuthors);
403
        exCombinationAuthorshipField.setVisible(showExAuthors);
404

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

    
423
    }
424

    
425
    /**
426
     * @param taxonName
427
     */
428
    @Override
429
    public void updateAuthorshipFields() {
430

    
431
        TaxonName taxonName = getBean();
432

    
433
        // ------------- CombinationAuthors
434
        isInferredCombinationAuthorship = updateAuthorshipFieldData(
435
                taxonName.getCombinationAuthorship(),
436
                inferCombinationAuthors(),
437
                combinationAuthorshipField,
438
                nomReferenceCombobox.getSelect(),
439
                isInferredCombinationAuthorship);
440

    
441

    
442
        // ------------- Basionym and ExBasionymAuthors
443
        if(BooleanUtils.isTrue(basionymToggle.getValue())){
444

    
445
            isInferredBasionymAuthorship = updateAuthorshipFieldData(
446
                    taxonName.getBasionymAuthorship(),
447
                    inferBasiomynAuthors(),
448
                    basionymAuthorshipField,
449
                    basionymsComboboxSelect,
450
                    isInferredBasionymAuthorship
451
                    );
452

    
453
            isInferredExBasionymAuthorship = updateAuthorshipFieldData(
454
                    taxonName.getExBasionymAuthorship(),
455
                    inferExBasiomynAuthors(),
456
                    exBasionymAuthorshipField,
457
                    basionymsComboboxSelect,
458
                    isInferredExBasionymAuthorship
459
                    );
460

    
461
        }
462

    
463
        updateFieldVisibility();
464

    
465
    }
466

    
467
//    /**
468
//     *
469
//     */
470
//    protected void updateAuthorshipFieldsVisibility() {
471
//        combinationAuthorshipField.setVisible(!isInferredCombinationAuthorship);
472
//        if(BooleanUtils.isTrue(basionymToggle.getValue())){
473
//            basionymAuthorshipField.setVisible(!isInferredBasionymAuthorship);
474
//            exBasionymAuthorshipField.setVisible(!isInferredExBasionymAuthorship);
475
//        }
476
//    }
477

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

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

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

    
525
        return lastInferredAuthorshipState;
526
    }
527

    
528
    /**
529
     * @param rank
530
     * @return
531
     */
532
    private void updateFieldVisibility() {
533

    
534
        // TODO use getField() instead and remove field references
535

    
536
        TaxonName taxonName = getBean();
537
        Rank rank = taxonName.getRank();
538

    
539
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
540
        Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue());
541
        Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue());
542

    
543
        basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
544
        exBasionymAuthorshipField.setVisible(withBasionym);
545
        basionymsComboboxSelect.setVisible(withBasionym);
546

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
663
    @Override
664
    public CheckBox getBasionymToggle() {
665
        return basionymToggle;
666
    }
667

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

    
685

    
686

    
687

    
688
}
(10-10/13)