Project

General

Profile

Revision 904cd1c0

ID904cd1c055d27a017e259ef2a499394c639d32b2
Parent b343468a
Child 18fbda82

Added by Andreas Kohlbecker over 1 year ago

ref #7364 validation section implemented in TaxonNameEditor

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/model/name/NameRelationshipDTO.java
1
/**
2
* Copyright (C) 2018 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.model.name;
10

  
11
import java.io.Serializable;
12

  
13
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
14
import eu.etaxonomy.cdm.model.name.NameRelationship;
15
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
16
import eu.etaxonomy.cdm.model.name.TaxonName;
17
import eu.etaxonomy.cdm.model.reference.Reference;
18

  
19
/**
20
 * @author a.kohlbecker
21
 * @since May 3, 2018
22
 *
23
 */
24
public class NameRelationshipDTO implements Serializable {
25

  
26
    private static final long serialVersionUID = 966322755160849163L;
27

  
28
    NameRelationship nameRel;
29

  
30
    TaxonName otherName;
31
    NameRelationshipType type;
32
    Direction direction;
33
    Reference citation;
34
    String citationMicroReference;
35
    String ruleConsidered;
36

  
37
    /**
38
     * @param entity
39
     */
40
    public NameRelationshipDTO(Direction direction, NameRelationshipType type) {
41
        this.direction = direction;
42
        this.type = type;
43
    }
44

  
45
    public NameRelationshipDTO(Direction direction, NameRelationship nameRel) {
46
        this.direction = direction;
47
        otherName = otherNameFrom(nameRel);
48
        type = nameRel.getType();
49
        citation = nameRel.getCitation();
50
        citationMicroReference = nameRel.getCitationMicroReference();
51
        ruleConsidered = nameRel.getRuleConsidered();
52
    }
53

  
54
    /**
55
     * @return
56
     */
57
    protected TaxonName otherNameFrom(NameRelationship nameRel) {
58
        return this.direction.equals(Direction.relatedTo) ?  nameRel.getFromName() : nameRel.getToName();
59
    }
60

  
61
    protected TaxonName thisNameFrom(NameRelationship nameRel) {
62
        return this.direction.equals(Direction.relatedTo) ?  nameRel.getToName() : nameRel.getFromName();
63
    }
64

  
65
    /**
66
     * @return the otherName
67
     */
68
    public TaxonName getOtherName() {
69
        return otherName;
70
    }
71

  
72
    /**
73
     * @param otherName the otherName to set
74
     */
75
    public void setOtherName(TaxonName otherName) {
76
        this.otherName = otherName;
77
    }
78

  
79
    /**
80
     * @return the type
81
     */
82
    public NameRelationshipType getType() {
83
        return type;
84
    }
85

  
86
    /**
87
     * @param type the type to set
88
     */
89
    public void setType(NameRelationshipType type) {
90
        this.type = type;
91
    }
92

  
93
    /**
94
     * @return the direction
95
     */
96
    public Direction getDirection() {
97
        return direction;
98
    }
99

  
100
    /**
101
     * @param direction the direction to set
102
     */
103
    public void setDirection(Direction direction) {
104
        this.direction = direction;
105
    }
106

  
107
    /**
108
     * @return the citation
109
     */
110
    public Reference getCitation() {
111
        return citation;
112
    }
113

  
114
    /**
115
     * @param citation the citation to set
116
     */
117
    public void setCitation(Reference citation) {
118
        this.citation = citation;
119
    }
120

  
121
    /**
122
     * @return the citationMicroReference
123
     */
124
    public String getCitationMicroReference() {
125
        return citationMicroReference;
126
    }
127

  
128
    /**
129
     * @param citationMicroReference the citationMicroReference to set
130
     */
131
    public void setCitationMicroReference(String citationMicroReference) {
132
        this.citationMicroReference = citationMicroReference;
133
    }
134

  
135
    /**
136
     * @return the ruleConsidered
137
     */
138
    public String getRuleConsidered() {
139
        return ruleConsidered;
140
    }
141

  
142
    /**
143
     * @param ruleConsidered the ruleConsidered to set
144
     */
145
    public void setRuleConsidered(String ruleConsidered) {
146
        this.ruleConsidered = ruleConsidered;
147
    }
148

  
149

  
150

  
151
}
src/main/java/eu/etaxonomy/cdm/vaadin/model/name/TaxonNameDTO.java
11 11
import java.util.HashSet;
12 12
import java.util.List;
13 13
import java.util.Set;
14
import java.util.stream.Collectors;
14 15

  
15 16
import org.joda.time.DateTime;
16 17

  
......
22 23
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
23 24
import eu.etaxonomy.cdm.model.common.User;
24 25
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
26
import eu.etaxonomy.cdm.model.name.NameRelationship;
25 27
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
26 28
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
27 29
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
......
37 39
 */
38 40
public class TaxonNameDTO extends CdmEntityDecoraterDTO<TaxonName> {
39 41

  
40
    class TN extends TaxonName {
41

  
42
    }
43

  
44 42
    private static final long serialVersionUID = -8018109905949198530L;
45 43

  
46 44
    private TaxonName name;
......
49 47

  
50 48
    private Set<TaxonName> persistedReplacedSynonyms;
51 49

  
50
    private TaxonName persistedValidatedName;
51

  
52 52
    /**
53 53
     * @param entity
54 54
     */
......
96 96
        return replacedSynonyms;
97 97
    }
