2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.data
.validator
;
11 import java
.util
.Objects
;
14 import com
.vaadin
.data
.Validator
;
15 import com
.vaadin
.ui
.AbstractSelect
;
17 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
21 * @author a.kohlbecker
25 public class InReferenceTypeValidator
implements Validator
{
28 private static final long serialVersionUID
= 5704902636623629859L;
29 private AbstractSelect referenceTypeSelect
;
31 public InReferenceTypeValidator(AbstractSelect referenceTypeSelect
){
32 this.referenceTypeSelect
= referenceTypeSelect
;
39 public void validate(Object value
) throws InvalidValueException
{
40 ReferenceType type
= (ReferenceType
)referenceTypeSelect
.getValue();
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]") );