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
|
/**
|
33
|
* {@inheritDoc}
|
34
|
*/
|
35
|
@Override
|
36
|
public void validate(Object value) throws InvalidValueException {
|
37
|
if(value != null){
|
38
|
NameRelationshipDTO nameRel = (NameRelationshipDTO)value;
|
39
|
if(nameRel.getOtherName() != null){
|
40
|
if(nameRel.getOtherName().getNomenclaturalReference() == null){
|
41
|
throw new InvalidValueException("The nomenclatural reference of the corrected name must not be null.");
|
42
|
} else {
|
43
|
if(!nameRel.getOtherName().getNomenclaturalReference().equals(nomenclaturalReferenceField.getValue())){
|
44
|
throw new InvalidValueException("The nomenclatural references of the corrected name and of the correcting name must be equal.");
|
45
|
}
|
46
|
}
|
47
|
}
|
48
|
}
|
49
|
|
50
|
}
|
51
|
|
52
|
}
|