1
|
/**
|
2
|
* Copyright (C) 2018 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.util.filter;
|
10
|
|
11
|
import java.util.List;
|
12
|
|
13
|
import com.vaadin.data.Container.Filter;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.term.TermBase;
|
16
|
|
17
|
import com.vaadin.data.Item;
|
18
|
import com.vaadin.data.Property;
|
19
|
|
20
|
/**
|
21
|
* @author a.kohlbecker
|
22
|
* @since Jun 21, 2018
|
23
|
*
|
24
|
*/
|
25
|
public class CdmTermFilter<T extends TermBase> implements Filter {
|
26
|
|
27
|
private static final long serialVersionUID = -613582375956129270L;
|
28
|
|
29
|
private List<T> includeFilter;
|
30
|
private Object propertyId;
|
31
|
|
32
|
/**
|
33
|
*
|
34
|
* @param propertyId
|
35
|
* @param includeFilter
|
36
|
* @param includeNullValues true by default
|
37
|
*/
|
38
|
public CdmTermFilter(Object propertyId, List<T> includeFilter){
|
39
|
this.propertyId = propertyId;
|
40
|
this.includeFilter = includeFilter;
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* {@inheritDoc}
|
45
|
*/
|
46
|
@Override
|
47
|
public boolean passesFilter(Object itemId, Item item) throws UnsupportedOperationException {
|
48
|
Property property = item.getItemProperty(propertyId);
|
49
|
Object value = property.getValue();
|
50
|
if(includeFilter.contains(value)){
|
51
|
return true;
|
52
|
}
|
53
|
return false;
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public boolean appliesToProperty(Object propertyId) {
|
58
|
return this.propertyId.equals(propertyId);
|
59
|
}
|
60
|
|
61
|
}
|