98 98

  
99
    public NameRelationshipDTO getValidationFor() {
100
        NameRelationshipDTO nameRelDto  = null;
101
        NameRelationship validatingRelationship = validatingRelationship();
102
        if(validatingRelationship != null){
103
            nameRelDto = new NameRelationshipDTO(Direction.relatedTo, validatingRelationship);
104
            if(persistedValidatedName == null){
105
               persistedValidatedName = nameRelDto.getOtherName();
106
            }
107
        }
108
        return nameRelDto;
109
    }
110

  
111
    /**
112
     * @return
113
     */
114
    protected NameRelationship validatingRelationship() {
115
        Set<NameRelationship> toRelations = name.getRelationsToThisName();
116
        Set<NameRelationship> validatedNameRelations = toRelations.stream().filter(
117
                    nr -> nr.getType().equals(NameRelationshipType.VALIDATED_BY_NAME())
118
                ).collect(Collectors.toSet());
119
        if(validatedNameRelations.size() > 1){
120
            // TODO use non RuntimeException
121
            throw new RuntimeException("More than one validated name found.");
122
        } else if(validatedNameRelations.size() == 0) {
123
            return null;
124
        }
125
        return validatedNameRelations.iterator().next();
126
    }
127

  
128
    public void setValidationFor(NameRelationshipDTO nameRelDto) {
129

  
130
        if(nameRelDto != null && nameRelDto.getOtherName() == null){
131
            // treat as if there is no validation
132
            nameRelDto = null;
133
        }
134

  
135
        NameRelationship validatingRelationship = validatingRelationship();
136

  
137
        if(nameRelDto != null){
138
            // add or update ...
139
            if(validatingRelationship != null && persistedValidatedName != null && validatingRelationship.getFromName().equals(persistedValidatedName)){
140
                // validated name has not changed, so we can update the relation
141
                validatingRelationship.setCitation(nameRelDto.getCitation());
142
                validatingRelationship.setCitationMicroReference(nameRelDto.getCitationMicroReference());
143
                validatingRelationship.setRuleConsidered(nameRelDto.getRuleConsidered());
144
            } else {
145
                // need to remove the old relationship and to create a new one.
146
                // the actual removal will take place ....
147
                name.addRelationshipFromName(nameRelDto.getOtherName(), NameRelationshipType.VALIDATED_BY_NAME(),
148
                        nameRelDto.getCitation(), nameRelDto.getCitationMicroReference(), nameRelDto.getRuleConsidered());
149
                if(persistedValidatedName != null){
150
                    name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
151
                }
152
            }
153
        } else {
154
            // remove ...
155
            if(persistedValidatedName != null && validatingRelationship != null){
156
                name.removeRelationWithTaxonName(persistedValidatedName, Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
157
            }
158
        }
159
    }
160

  
99 161
    public void setBasionyms(Set<TaxonName> basionyms) {
100 162
        setRelatedNames(Direction.relatedTo, NameRelationshipType.BASIONYM(), basionyms);
101 163
    }
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNameEditorPresenter.java
130 130
        getView().getReplacedSynonymsComboboxSelect().setCaptionGenerator( new CdmTitleCacheCaptionGenerator<TaxonName>());
131 131
        // reusing the basionymPagingProvider for the replaced synonyms to benefit from caching
132 132
        getView().getReplacedSynonymsComboboxSelect().setPagingProviders(basionymPagingProvider, basionymPagingProvider, basionymPagingProvider.getPageSize(), this);
133

  
134
        getView().getValidationField().getValidatedNameComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<TaxonName>());
135
        // reusing the basionymPagingProvider for the replaced synonyms to benefit from caching
136
        getView().getValidationField().getValidatedNameComboBox().loadFrom(basionymPagingProvider, basionymPagingProvider, basionymPagingProvider.getPageSize());
137
        getView().getValidationField().getValidatedNameComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getValidatedNameComboBox(), this));
138

  
139

  
140
        getView().getValidationField().getCitatonComboBox().getSelect().setCaptionGenerator(new CdmTitleCacheCaptionGenerator<Reference>());
141
        getView().getValidationField().getCitatonComboBox().loadFrom(referencePagingProvider, referencePagingProvider, referencePagingProvider.getPageSize());
142
        getView().getValidationField().getCitatonComboBox().getSelect().addValueChangeListener(new ToOneRelatedEntityReloader<>(getView().getValidationField().getCitatonComboBox(), this));
143

  
133 144
    }
