Project

General

Profile

Download (1.45 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2013 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.remote.editor.term;
10

    
11
import java.beans.PropertyEditorSupport;
12

    
13
import eu.etaxonomy.cdm.model.term.EnumeratedTermVoc;
14
import eu.etaxonomy.cdm.model.term.IEnumTerm;
15

    
16
/**
17
 * This PropertyEditor translates a single string into a {@link eu.etaxonomy.cdm.model.term.IEnumTerm} instance.
18
 * The instance can be identified by the value of the
19
 * {@link eu.etaxonomy.cdm.model.term.IKeyTerm#getKey() key} property.
20
 *
21
 * @author a.kohlbecker
22
 * @since Jun 25, 2013
23
 *
24
 */
25
public class EnumTermPropertyEditor<T extends IEnumTerm<T>> extends PropertyEditorSupport {
26

    
27
    protected final EnumeratedTermVoc<T> delegateVoc;
28

    
29
    public EnumTermPropertyEditor(EnumeratedTermVoc<T> delegateVoc){
30
        super();
31
        this.delegateVoc = delegateVoc;
32
    }
33

    
34
    @Override
35
    public void setAsText(String text) {
36
        setValue(textToTerm(text));
37
    }
38

    
39
    /**
40
     * @param text
41
     * @return
42
     */
43
    protected T textToTerm(String text) {
44
        T term = delegateVoc.getByKey(text);
45
        if(term == null){
46
            throw new java.lang.IllegalArgumentException("No EnumTerm instance in " + delegateVoc.toString() + " found for the key: " + text);
47
        }
48
        return term;
49
    }
50
}
(3-3/4)