Project

General

Profile

Download (1.46 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.util.ArrayList;
12
import java.util.List;
13

    
14
import org.apache.commons.lang.StringUtils;
15

    
16
import eu.etaxonomy.cdm.model.term.EnumeratedTermVoc;
17
import eu.etaxonomy.cdm.model.term.IEnumTerm;
18

    
19
/**
20
 * This PropertyEditor translates concatenated lists string identifiers into
21
 * {@link eu.etaxonomy.cdm.model.term.IEnumTerm} instances. The instances can be identified by the value of the
22
 * {@link eu.etaxonomy.cdm.model.term.IKeyTerm#getKey() key} property. The separator for concatenations is the colon: ','
23
 *
24
 * @author a.kohlbecker
25
 * @since Jun 25, 2013
26
 *
27
 */
28
public class EnumTermListPropertyEditor<T extends IEnumTerm<T>> extends EnumTermPropertyEditor<T> {
29

    
30
    public EnumTermListPropertyEditor(EnumeratedTermVoc<T> delegateVoc){
31
        super(delegateVoc);
32
    }
33

    
34
    @Override
35
    public void setAsText(String text) {
36

    
37
        List<T> termList = null;
38

    
39
        String[] tokens = StringUtils.split(text, ',');
40
        if(tokens != null && tokens.length > 0){
41
            termList = new ArrayList<>(tokens.length);
42
            for(String key : tokens){
43
                termList.add(super.textToTerm(key));
44
            }
45
        }
46
        setValue(termList);
47
    }
48

    
49
}
(2-2/4)