134 145

  
135 146
    /**
......
331 342
        if(getView() == null || event.getSourceView() != getView() ){
332 343
            return;
333 344
        }
345
        ReloadableLazyComboBox<TaxonName> sourceField = (ReloadableLazyComboBox<TaxonName>)event.getSourceComponent();
334 346

  
335
        basionymSourceField = (ReloadableLazyComboBox<TaxonName>)event.getSourceComponent();
347
        if(sourceField == getView().getValidationField().getValidatedNameComboBox().getSelect()){
348
            // validatedNameSourceField .. this is awkward, better use a map to correlate fields to popup editors!!!!
336 349

  
337
        basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
338
        basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
339
        basionymNamePopup.withDeleteButton(true);
340
        getView().getModesActive().stream()
341
                .filter(
342
                        m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
343
                .forEach(m -> basionymNamePopup.enableMode(m));
344
        basionymNamePopup.loadInEditor(event.getEntityUuid());
345
        basionymNamePopup.getBasionymToggle().setVisible(false);
350
        } else {
351
            basionymSourceField = sourceField;
352

  
353
            basionymNamePopup = getNavigationManager().showInPopup(TaxonNamePopupEditor.class, getView());
354
            basionymNamePopup.grantToCurrentUser(EnumSet.of(CRUD.UPDATE, CRUD.DELETE));
355
            basionymNamePopup.withDeleteButton(true);
356
            getView().getModesActive().stream()
357
                    .filter(
358
                            m -> !TaxonNamePopupEditorMode.NOMENCLATURALREFERENCE_SECTION_EDITING_ONLY.equals(m))
359
                    .forEach(m -> basionymNamePopup.enableMode(m));
360
            basionymNamePopup.loadInEditor(event.getEntityUuid());
361
            basionymNamePopup.getBasionymToggle().setVisible(false);
362
        }
346 363

  
347 364
    }
348 365

  
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditor.java
34 34

  
35 35
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
36 36
import eu.etaxonomy.cdm.model.common.CdmBase;
37
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
38
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
37 39
import eu.etaxonomy.cdm.model.name.Rank;
38 40
import eu.etaxonomy.cdm.model.name.TaxonName;
39 41
import eu.etaxonomy.cdm.model.reference.Reference;
40 42
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
41 43
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
42 44
import eu.etaxonomy.cdm.vaadin.event.TaxonNameEditorAction;
45
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
43 46
import eu.etaxonomy.cdm.vaadin.model.name.TaxonNameDTO;
44 47
import eu.etaxonomy.cdm.vaadin.permission.AccessRestrictedView;
45 48
import eu.etaxonomy.cdm.vaadin.permission.CdmEditDeletePermissionTester;
46 49
import eu.etaxonomy.cdm.vaadin.util.TeamOrPersonBaseCaptionGenerator;
47 50
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
51
import eu.etaxonomy.vaadin.component.NameRelationField;
48 52
import eu.etaxonomy.vaadin.component.ReloadableLazyComboBox;
49 53
import eu.etaxonomy.vaadin.component.SwitchableTextField;
50 54
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
......
65 69

  
66 70
    private final static int GRID_COLS = 4;
67 71

  
68
    private final static int GRID_ROWS = 15;
72
    private final static int GRID_ROWS = 16;
69 73

  
70 74
    private static final boolean HAS_BASIONYM_DEFAULT = false;
71 75

  
......
93 97

  
94 98
    private ToManyRelatedEntitiesComboboxSelect<TaxonName> replacedSynonymsComboboxSelect;
95 99

  
100
    private NameRelationField validationField;
101

  
96 102
    private CheckBox basionymToggle;
97 103

  
98 104
    private CheckBox replacedSynonymsToggle;
......
115 121

  
116 122
    private Map<AbstractField, Property.ValueChangeListener> authorshipUpdateListeners = new HashMap<>();
117 123

  
124
    private Boolean isInferredExCombinationAuthorship;
125

  
118 126
    /**
119 127
     * @param layout
120 128
     * @param dtoType
......
236 244

  
237 245
        basionymToggle = new CheckBox("With basionym");
238 246
        basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
247
        basionymToggle.addValueChangeListener(e -> {
248
            updateAuthorshipFields();
249
        });
239 250

  
240 251
        basionymToggle.setStyleName(getDefaultComponentStyles());
241 252
        grid.addComponent(basionymToggle, 2, row, 3, row);
......
253 264
        row++;
254 265
        validationToggle = new CheckBox("Validation");
255 266
        validationToggle.addValueChangeListener(e -> {
256
                boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
257
                exCombinationAuthorshipField.setVisible(enable);
267
            updateAuthorshipFields();
258 268
            });
259 269
        grid.addComponent(validationToggle, 2, row, 3, row);
260 270
        grid.setComponentAlignment(validationToggle, Alignment.BOTTOM_LEFT);
......
310 320
        nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
311 321
        nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
312 322

  
313
        row++;
314
        exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
315
        exCombinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
316
        addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
317

  
318
        // Basionym
323
        // --------------- Basionyms
319 324
        row++;
320 325
        basionymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
321 326
        basionymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
......
345 350
        exBasionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
346 351
        addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
347 352

  
348
        // ReplacedSynonyms
353
        // --------------- ReplacedSynonyms
349 354
        row++;
350 355
        replacedSynonymsComboboxSelect = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Replaced synonyms");
351 356
        replacedSynonymsComboboxSelect.setConverter(new SetToListConverter<TaxonName>());
......
366 371
        });
367 372
        grid.setComponentAlignment(replacedSynonymsComboboxSelect, Alignment.TOP_RIGHT);
368 373

  
374
        // --------------- Validation
375
        row++;
376
        validationField = new NameRelationField("Validation", Direction.relatedTo, NameRelationshipType.VALIDATED_BY_NAME());
377
        validationField.setWidth(100, Unit.PERCENTAGE);
378
        ToOneRelatedEntityCombobox<TaxonName> validatedNameComboBox = validationField.getValidatedNameComboBox();
379
        validatedNameComboBox.addClickListenerAddEntity(e -> getViewEventBus().publish(
380
                this,
381
                new TaxonNameEditorAction(EditorActionType.ADD, null, validatedNameComboBox, this)
382
                ));
383
        validatedNameComboBox.addClickListenerAddEntity(e -> {
384
            if(validatedNameComboBox.getValue() != null){
385
                getViewEventBus().publish(this,
386
                    new TaxonNameEditorAction(
387
                            EditorActionType.EDIT,
388
                            validatedNameComboBox.getValue().getUuid(),
389
                            validatedNameComboBox,
390
                            this)
391
                );
392
            }
393
        });
394
        ToOneRelatedEntityCombobox<Reference> validationCitatonComboBox = validationField.getCitatonComboBox();
395
        validationCitatonComboBox.addClickListenerAddEntity(e -> getViewEventBus().publish(
396
                this,
397
                new ReferenceEditorAction(EditorActionType.ADD, null, validationCitatonComboBox, this)
398
                ));
399
        validationCitatonComboBox.addClickListenerAddEntity(e -> {
400
            if(validationCitatonComboBox.getValue() != null){
401
                getViewEventBus().publish(this,
402
                    new ReferenceEditorAction(
403
                            EditorActionType.EDIT,
404
                            validationCitatonComboBox.getValue().getUuid(),
405
                            validationCitatonComboBox,
406
                            this)
407
                );
408
            }
409
        });
410
        addField(validationField, "validationFor", 0, row, 3, row);
411
        grid.setComponentAlignment(validationField, Alignment.TOP_RIGHT);
412

  
413
        row++;
414
        exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)", TeamOrPersonBaseCaptionGenerator.CacheType.NOMENCLATURAL_TITLE);
415
        exCombinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
416
        addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
417

  
418
        // -----------------------------------------------------------------------------
419

  
369 420
        setAdvancedModeEnabled(true);
370 421
        registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
371 422

  
372 423
        registerAdvancedModeComponents(combinationAuthorshipField);
373 424
        registerAdvancedModeComponents(basionymAuthorshipField);
374 425
        registerAdvancedModeComponents(exBasionymAuthorshipField);
426
        registerAdvancedModeComponents(exCombinationAuthorshipField);
375 427

  
376 428
        registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
377 429
        registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
......
412 464
        return null;
413 465
    }
414 466

  
467
    protected TeamOrPersonBase inferExCombinationAuthors() {
468
        NameRelationshipDTO nameRelationDTO = validationField.getValue();
469
        if(nameRelationDTO != null && nameRelationDTO.getOtherName() != null){
470
            TaxonName validatedName = nameRelationDTO.getOtherName();
471
            if(validatedName.getCombinationAuthorship() != null) {
472
                return validatedName.getCombinationAuthorship();
473
            } else if(validatedName.getNomenclaturalReference() != null){
474
                return validatedName.getNomenclaturalReference().getAuthorship();
475
            }
476
        }
477
        return null;
478
    }
479

  
415 480
    @Override
416 481
    protected void afterItemDataSourceSet() {
417 482
        TaxonNameDTO taxonNameDTO = getBean();
......
420 485
                || taxonNameDTO.getExBasionymAuthorship() != null;
421 486
        basionymToggle.setValue(showBasionymSection);
422 487
        basionymToggle.setReadOnly(showBasionymSection);
423
        basionymToggle.addValueChangeListener(e -> {
424
            updateAuthorshipFields();
425
            updateFieldVisibility();
426
        });
427 488

  
428 489
        boolean showReplacedSynonyms = taxonNameDTO.getReplacedSynonyms().size() > 0;
429 490
        replacedSynonymsToggle.setValue(showReplacedSynonyms);
430 491
        replacedSynonymsToggle.setReadOnly(showReplacedSynonyms);
431 492
        replacedSynonymsComboboxSelect.setVisible(showReplacedSynonyms);
432 493

  
433
        boolean showExAuthors = taxonNameDTO.getExCombinationAuthorship() != null;
434
        validationToggle.setValue(showExAuthors);
435
        validationToggle.setReadOnly(showExAuthors);
436
        exCombinationAuthorshipField.setVisible(showExAuthors);
494
        boolean showValidationSection = taxonNameDTO.getValidationFor() != null || taxonNameDTO.getExCombinationAuthorship() != null;
495

  
496
        validationToggle.setValue(showValidationSection);
497
        validationToggle.setReadOnly(showValidationSection);
498
//        validationField.setVisible(showValidation);
499
//        exCombinationAuthorshipField.setVisible(showExAuthors);
437 500

  
438 501
        if(isModeEnabled(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
439 502
            updateAuthorshipFields();
......
456 519
    }
457 520

  
458 521
    /**
522
     * Updates all authorship fields if the an authorship field is empty this method attempts to infer the
523
     * authors from the related nomenclatural reference or taxon name.
524
     * <p>
525
     * Finally the {@link #updateFieldVisibility()} is invoked.
526
     *
459 527
     * @param taxonName
460 528
     */
