1 | package de.ugoe.cs.autoquest.usability.tasktree.filter;
|
---|
2 |
|
---|
3 | import com.google.common.base.Function;
|
---|
4 | import com.google.common.base.Predicate;
|
---|
5 | import com.google.common.base.Predicates;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.autoquest.eventcore.IEventType;
|
---|
8 | import de.ugoe.cs.autoquest.eventcore.gui.MouseButtonInteraction;
|
---|
9 | import de.ugoe.cs.autoquest.eventcore.gui.MouseInteraction;
|
---|
10 | import de.ugoe.cs.autoquest.eventcore.gui.TextInput;
|
---|
11 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
12 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
|
---|
13 |
|
---|
14 | public enum EventTypeFilter implements TaskTreeNodeFilter<IEventType> {
|
---|
15 |
|
---|
16 | TEXT_INPUT(TextInput.class),
|
---|
17 |
|
---|
18 | MOUSE_INTERACTION(MouseInteraction.class),
|
---|
19 |
|
---|
20 | MOUSE_BUTTON_INTERACTION(MouseButtonInteraction.class);
|
---|
21 |
|
---|
22 | private Class<? extends IEventType> eventTypeClazz;
|
---|
23 |
|
---|
24 | private EventTypeFilter(Class<? extends IEventType> eventTypeClazz) {
|
---|
25 | this.eventTypeClazz = eventTypeClazz;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @SuppressWarnings("unchecked")
|
---|
29 | @Override
|
---|
30 | public Class<IEventType> clazz() {
|
---|
31 | return (Class<IEventType>) eventTypeClazz;
|
---|
32 | }
|
---|
33 |
|
---|
34 | @SuppressWarnings("rawtypes")
|
---|
35 | @Override
|
---|
36 | public Predicate filterPredicate() {
|
---|
37 | Predicate<Object> instanceOfIEventTaskPredicate = Predicates.instanceOf(IEventTask.class);
|
---|
38 | Predicate<ITaskTreeNode> nodeHoldsInstanceOfFilterArgument =
|
---|
39 | Predicates.compose(Predicates.instanceOf(eventTypeClazz), nodeExtractionFunction());
|
---|
40 | return Predicates.and(instanceOfIEventTaskPredicate, nodeHoldsInstanceOfFilterArgument);
|
---|
41 | }
|
---|
42 |
|
---|
43 | private Function<ITaskTreeNode, IEventType> nodeExtractionFunction() {
|
---|
44 | return new Function<ITaskTreeNode, IEventType>() {
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public IEventType apply(ITaskTreeNode treeNode) {
|
---|
48 | return ((IEventTask) treeNode).getEventType();
|
---|
49 | }
|
---|
50 | };
|
---|
51 | }
|
---|
52 | }
|
---|