Project

General

Profile

Download (2.05 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.component;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.List;
14

    
15
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.beans.factory.annotation.Qualifier;
17

    
18
import com.vaadin.data.util.BeanItemContainer;
19
import com.vaadin.spring.annotation.SpringComponent;
20
import com.vaadin.ui.ListSelect;
21

    
22
import eu.etaxonomy.cdm.api.application.CdmRepository;
23
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
24
import eu.etaxonomy.cdm.model.common.TermType;
25
import eu.etaxonomy.cdm.persistence.query.OrderHint;
26

    
27
/**
28
 * @author a.kohlbecker
29
 * @since Apr 6, 2017
30
 *
31
 */
32
@SpringComponent
33
public class SelectFieldFactory {
34

    
35
    @Autowired
36
    @Qualifier("cdmRepository")
37
    private CdmRepository repo;
38

    
39
    private final static List<String> INIT_STRATEGY = Arrays.asList(new String[]{"$", "representations"});
40

    
41
    private static List<OrderHint> orderHints = new ArrayList<>();
42

    
43
    static {
44
        orderHints.add(OrderHint.BY_ORDER_INDEX);
45
        orderHints.add(OrderHint.ORDER_BY_TITLE_CACHE);
46
    }
47

    
48
    public ListSelect createListSelect(String caption, TermType termType){
49
        BeanItemContainer<DefinedTermBase> termItemContainer = buildBeanItemContainer(termType);
50
        ListSelect select = new ListSelect(caption, termItemContainer);
51
        return select;
52
    }
53

    
54
    /**
55
     * @param termType
56
     */
57
    private BeanItemContainer<DefinedTermBase> buildBeanItemContainer(TermType termType) {
58
        // TODO use TermCacher?
59
        List<DefinedTermBase> terms = repo.getTermService().listByTermType(termType, null, null, orderHints, INIT_STRATEGY);
60
        BeanItemContainer<DefinedTermBase> termItemContainer = new BeanItemContainer<>(DefinedTermBase.class);
61
        termItemContainer.addAll(terms);
62
        return termItemContainer;
63
    }
64

    
65
}
(5-5/6)