461 529
    @Override
......
493 561

  
494 562
        }
495 563

  
564
        // ------------- Validation and ExCombinationAuthors
565
        isInferredExCombinationAuthorship = updateAuthorshipFieldData(
566
                taxonName.getExCombinationAuthorship(),
567
                inferExCombinationAuthors(),
568
                exCombinationAuthorshipField,
569
                validationField.getValidatedNameComboBox(),
570
                isInferredExCombinationAuthorship
571
                );
572

  
496 573
        updateFieldVisibility();
497 574

  
498 575
    }
......
568 645
        Rank rank = (Rank) rankSelect.getValue();
569 646

  
570 647
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
571
        Boolean withBasionym = BooleanUtils.isTrue(basionymToggle.getValue());
572
        Boolean withValidation = BooleanUtils.isTrue(validationToggle.getValue());
648
        Boolean withBasionymSection = BooleanUtils.isTrue(basionymToggle.getValue());
649
        Boolean withValidationSection = isSpeciesOrBelow && BooleanUtils.isTrue(validationToggle.getValue());
573 650

  
574 651
        specificEpithetField.setVisible(isSpeciesOrBelow);
575 652
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
576 653
        infraGenericEpithetField.setVisible(rank.isInfraGeneric());
577 654

  
578

  
579
        basionymAuthorshipField.setVisible(withBasionym != null && withBasionym);
