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.event;
|
10
|
|
11
|
import java.util.Optional;
|
12
|
|
13
|
import org.vaadin.spring.events.Event;
|
14
|
import org.vaadin.spring.events.EventBusListenerMethodFilter;
|
15
|
|
16
|
import eu.etaxonomy.cdm.vaadin.event.EntityChangeEvent.Type;
|
17
|
|
18
|
/**
|
19
|
* @author a.kohlbecker
|
20
|
* @since Jan 31, 2018
|
21
|
*
|
22
|
*/
|
23
|
public class EntityChangeEventFilter implements EventBusListenerMethodFilter {
|
24
|
|
25
|
|
26
|
private Optional<Class<?>> entityType = null;
|
27
|
|
28
|
private Optional<Type> eventType = null;
|
29
|
|
30
|
private EntityChangeEventFilter(Class<?> entityType, Type eventType){
|
31
|
this.entityType = Optional.of(entityType);
|
32
|
this.eventType = Optional.of(eventType);
|
33
|
}
|
34
|
|
35
|
private EntityChangeEventFilter(Type eventType){
|
36
|
this.eventType = Optional.of(eventType);
|
37
|
}
|
38
|
|
39
|
private EntityChangeEventFilter(Class<?> entityType){
|
40
|
this.entityType = Optional.of(entityType);
|
41
|
}
|
42
|
|
43
|
/**
|
44
|
* {@inheritDoc}
|
45
|
*/
|
46
|
@Override
|
47
|
public boolean filter(Event<?> event) {
|
48
|
if(event.getPayload() instanceof EntityChangeEvent){
|
49
|
EntityChangeEvent testEvent = (EntityChangeEvent)event.getPayload();
|
50
|
boolean match = true;
|
51
|
if(this.entityType != null){
|
52
|
match &= this.entityType.get().equals(testEvent.getEntityType());
|
53
|
}
|
54
|
if(this.eventType != null){
|
55
|
match &= this.eventType.get().equals(testEvent.getType());
|
56
|
}
|
57
|
return match;
|
58
|
}
|
59
|
return false;
|
60
|
}
|
61
|
|
62
|
|
63
|
public static class OccurrenceCollectionFilter extends EntityChangeEventFilter{
|
64
|
|
65
|
public OccurrenceCollectionFilter(){
|
66
|
super(eu.etaxonomy.cdm.model.occurrence.Collection.class);
|
67
|
}
|
68
|
}
|
69
|
|
70
|
public static class ReferenceFilter extends EntityChangeEventFilter {
|
71
|
|
72
|
public ReferenceFilter() {
|
73
|
super(eu.etaxonomy.cdm.model.reference.Reference.class);
|
74
|
}
|
75
|
}
|
76
|
|
77
|
}
|