Project

General

Profile

Revision e90e4ec3

IDe90e4ec3d22b5e30ca2d422c31f052b79ec9fc36
Parent c92b53a5
Child 810e8605

Added by Andreas Kohlbecker over 2 years ago

ref #7344 new TaxonNameEditor mode to allow autofilling of name authorship fields

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
64 64
    /**
65 65
     *
66 66
     */
67
    private static final List<String> BASIONYM_INIT_STRATEGY = Arrays.asList("$", "relationsFromThisName", "relationsToThisName.type", "homotypicalGroup.typifiedNames");
67
    private static final List<String> BASIONYM_INIT_STRATEGY = Arrays.asList(
68
            "$",
69
            "relationsFromThisName",
70
            "relationsToThisName.type",
71
            "homotypicalGroup.typifiedNames"
72
            );
68 73

  
69 74
    private static final List<String> REFERENCE_INIT_STRATEGY = Arrays.asList("authorship", "inReference.authorship", "inReference.inReference.authorship", "inReference.inReference.inReference.authorship");
70 75

  
......
145 150

  
146 151
                "status.type",
147 152

  
148
                "combinationAuthorship",
149
                "exCombinationAuthorship",
150
                "basionymAuthorship",
151
                "exBasionymAuthorship",
153
                "combinationAuthorship.teamMembers",
154
                "exCombinationAuthorship.teamMembers",
155
                "basionymAuthorship.teamMembers",
156
                "exBasionymAuthorship.teamMembers",
152 157

  
153 158
                // basionyms: relationsToThisName.fromName
154 159
                "relationsToThisName.type",
155 160
                "relationsToThisName.fromName.rank",
156
                "relationsToThisName.fromName.nomenclaturalReference.authorship",
157
                "relationsToThisName.fromName.nomenclaturalReference.inReference.authorship",
158
                "relationsToThisName.fromName.nomenclaturalReference.inReference.inReference.inReference.authorship",
161
                "relationsToThisName.fromName.combinationAuthorship.teamMembers",
162
                "relationsToThisName.fromName.exCombinationAuthorship.teamMembers",
163
                "relationsToThisName.fromName.nomenclaturalReference.authorship.teamMembers",
164
                "relationsToThisName.fromName.nomenclaturalReference.inReference.authorship.teamMembers",
165
                "relationsToThisName.fromName.nomenclaturalReference.inReference.inReference.inReference.authorship.teamMembers",
159 166
                "relationsToThisName.fromName.relationsToThisName",
160 167
                "relationsToThisName.fromName.relationsFromThisName",
161 168

  
......
172 179
            taxonName = TaxonNameFactory.NewNameInstance(RegistrationUIDefaults.NOMENCLATURAL_CODE, Rank.SPECIES());
173 180
        }
174 181

  
175
        if(getView().isModeEnabled(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly)){
182
        if(getView().isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY)){
176 183
            if(taxonName.getNomenclaturalReference() != null){
177 184
                Reference nomRef = (Reference)taxonName.getNomenclaturalReference();
178 185
                //getView().getNomReferenceCombobox().setEnabled(nomRef.isOfType(ReferenceType.Section));
......
331 338
                // so re reload it using the uuid since new beans might not have an Id at this point.
332 339
                // modifiedReference = getRepo().getReferenceService().load(modifiedReference.getUuid(), Arrays.asList("inReference"));
333 340
                getView().getNomReferenceCombobox().reload(); // refreshSelectedValue(modifiedReference);
341

  
334 342
            }
335 343

  
336 344
            referenceEditorPopup = null;
......
340 348
                // TaxonName modifiedTaxonName = basionymNamePopup.getBean();
341 349
                // modifiedTaxonName = getRepo().getNameService().load(modifiedTaxonName.getUuid(), BASIONYM_INIT_STRATEGY);
342 350
                ((ReloadableSelect)basionymSourceField).reload();
351
                getView().updateAuthorshipFields();
343 352

  
344 353
            }