580
        exBasionymAuthorshipField.setVisible(withBasionym);
581
        basionymsComboboxSelect.setVisible(withBasionym);
655
        basionymsComboboxSelect.setVisible(withBasionymSection);
582 656

  
583 657
        combinationAuthorshipField.setVisible(isInferredCombinationAuthorship != null && !isInferredCombinationAuthorship);
584
        if(BooleanUtils.isTrue(basionymToggle.getValue())){
585
            basionymAuthorshipField.setVisible(isInferredBasionymAuthorship != null && !isInferredBasionymAuthorship);
586
            exBasionymAuthorshipField.setVisible(isInferredExBasionymAuthorship != null && !isInferredExBasionymAuthorship);
587
        }
658
        basionymAuthorshipField.setVisible(withBasionymSection && isInferredBasionymAuthorship != null && !isInferredBasionymAuthorship);
659
        exBasionymAuthorshipField.setVisible(withBasionymSection && isInferredExBasionymAuthorship != null && !isInferredExBasionymAuthorship);
660

  
661
        validationField.setVisible(withValidationSection);
662
        exCombinationAuthorshipField.setVisible(withValidationSection && isInferredExCombinationAuthorship != null && !isInferredExCombinationAuthorship);
663

  
588 664

  
589 665
//        if(taxonName != null){
590 666
//            if(modesActive.contains(TaxonNamePopupEditorMode.AUTOFILL_AUTHORSHIP_DATA)){
......
595 671
        specificEpithetField.setVisible(isSpeciesOrBelow);
596 672
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
597 673
        genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
598
        exCombinationAuthorshipField.setVisible(isSpeciesOrBelow && withValidation);
599 674
    }
600 675

  
601 676
    @Override
......
685 760
    }
686 761

  
687 762
    @Override
763
    public NameRelationField getValidationField(){
764
        return validationField;
765
    }
766

  
767
    @Override
688 768
    public void enableMode(TaxonNamePopupEditorMode mode){
689 769
            modesActive.add(mode);
690 770
    }
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/TaxonNamePopupEditorView.java
16 16
import eu.etaxonomy.cdm.model.name.TaxonName;
17 17
import eu.etaxonomy.cdm.model.reference.Reference;
18 18
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
19
import eu.etaxonomy.vaadin.component.NameRelationField;
19 20
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
20 21
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
21 22
import eu.etaxonomy.vaadin.mvp.ApplicationView;
......
88 89
     */
89 90
    ToManyRelatedEntitiesComboboxSelect<TaxonName> getReplacedSynonymsComboboxSelect();
90 91

  
92
    /**
93
     * @return
94
     */
95
    NameRelationField getValidationField();
96

  
91 97
}
src/main/java/eu/etaxonomy/vaadin/component/NameRelationField.java
1
/**
2
* Copyright (C) 2018 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.vaadin.component;
10

  
11
import com.vaadin.data.fieldgroup.BeanFieldGroup;
12
import com.vaadin.data.fieldgroup.FieldGroup;
13
import com.vaadin.server.FontAwesome;
14
import com.vaadin.ui.Button;
15
import com.vaadin.ui.Component;
16
import com.vaadin.ui.CssLayout;
17
import com.vaadin.ui.GridLayout;
18
import com.vaadin.ui.themes.ValoTheme;
19

  
20
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
21
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
22
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix;
26
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityButtonUpdater;
27
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
28

  
29

  
30
/**
31
 * @author a.kohlbecker
32
 * @since May 3, 2018
33
 *
34
 */
