Project

General

Profile

Download (3.37 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
     * With defaults for matchMode = MatchMode.ANYWHERE and orderHints = OrderHint.ORDER_BY_TITLE_CACHE
69
     *
70
     * @param service
71
     */
72
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service) {
73
        super();
74
        this.service = service;
75
    }
76

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

    
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public List<T> findEntities(int firstRow, String filter) {
94

    
95
        Pager<T> page = service.findByTitle(
96
                null,
97
                filter,
98
                matchMode,
99
                null,
100
                pageSize,
101
                firstRow,
102
                orderHints,
103
                Arrays.asList("$")
104
              );
105
        return page.getRecords();
106
    }
107

    
108
    /**
109
     * {@inheritDoc}
110
     */
111
    @Override
112
    public int size(String filter) {
113

    
114
        Pager<T> page = service.findByTitle(
115
                null,
116
                filter,
117
                matchMode,
118
                null,
119
                1,
120
                0,
121
                null,
122
                null
123
              );
124
        return page.getCount().intValue();
125
    }
126

    
127
    /**
128
     * @return the pageSize
129
     */
130
    public int getPageSize() {
131
        return pageSize;
132
    }
133

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

    
141
}
(1-1/7)