Project

General

Profile

Download (3.79 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
import eu.etaxonomy.cdm.vaadin.session.ConversationDirector;
23

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

    
31
    private int pageSize = 20;
32

    
33
    private IIdentifiableEntityService<T> service;
34

    
35
    private MatchMode matchMode = MatchMode.ANYWHERE;
36

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

    
39
    private ConversationDirector conversationDirector;
40

    
41

    
42
    /**
43
     * @return the matchMode
44
     */
45
    protected MatchMode getMatchMode() {
46
        return matchMode;
47
    }
48

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

    
56
    /**
57
     * @return the orderHints
58
     */
59
    protected List<OrderHint> getOrderHints() {
60
        return orderHints;
61
    }
62

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

    
70
    /**
71
     * With defaults for matchMode = MatchMode.ANYWHERE and orderHints = OrderHint.ORDER_BY_TITLE_CACHE
72
     *
73
     * @param service
74
     */
75
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, ConversationDirector conversationDirector) {
76
        super();
77
        this.service = service;
78
        this.conversationDirector = conversationDirector;
79
    }
80

    
81
    /**
82
     * @param service
83
     * @param matchMode
84
     * @param orderHints
85
     */
86
    public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode, List<OrderHint> orderHints, ConversationDirector conversationDirector) {
87
        super();
88
        this.service = service;
89
        this.matchMode = matchMode;
90
        this.orderHints = orderHints;
91
        this.conversationDirector = conversationDirector;
92
    }
93

    
94
    /**
95
     * {@inheritDoc}
96
     */
97
    @Override
98
    public List<T> findEntities(int firstRow, String filter) {
99

    
100
        conversationDirector.ensureBoundConversation();
101
        Pager<T> page = service.findByTitle(
102
                null,
103
                filter,
104
                matchMode,
105
                null,
106
                pageSize,
107
                firstRow,
108
                orderHints,
109
                Arrays.asList("$")
110
              );
111
        return page.getRecords();
112
    }
113

    
114
    /**
115
     * {@inheritDoc}
116
     */
117
    @Override
118
    public int size(String filter) {
119

    
120
        conversationDirector.ensureBoundConversation();
121
        Pager<T> page = service.findByTitle(
122
                null,
123
                filter,
124
                matchMode,
125
                null,
126
                1,
127
                0,
128
                null,
129
                null
130
              );
131
        return page.getCount().intValue();
132
    }
133

    
134
    /**
135
     * @return the pageSize
136
     */
137
    public int getPageSize() {
138
        return pageSize;
139
    }
140

    
141
    /**
142
     * @param pageSize the pageSize to set
143
     */
144
    public void setPageSize(int pageSize) {
145
        this.pageSize = pageSize;
146
    }
147

    
148
}
(1-1/5)