35
public class NameRelationField extends CompositeCustomField<NameRelationshipDTO> {
36

  
37
    /**
38
     *
39
     */
40
    public static final String PRIMARY_STYLE = "v-name-relation-field";
41

  
42
    private static final long serialVersionUID = -7080885013120044655L;
43

  
44
    private CssLayout compositeWrapper = new CssLayout();
45

  
46
    private CssLayout toolBar= new CssLayout();
47

  
48
    private Button removeButton = new Button(FontAwesome.REMOVE);
49

  
50
    private Button newButton = new Button(FontAwesome.PLUS);
51

  
52
    private BeanFieldGroup<NameRelationshipDTO> fieldGroup = new BeanFieldGroup<>(NameRelationshipDTO.class);
53

  
54
    ToOneRelatedEntityCombobox<TaxonName> validatedNameComboBox;
55

  
56
    ToOneRelatedEntityCombobox<Reference> citatonComboBox;
57

  
58
    TextFieldNFix citationMicroReferenceField = new TextFieldNFix();
59

  
60
    TextFieldNFix ruleConsideredField = new TextFieldNFix();
61

  
62
    private Direction direction;
63

  
64
    private NameRelationshipType type;
65

  
66
    private GridLayout grid;
67

  
68

  
69
    /**
70
     * @param string
71
     */
72
    public NameRelationField(String caption, Direction direction, NameRelationshipType type) {
73
        this.direction = direction;
74
        this.type = type;
75

  
76
        setCaption(caption);
77
        setPrimaryStyleName(PRIMARY_STYLE);
78

  
79
        validatedNameComboBox = new ToOneRelatedEntityCombobox<TaxonName>("Validated name", TaxonName.class);
80
        citatonComboBox = new ToOneRelatedEntityCombobox<Reference>("Reference", Reference.class);
81
    }
82

  
83
    /**
84
     * {@inheritDoc}
85
     */
86
    @Override
87
    protected void addDefaultStyles() {
88
        // TODO Auto-generated method stub
89

  
90
    }
91

  
92
    /**
93
     * {@inheritDoc}
94
     */
95
    @Override
96
    public FieldGroup getFieldGroup() {
97
        return fieldGroup;
98
    }
99

  
100
    /**
101
     * {@inheritDoc}
102
     */
103
    @Override
104
    protected Component initContent() {
105

  
106
        newButton.addClickListener(e -> {
107
            setValue(new NameRelationshipDTO(direction, type));
108
            updateToolBarButtonStates();
109
            });
110
        removeButton.addClickListener(e -> {
111
                setValue(null);
112
                updateToolBarButtonStates();
113
            });
114
        validatedNameComboBox.getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<TaxonName>(validatedNameComboBox));
115
        citatonComboBox.getSelect().addValueChangeListener(new ToOneRelatedEntityButtonUpdater<Reference>(citatonComboBox));
116

  
117
        grid = new GridLayout(2, 3);
118

  
119
        grid.addComponent(validatedNameComboBox, 0, 0, 1, 0);
120

  
121
        validatedNameComboBox.setCaption("Validated name");
122
        citatonComboBox.setCaption("Reference");
123
        citationMicroReferenceField.setCaption("Reference detail");
124
        ruleConsideredField.setCaption("Rule considered");
125

  
126
        grid.addComponent(citatonComboBox, 0, 1, 0, 1);
127
        grid.addComponent(citationMicroReferenceField, 1, 1, 1, 1);
128
        grid.addComponent(ruleConsideredField, 0, 2, 1, 2);
129

  
130
        validatedNameComboBox.setWidth(100, Unit.PERCENTAGE);
131
        ruleConsideredField.setWidth(100, Unit.PERCENTAGE);
132
        citatonComboBox.setWidth(100, Unit.PERCENTAGE);
133

  
134

  
135
        grid.setColumnExpandRatio(0, 7);
136
        grid.setWidth(100, Unit.PERCENTAGE);
137

  
138
        toolBar.setStyleName(ValoTheme.LAYOUT_COMPONENT_GROUP + " toolbar");
139
        toolBar.addComponents(newButton, removeButton);
140

  
141
        compositeWrapper.setStyleName("margin-wrapper");
142
        compositeWrapper.addComponents(toolBar);
143

  
144
        addSizedComponents(compositeWrapper);
145
        addStyledComponents(validatedNameComboBox, citationMicroReferenceField, citatonComboBox, ruleConsideredField, newButton, removeButton);
146

  
147
        return compositeWrapper;
148
    }
149

  
150
    /**
151
     * {@inheritDoc}
152
     */
153
    @Override
154
    public Class<NameRelationshipDTO> getType() {
155
        return NameRelationshipDTO.class;
156
    }
157

  
158
    /**
159
     * {@inheritDoc}
160
     */
161
    @Override
162
    protected void setInternalValue(NameRelationshipDTO newValue) {
163

  
164
        NameRelationshipDTO oldValue = getValue();
165

  
166
        super.setInternalValue(newValue);
167

  
168

  
169
        newValue = HibernateProxyHelper.deproxy(newValue);
170
        if(newValue != null) {
171
            compositeWrapper.addComponent(grid);
172
            getFieldGroup().bind(validatedNameComboBox, "otherName");
173
            getFieldGroup().bind(citationMicroReferenceField, "citationMicroReference");
174
            getFieldGroup().bind(citatonComboBox, "citation");
175
            getFieldGroup().bind(ruleConsideredField, "ruleConsidered");
176

  
177
            fieldGroup.setItemDataSource(newValue);
178
        } else {
179
            if(oldValue != null){
180
                compositeWrapper.removeComponent(grid);
181
                getFieldGroup().unbind(validatedNameComboBox);
182
                getFieldGroup().unbind(citationMicroReferenceField);
183
                getFieldGroup().unbind(citatonComboBox);
184
                getFieldGroup().unbind(ruleConsideredField);
185

  
186
                fieldGroup.setItemDataSource(newValue);
187
            }
188
        }
189

  
190
        updateToolBarButtonStates();
191

  
192
    }
193

  
194

  
195
   private void updateToolBarButtonStates(){
196
       boolean hasValue = getValue() != null;
197
       removeButton.setEnabled(hasValue);
198
       newButton.setEnabled(!hasValue);
199
   }
