Project

General

Profile

Download (3.27 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.service;
10

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

    
14
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
15
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
16

    
17
import eu.etaxonomy.cdm.api.service.IIdentifiableEntityService;
18
import eu.etaxonomy.cdm.api.service.pager.Pager;
19
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
20
import eu.etaxonomy.cdm.persistence.query.MatchMode;
21
import eu.etaxonomy.cdm.persistence.query.OrderHint;
22

    
23
/**
24
 * @author a.kohlbecker
25
 * @since Jun 7, 2017
26
 *
27
 */
28
public class CdmFilterablePagingProvider<T extends IdentifiableEntity> implements FilterablePagingProvider<T>, FilterableCountProvider {
29

    
30
    private int pageSize = 20;
31

    
32
    private IIdentifiableEntityService<T> service;
33

    
34
    private MatchMode matchMode = MatchMode.ANYWHERE;
35

    
36
    private List<OrderHint> orderHints = OrderHint.ORDER_BY_TITLE_CACHE.asList();
37

    
38

    
39
    /**
40
     * @return the matchMode
41
     */
42
    protected MatchMode getMatchMode() {
43
        return matchMode;
44
    }
45

    
46
    /**
47
     * @param matchMode the matchMode to set
48
     */
49
    protected void setMatchMode(MatchMode matchMode) {
50
        this.matchMode = matchMode;
51
    }
52

    
53
    /**
54
     * @return the orderHints
55
     */
56
    protected List<OrderHint> getOrderHints() {
57
        return orderHints;
58
    }
59

    
60
    /**
61
     * @param orderHints the orderHints to set
62
     */
63
    protected void setOrderHints(List<OrderHint> orderHints) {
64
        this.orderHints = orderHints;
65
    }
66

    
67
    /**
68
     * @param service
69
     */
70
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service) {
71
        super();
72
        this.service = service;
73
    }
74

    
75
    /**
76
     * @param service
77
     * @param matchMode
78
     * @param orderHints
79
     */
80
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode,
81
            List<OrderHint> orderHints) {
82
        super();
83
        this.service = service;
84
        this.matchMode = matchMode;
85
        this.orderHints = orderHints;
86
    }
87

    
88
    /**
89
     * {@inheritDoc}
90
     */
91
    @Override
92
    public List<T> findEntities(int firstRow, String filter) {
93
        Pager<T> page = service.findByTitle(
94
                null,
95
                filter,
96
                matchMode,
97
                null,
98
                pageSize,
99
                firstRow,
100
                orderHints,
101
                Arrays.asList("$")
102
              );
103
        return page.getRecords();
104
    }
105

    
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public int size(String filter) {
111
        Pager<T> page = service.findByTitle(
112
                null,
113
                filter,
114
                matchMode,
115
                null,
116
                1,
117
                0,
118
                null,
119
                null
120
              );
121
        return page.getCount().intValue();
122
    }
123

    
124
    /**
125
     * @return the pageSize
126
     */
127
    public int getPageSize() {
128
        return pageSize;
129
    }
130

    
131
    /**
132
     * @param pageSize the pageSize to set
133
     */
134
    public void setPageSize(int pageSize) {
135
        this.pageSize = pageSize;
136
    }
137

    
138
}
(1-1/4)