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, V extends T> implements FilterablePagingProvider<V>, FilterableCountProvider {
|
29
|
|
30
|
private int pageSize = 20;
|
31
|
|
32
|
private IIdentifiableEntityService<T> service;
|
33
|
|
34
|
private Class<V> type = null;
|
35
|
|
36
|
private MatchMode matchMode = MatchMode.ANYWHERE;
|
37
|
|
38
|
private List<OrderHint> orderHints = OrderHint.ORDER_BY_TITLE_CACHE.asList();
|
39
|
|
40
|
|
41
|
/**
|
42
|
* @return the matchMode
|
43
|
*/
|
44
|
protected MatchMode getMatchMode() {
|
45
|
return matchMode;
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* @param matchMode the matchMode to set
|
50
|
*/
|
51
|
protected void setMatchMode(MatchMode matchMode) {
|
52
|
this.matchMode = matchMode;
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* @return the orderHints
|
57
|
*/
|
58
|
protected List<OrderHint> getOrderHints() {
|
59
|
return orderHints;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* @param orderHints the orderHints to set
|
64
|
*/
|
65
|
protected void setOrderHints(List<OrderHint> orderHints) {
|
66
|
this.orderHints = orderHints;
|
67
|
}
|
68
|
|
69
|
/**
|
70
|
* With defaults for matchMode = MatchMode.ANYWHERE and orderHints = OrderHint.ORDER_BY_TITLE_CACHE
|
71
|
*
|
72
|
*/
|
73
|
public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service) {
|
74
|
this(service, null);
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* With defaults for matchMode = MatchMode.ANYWHERE and orderHints = OrderHint.ORDER_BY_TITLE_CACHE
|
79
|
*
|
80
|
*/
|
81
|
public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, Class<V> type) {
|
82
|
super();
|
83
|
this.type = type;
|
84
|
this.service = service;
|
85
|
}
|
86
|
|
87
|
|
88
|
public CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, MatchMode matchMode, List<OrderHint> orderHints) {
|
89
|
this(service, null, matchMode, orderHints);
|
90
|
}
|
91
|
|
92
|
public <S extends T> CdmFilterablePagingProvider(IIdentifiableEntityService<T> service, Class<V> type, MatchMode matchMode, List<OrderHint> orderHints) {
|
93
|
super();
|
94
|
this.type = type;
|
95
|
this.service = service;
|
96
|
this.matchMode = matchMode;
|
97
|
this.orderHints = orderHints;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* {@inheritDoc}
|
102
|
*/
|
103
|
@Override
|
104
|
public List<V> findEntities(int firstRow, String filter) {
|
105
|
|
106
|
Pager<V> page = (Pager<V>) service.findByTitle(
|
107
|
type,
|
108
|
filter,
|
109
|
matchMode,
|
110
|
null,
|
111
|
pageSize,
|
112
|
firstRow,
|
113
|
orderHints,
|
114
|
Arrays.asList("$")
|
115
|
);
|
116
|
return page.getRecords();
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* {@inheritDoc}
|
121
|
*/
|
122
|
@Override
|
123
|
public int size(String filter) {
|
124
|
|
125
|
Pager<V> page = (Pager<V>) service.findByTitle(
|
126
|
type,
|
127
|
filter,
|
128
|
matchMode,
|
129
|
null,
|
130
|
1,
|
131
|
0,
|
132
|
null,
|
133
|
null
|
134
|
);
|
135
|
return page.getCount().intValue();
|
136
|
}
|
137
|
|
138
|
/**
|
139
|
* @return the pageSize
|
140
|
*/
|
141
|
public int getPageSize() {
|
142
|
return pageSize;
|
143
|
}
|
144
|
|
145
|
/**
|
146
|
* @param pageSize the pageSize to set
|
147
|
*/
|
148
|
public void setPageSize(int pageSize) {
|
149
|
this.pageSize = pageSize;
|
150
|
}
|
151
|
|
152
|
}
|