200

  
201
    /**
202
     * @return the validatedNameComboBox
203
     */
204
    public ToOneRelatedEntityCombobox<TaxonName> getValidatedNameComboBox() {
205
        return validatedNameComboBox;
206
    }
207

  
208
    /**
209
     * @return the citatonComboBox
210
     */
211
    public ToOneRelatedEntityCombobox<Reference> getCitatonComboBox() {
212
        return citatonComboBox;
213
    }
214

  
215
}
src/main/java/eu/etaxonomy/vaadin/component/NameRelationsListEditor.java
1
/**
2
* Copyright (C) 2018 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.vaadin.component;
10

  
11
import org.vaadin.viritin.fields.CaptionGenerator;
12
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
13
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
14

  
15
import eu.etaxonomy.cdm.model.name.TaxonName;
16
import eu.etaxonomy.cdm.model.reference.Reference;
17
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
18
import eu.etaxonomy.cdm.vaadin.view.name.CachingPresenter;
19

  
20
/**
21
 * @author a.kohlbecker
22
 * @since May 3, 2018
23
 *
24
 */
25
public class NameRelationsListEditor extends ToManyRelatedEntitiesListSelect<NameRelationshipDTO, NameRelationField> {
26

  
27
    private static final long serialVersionUID = 6295557881702890211L;
28

  
29
    private ReloadableLazyComboBoxInstantiator<TaxonName> nameSelectInstantiator;
30

  
31
    private ReloadableLazyComboBoxInstantiator<Reference> referenceSelectInstantiator;
32

  
33
    /**
34
     * @param itemType
35
     * @param caption
36
     */
37
    public NameRelationsListEditor(String caption) {
38
        super(NameRelationshipDTO.class, null, caption);
39
        this.fieldType = NameRelationField.class;
40
        // addEmptyRowOnInitContent is false in this class since adding row is only possible after setting the PagingProviders
41
        addEmptyRowOnInitContent = false;
42
        nameSelectInstantiator = new ReloadableLazyComboBoxInstantiator<TaxonName>(TaxonName.class);
43
        referenceSelectInstantiator = new ReloadableLazyComboBoxInstantiator<Reference>(Reference.class);
44
    }
45

  
46
    /**
47
     * {@inheritDoc}
48
     */
49
//    @Override
50
//    protected NameRelationField newFieldInstance(NameRelationshipDTO val) throws InstantiationException, IllegalAccessException {
51
//
52
//        NameRelationField field = new NameRelationField(nameSelectInstantiator, referenceSelectInstantiator, val);
53
//        field.setWidth(100, Unit.PERCENTAGE);
54
//        return field;
55
//    }
56

  
57
    public void setTaxonNamePagingProviders(FilterablePagingProvider<TaxonName> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength,
58
            CachingPresenter cachingPresenter){
59
        nameSelectInstantiator.setPagingProviders(filterablePagingProvider, filterableCountProvider, pageLength, cachingPresenter);
60
        setInternalValue(null);
61
    }
62

  
63
    /**
64
     * @param cdmTitleCacheCaptionGenerator
65
     */
66
    public void setTaxonNameCaptionGenerator(CaptionGenerator<TaxonName> captionGenerator) {
67
        nameSelectInstantiator.setCaptionGenerator(captionGenerator);
68
    }
69

  
70
    public void setReferencePagingProviders(FilterablePagingProvider<Reference> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength,
71
            CachingPresenter cachingPresenter){
72
        referenceSelectInstantiator.setPagingProviders(filterablePagingProvider, filterableCountProvider, pageLength, cachingPresenter);
73
        setInternalValue(null);
74
    }
75

  
76
    /**
77
     * @param cdmTitleCacheCaptionGenerator
78
     */
79
    public void setReferenceCaptionGenerator(CaptionGenerator<Reference> captionGenerator) {
80
        referenceSelectInstantiator.setCaptionGenerator(captionGenerator);
81
    }
82

  
83

  
84
}
src/main/java/eu/etaxonomy/vaadin/component/ReloadableLazyComboBoxInstantiator.java
1
/**
2
* Copyright (C) 2018 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.vaadin.component;
10

  
11
import org.vaadin.viritin.fields.CaptionGenerator;
12
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
13
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
14

  
15
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
16
import eu.etaxonomy.cdm.vaadin.view.name.CachingPresenter;
17

  
18
/**
19
 * @author a.kohlbecker
20
 * @since May 3, 2018
21
 *
22
 */
