Project

General

Profile

Download (1.7 KB) Statistics
| Branch: | Tag: | Revision:
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.view.name;
10

    
11
import com.vaadin.data.Validator;
12
import com.vaadin.ui.Field;
13

    
14
import eu.etaxonomy.cdm.model.reference.Reference;
15
import eu.etaxonomy.cdm.vaadin.model.name.NameRelationshipDTO;
16

    
17
/**
18
 * @author a.kohlbecker
19
 * @since Dec 10, 2018
20
 *
21
 */
22
public class OrthographicCorrectionReferenceValidator implements Validator {
23

    
24
    private static final long serialVersionUID = 8489749130640936863L;
25

    
26
    private Field<Reference> nomenclaturalReferenceField;
27

    
28
    public OrthographicCorrectionReferenceValidator(Field<Reference> nomenclaturalReferenceField){
29
        this.nomenclaturalReferenceField = nomenclaturalReferenceField;
30
    }
31

    
32
    @Override
33
    public void validate(Object value) throws InvalidValueException {
34
        if(value != null){
35
            NameRelationshipDTO nameRel = (NameRelationshipDTO)value;
36
            if(nameRel.getOtherName() != null){
37
                if(nameRel.getOtherName().getNomenclaturalReference() == null){
38
                    throw new InvalidValueException("The nomenclatural reference of the corrected name must not be null.");
39
                } else {
40
                    if(!nameRel.getOtherName().getNomenclaturalReference().equals(nomenclaturalReferenceField.getValue())){
41
                        throw new InvalidValueException("The nomenclatural references of the corrected name and of the correcting name must be equal.");
42
                    }
43
                }
44
            }
45
        }
46

    
47
    }
48

    
49
}
(8-8/18)