345 354
            if(event.getReason() == Reason.DELETE){
......
365 374
        basionymNamePopup.withDeleteButton(true);
366 375
        getView().getModesActive().stream()
367 376
                .filter(
368
                        m -> !TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly.equals(m))
377
                        m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
369 378
                .forEach(m -> basionymNamePopup.enableMode(m));
370 379
        basionymNamePopup.loadInEditor(event.getEntityId());
371 380
        basionymNamePopup.getBasionymToggle().setVisible(false);
......
386 395
        basionymNamePopup.withDeleteButton(true);
387 396
        getView().getModesActive().stream()
388 397
                .filter(
389
                        m -> !TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly.equals(m))
398
                        m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
390 399
                .forEach(m -> basionymNamePopup.enableMode(m));
391 400
        basionymNamePopup.loadInEditor(null);
392 401
        basionymNamePopup.getBasionymToggle().setVisible(false);
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
17 17

  
18 18
import com.vaadin.shared.ui.label.ContentMode;
19 19
import com.vaadin.spring.annotation.SpringComponent;
20
import com.vaadin.ui.AbstractField;
20 21
import com.vaadin.ui.Alignment;
21 22
import com.vaadin.ui.CheckBox;
22 23
import com.vaadin.ui.GridLayout;
......
24 25
import com.vaadin.ui.ListSelect;
25 26
import com.vaadin.ui.TextField;
26 27

  
28
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
27 29
import eu.etaxonomy.cdm.model.common.CdmBase;
28 30
import eu.etaxonomy.cdm.model.name.Rank;
29 31
import eu.etaxonomy.cdm.model.name.TaxonName;
......
94 96

  
95 97
    private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class);
96 98

  
99
    private Boolean isInferredCombinationAuthorship = null;
100

  
101
    private Boolean isInferredBasionymAuthorship = null;
102

  
103
    private Boolean isInferredExBasionymAuthorship = null;
104

  
97 105
    /**
98 106
     * @param layout
99 107
     * @param dtoType
......
217 225
        basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
218 226
        basionymToggle.addValueChangeListener(e -> {
219 227
                updateFieldVisibility();
228
                updateAuthorshipFields();
220 229
            });
221 230
        basionymToggle.setStyleName(getDefaultComponentStyles());
222 231
        grid.addComponent(basionymToggle, 2, row, 3, row);
......
323 332

  
324 333
        setAdvancedModeEnabled(true);
325 334
        registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
326
        registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
327
        registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
335

  
336
        registerAdvancedModeComponents(combinationAuthorshipField);
337
        registerAdvancedModeComponents(basionymAuthorshipField);
338
        registerAdvancedModeComponents(exBasionymAuthorshipField);
339

  
328 340
        registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
329 341
        registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
342
        registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
343
        registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
344

  
330 345
        setAdvancedMode(false);
331 346

  
332 347
    }
333 348

  
334
    /**
335
     * @param rank
336
     * @return
337
     */
338
    private void updateFieldVisibility() {
339

  
340
        // TODO use getField() instead and remove field references
341

  
342
        TaxonName taxonName = getBean();
343
        Rank rank = taxonName.getRank();
344

  
345
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
346
        Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue());
347
        Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue());
348

  
349
        basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
350
        exBasionymAuthorshipField.setVisible(withBasionym);
351
        basionymsComboboxSelect.setVisible(withBasionym);