23
public class ReloadableLazyComboBoxInstantiator<V extends Object> {
24

  
25
    private FilterablePagingProvider<V> filterablePagingProvider = null;
26
    private FilterableCountProvider filterableCountProvider = null;
27
    private Integer pageLength = null;
28

  
29
    private CaptionGenerator<V> captionGenerator;
30

  
31
    private CachingPresenter cachingPresenter;
32
    private Class<V> itemType;
33

  
34
    public ReloadableLazyComboBoxInstantiator(Class<V> itemType){
35
        this.itemType = itemType;
36
    }
37

  
38
    /**
39
     * {@inheritDoc}
40
     */
41
    protected ReloadableLazyComboBox<V> newInstance(V val) throws InstantiationException, IllegalAccessException {
42

  
43

  
44
        ReloadableLazyComboBox<V> field = new ReloadableLazyComboBox<V>(itemType);
45
        // FIXME using the ToOneRelatedEntityReloader created a dependency to the cdm packages, this should be relaxed!!!
46
        field.addValueChangeListener(new ToOneRelatedEntityReloader(field, cachingPresenter));
47

  
48
        if(filterablePagingProvider == null || filterableCountProvider == null ||  pageLength == null) {
49
            throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
50
        }
51
        field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
52
        if(captionGenerator != null){
53
            field.setCaptionGenerator(captionGenerator);
54
        }
55
        field.setValue(val);
56
        return field;
57
    }
58

  
59
    public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength,
60
            CachingPresenter cachingPresenter){
61
        this.filterablePagingProvider = filterablePagingProvider;
62
        this.filterableCountProvider = filterableCountProvider;
63
        this.pageLength = pageLength;
64
        this.cachingPresenter = cachingPresenter;
65
    }
66

  
67
    /**
68
     * @param cdmTitleCacheCaptionGenerator
69
     */
70
    public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
71
        this.captionGenerator = captionGenerator;
72
    }
73

  
74

  
75

  
76
}
src/main/java/eu/etaxonomy/vaadin/component/ToManyRelatedEntitiesComboboxSelect.java
13 13
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
14 14
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
15 15

  
16
import eu.etaxonomy.cdm.vaadin.event.ToOneRelatedEntityReloader;
17 16
import eu.etaxonomy.cdm.vaadin.view.name.CachingPresenter;
18 17

  
19 18
/**
......
27 26

  
28 27
    private static final long serialVersionUID = -4496067980953939548L;
29 28

  
30
    private FilterablePagingProvider<V> filterablePagingProvider = null;
31
    private FilterableCountProvider filterableCountProvider = null;
32
    private Integer pageLength = null;
33

  
34
    private CaptionGenerator<V> captionGenerator;
35

  
36
    private CachingPresenter cachingPresenter;
29
    private ReloadableLazyComboBoxInstantiator<V> fieldInstantiator;
37 30

  
38 31
    /**
39 32
     * @param itemType
......
47 40
        this.fieldType = (Class<ReloadableLazyComboBox<V>>) field.getClass();
48 41
        // addEmptyRowOnInitContent is false in this class since adding row is only possible after setting the PagingProviders
49 42
        addEmptyRowOnInitContent = false;
43
        fieldInstantiator = new ReloadableLazyComboBoxInstantiator<V>(itemType);
50 44
    }
51 45

  
52 46
    /**
......
56 50
    protected ReloadableLazyComboBox<V> newFieldInstance(V val) throws InstantiationException, IllegalAccessException {
57 51

  
58 52
        // TODO use the setEntityFieldInstantiator(EntityFieldInstantiator) instead to inject as instantiator?
59
        ReloadableLazyComboBox<V> field = new ReloadableLazyComboBox<V>(itemType);
60
        // FIXME using the ToOneRelatedEntityReloader created a dependency to the cdm packages, this should be relaxed!!!
61
        field.addValueChangeListener(new ToOneRelatedEntityReloader(field, cachingPresenter));
62

  
63
        if(filterablePagingProvider == null || filterableCountProvider == null ||  pageLength == null) {
64
            throw new RuntimeException("The filterablePagingProvider, filterableCountProvider and pageLength must be set, use setPagingProviders().");
65
        }
66
        field.loadFrom(filterablePagingProvider, filterableCountProvider, pageLength);
67
        if(captionGenerator != null){
68
            field.setCaptionGenerator(captionGenerator);
69
        }
70
        field.setValue(val);
53
        ReloadableLazyComboBox<V> field = fieldInstantiator.newInstance(val);
71 54
        field.setWidth(100, Unit.PERCENTAGE);
72 55
        return field;
73 56
    }
74 57

  
75 58
    public void setPagingProviders(FilterablePagingProvider<V> filterablePagingProvider, FilterableCountProvider filterableCountProvider, int pageLength,
76 59
            CachingPresenter cachingPresenter){
77
        this.filterablePagingProvider = filterablePagingProvider;
78
        this.filterableCountProvider = filterableCountProvider;
79
        this.pageLength = pageLength;
80
        this.cachingPresenter = cachingPresenter;
60
        fieldInstantiator.setPagingProviders(filterablePagingProvider, filterableCountProvider, pageLength, cachingPresenter);
81 61
        setInternalValue(null);
82 62
    }
83 63

  
......
85 65
     * @param cdmTitleCacheCaptionGenerator
86 66
     */
87 67
    public void setCaptionGenerator(CaptionGenerator<V> captionGenerator) {
88
        this.captionGenerator = captionGenerator;
68
        fieldInstantiator.setCaptionGenerator(captionGenerator);
89 69
    }
90 70

  
91 71
}
src/main/webapp/VAADIN/themes/edit-valo/custom-fields.scss
95 95
    }
96 96
  }
97 97
  
98
  // ------------ NameRelationField ------------ //
99
  .v-name-relation-field {
100
      .toolbar {
101
            float: right;
102
            height: $v-unit-size;
103
      }
104
      .margin-wrapper {
105
          @include composite-field-wrapper;
106
      }
107
  }
108
  
98 109
  // ------------ v-person-field ------------ //
99 110
  .v-person-field {
100 111
    position: relative;

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)