Project

General

Profile

Download (1.53 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.data.validator;
10

    
11
import java.util.Objects;
12
import java.util.Set;
13

    
14
import com.vaadin.data.Validator;
15
import com.vaadin.ui.AbstractSelect;
16

    
17
import eu.etaxonomy.cdm.model.reference.Reference;
18
import eu.etaxonomy.cdm.model.reference.ReferenceType;
19

    
20
/**
21
 * @author a.kohlbecker
22
 * @since Dec 20, 2018
23
 *
24
 */
25
public class InReferenceTypeValidator implements Validator {
26

    
27

    
28
    private static final long serialVersionUID = 5704902636623629859L;
29
    private AbstractSelect referenceTypeSelect;
30

    
31
    public InReferenceTypeValidator(AbstractSelect referenceTypeSelect){
32
        this.referenceTypeSelect = referenceTypeSelect;
33
    }
34

    
35
    /**
36
     * {@inheritDoc}
37
     */
38
    @Override
39
    public void validate(Object value) throws InvalidValueException {
40
        ReferenceType type = (ReferenceType)referenceTypeSelect.getValue();
41
        if(value != null){
42
            Set<ReferenceType> applicableInRefTypes = type.inReferenceContraints(type);
43
            Reference inReference = (Reference)value;
44
            if(!applicableInRefTypes.contains(inReference.getType())){
45
                throw new InvalidValueException(Objects.toString(inReference.getType(), "[NULL]") + " is not a suitable in-reference type for " + Objects.toString(type, "[NULL]") );
46
            }
47
        }
48

    
49
    }
50

    
51
}
    (1-1/1)