352

  
353
        if(taxonName != null){
354
            if(modesActive.contains(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
355
                basionymAuthorshipField.setVisible(taxonName.getBasionymAuthorship() != null);
356
                exBasionymAuthorshipField.setVisible(taxonName.getExBasionymAuthorship() != null);
349
    protected TeamOrPersonBase inferBasiomynAuthors(TaxonName taxonName) {
350
        TaxonName basionym = taxonName.getBasionym();
351
        if(basionym != null){
352
            if(basionym.getCombinationAuthorship() != null){
353
                return basionym.getCombinationAuthorship();
354
            } else if(basionym.getNomenclaturalReference() != null){
355
                return basionym.getNomenclaturalReference().getAuthorship();
357 356
            }
358 357
        }
358
        return null;
359
    }
359 360

  
360
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
361
        specificEpithetField.setVisible(isSpeciesOrBelow);
362
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
363
        genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
364
        exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
361
    protected TeamOrPersonBase inferExBasiomynAuthors(TaxonName taxonName) {
362
        TaxonName basionym = taxonName.getBasionym();
363
        if(basionym != null){
364
                return basionym.getExCombinationAuthorship();
365
        }
366
        return null;
367
    }
368

  
369
    protected TeamOrPersonBase inferCombinationAuthors(TaxonName taxonName) {
370
        if(taxonName.getNomenclaturalReference() != null) {
371
            return taxonName.getNomenclaturalReference().getAuthorship();
372
        }
373
        return null;
365 374
    }
366 375

  
367 376
    @Override
......
378 387
        validationToggle.setReadOnly(showExAuthors);
379 388
        exCombinationAuthorshipField.setVisible(showExAuthors);
380 389

  
381
        if(isModeEnabled(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
382
            combinationAuthorshipField.setVisible(taxonName.getCombinationAuthorship() != null);
390
        if(isModeEnabled(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
391
            updateAuthorshipFields();
383 392
        }
384
        if(isModeEnabled(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly) && getBean().getNomenclaturalReference() != null) {
393
        if(isModeEnabled(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY) && getBean().getNomenclaturalReference() != null) {
385 394
            nomReferenceCombobox.setCaption("Selection limited to nomenclatural reference and sections");
386 395
        }
387
        if(isModeEnabled(TaxonNamePopupEditorMode.requireNomenclaturalReference)) {
396
        if(isModeEnabled(TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE)) {
388 397
            if(combinationAuthorshipField.getValue() == null){
389 398
                nomReferenceCombobox.setRequired(true);
390 399
            } else {
......
399 408
    }
400 409

  
401 410
    /**
411
     * @param taxonName
412
     */
413
    @Override
414
    public void updateAuthorshipFields() {
415

  
416
        TaxonName taxonName = getBean();
417

  
418
        // ------------- CombinationAuthors
419
        isInferredCombinationAuthorship = updateAuthorshipField(
420
                taxonName.getCombinationAuthorship(),
421
                inferCombinationAuthors(taxonName),
422
                combinationAuthorshipField,
423
                nomReferenceCombobox.getSelect(),
424
                isInferredCombinationAuthorship);
425

  
426

  
427
        // ------------- Basionym and ExBasionymAuthors
428
        if(BooleanUtils.isTrue(basionymToggle.getValue())){
429

  
430
            isInferredBasionymAuthorship = updateAuthorshipField(
431
                    taxonName.getBasionymAuthorship(),
432
                    inferBasiomynAuthors(taxonName),
433
                    basionymAuthorshipField,
434
                    basionymsComboboxSelect,
435
                    isInferredBasionymAuthorship
436
                    );
437

  
438
            isInferredExBasionymAuthorship = updateAuthorshipField(
439
                    taxonName.getExBasionymAuthorship(),
440
                    inferExBasiomynAuthors(taxonName),
441
                    exBasionymAuthorshipField,
442
                    //no point adding the basionymsComboboxSelect again, it has bee registered already for the BasionymAuthorship above
443
                    null,
444
                    isInferredExBasionymAuthorship
445
                    );
446
        }
447
    }
448

  
449
    /**
450
     *
451
     * @param authorship
452
     *    the value of the taxonName authorship field
453
     * @param inferredAuthors
454
     *    the value inferred from other fields which may be set as authorship to the taxon name
455
     * @param authorshipField
456
     *    the ui element to edit the taxonName authorship field
457
     * @param updateTriggerField
458
     * @param lastInferredAuthorshipState
459
     * @return
460
     */
461
    protected Boolean updateAuthorshipField(TeamOrPersonBase<?> authorship, TeamOrPersonBase inferredAuthors,
462
            TeamOrPersonField authorshipField, AbstractField updateTriggerField,
463
            Boolean lastInferredAuthorshipState) {
464

  
465
        if(authorship == null){
466
            authorshipField.setValue(inferredAuthors);
467
            lastInferredAuthorshipState = true;
468
        } else {
469
            boolean authorshipMatch = authorship == inferredAuthors;
470
            if(lastInferredAuthorshipState == null){
471
                // initialization of isInferredCombinationAuthorship in case the editor is just being initialized
472
                lastInferredAuthorshipState = authorshipMatch;
473
                if(updateTriggerField != null){
474
                    // IMPORTANT!
475
                    // this ChangeListener must be added at this very late point in the editor lifecycle so that it is called after
476
                    // the ToOneRelatedEntityReloader which may have been added to the updateTriggerField in the presenters handleViewEntered() method.
477
                    // Otherwise we risk multiple representation problems in the hibernate session
478
                    updateTriggerField.addValueChangeListener(e -> updateAuthorshipFields());
479
                }
480
            }
481
            if(!authorshipMatch && lastInferredAuthorshipState){
482
                // update the combinationAuthorshipField to follow changes of the nomenclatural reference in case it was autofilled before
483
                authorshipField.setValue(inferredAuthors);
484
                lastInferredAuthorshipState = true;
485
            }
486
        }
487
        authorshipField.setVisible(!lastInferredAuthorshipState);
488
        return lastInferredAuthorshipState;
489
    }
490

  
491
    /**
492
     * @param rank
493
     * @return
494
     */
495
    private void updateFieldVisibility() {
496

  
497
        // TODO use getField() instead and remove field references
498

  
499
        TaxonName taxonName = getBean();
500
        Rank rank = taxonName.getRank();
501

  
502
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
503
        Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue());
504
        Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue());
505

  
506
        basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
507
        exBasionymAuthorshipField.setVisible(withBasionym);
508
        basionymsComboboxSelect.setVisible(withBasionym);
509

  
510
        if(taxonName != null){
511
            if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
512
                updateAuthorshipFields();
513
            }
514
        }
515

  
516
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
517
        specificEpithetField.setVisible(isSpeciesOrBelow);
518
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
519
        genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
520
        exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
521
    }
522

  
523
    /**
402 524
     * {@inheritDoc}
403 525
     */
404 526
    @Override
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditorMode.java
19 19
     * CombinationAuthorship BasionymAuthorship fields only visible if
20 20
     * not empty
21 21
     */
22
    suppressReplacementAuthorshipData,
22
    AUTOFILL_AUTHORSHIP_DATA,
23 23

  
24 24
    /**
25 25
     * Editing of the nomenclatural reference is limited to editing the sub section of the
......
29 29
     * section can be edited via a ReferencePopupEditor.
30 30
     *
31 31
     */
32
    nomenclaturalReferenceSectionEditingOnly,
32
    NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY,
33 33

  
34 34
    /**
35 35
     * setting the nomenclatural reference is required with the exception
36 36
     * that existing data is considered complete if the combination
37 37
     * authors are set.
38 38
     */
39
    requireNomenclaturalReference
39
    REQUIRE_NOMENCLATURALREFERENCE
40 40

  
41 41
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditorView.java
10 10

  
11 11
import java.util.EnumSet;
12 12

  
13
import org.apache.commons.lang3.BooleanUtils;
14

  
13 15
import com.vaadin.ui.CheckBox;
14 16
import com.vaadin.ui.ListSelect;
15 17

  
18
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
16 19
import eu.etaxonomy.cdm.model.name.TaxonName;
17 20
import eu.etaxonomy.cdm.model.reference.Reference;
18 21
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
......
81 84
     */
82 85
    CheckBox getBasionymToggle();
83 86

  
87
    void updateAuthorshipFields();
88

  
84 89
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkingsetPresenter.java
75 75
import eu.etaxonomy.cdm.vaadin.view.name.SpecimenTypeDesignationWorkingsetPopupEditor;
76 76
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditor;
77 77
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorMode;
78
import eu.etaxonomy.cdm.vaadin.view.name.TaxonNamePopupEditorView;
78 79
import eu.etaxonomy.cdm.vaadin.view.name.TypeDesignationWorkingsetEditorIdSet;
79 80
import eu.etaxonomy.cdm.vaadin.view.reference.ReferencePopupEditor;
80 81
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
......
365 366
     *
366 367
     * @param popup
367 368
     */
368
    protected void configureTaxonNameEditor(TaxonNamePopupEditor popup) {
369
        popup.enableMode(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData);
370
        popup.enableMode(TaxonNamePopupEditorMode.nomenclaturalReferenceSectionEditingOnly);
371
        popup.enableMode(TaxonNamePopupEditorMode.requireNomenclaturalReference);
369
    protected void configureTaxonNameEditor(TaxonNamePopupEditorView popup) {
370
        popup.enableMode(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA);
371
        popup.enableMode(TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY);
372
        // popup.enableMode(TaxonNamePopupEditorMode.REQUIRE_NOMENCLATURALREFERENCE);
372 373
    }
373 374

  
374 375
    /**

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)