1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.taskmodel.filter.types;
|
---|
16 |
|
---|
17 | import com.google.common.base.Function;
|
---|
18 | import com.google.common.base.Predicate;
|
---|
19 | import com.google.common.base.Predicates;
|
---|
20 |
|
---|
21 | import de.ugoe.cs.autoquest.eventcore.IEventTarget;
|
---|
22 | import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea;
|
---|
23 | import de.ugoe.cs.autoquest.eventcore.guimodel.ITextField;
|
---|
24 | import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText;
|
---|
25 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
|
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * <p>
|
---|
30 | * Event target filter for {@link EventTask}s.
|
---|
31 | * </p>
|
---|
32 | *
|
---|
33 | * @author Alexander Deicke
|
---|
34 | */
|
---|
35 | public enum EventTargetFilter implements TaskFilter<IEventTarget> {
|
---|
36 |
|
---|
37 | TEXT_FIELD(ITextField.class),
|
---|
38 |
|
---|
39 | TEXT_AREA(ITextArea.class),
|
---|
40 |
|
---|
41 | SPAN(HTMLText.class);
|
---|
42 |
|
---|
43 | private Class<? extends IEventTarget> eventTargetClazz;
|
---|
44 |
|
---|
45 | private EventTargetFilter(Class<? extends IEventTarget> eventTargetClazz) {
|
---|
46 | this.eventTargetClazz = eventTargetClazz;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * (non-Javadoc)
|
---|
51 | *
|
---|
52 | * @see de.ugoe.cs.autoquest.usability.tasktree.filters.TaskFilter#getId()
|
---|
53 | */
|
---|
54 | @SuppressWarnings("unchecked")
|
---|
55 | @Override
|
---|
56 | public Class<IEventTarget> clazz() {
|
---|
57 | return (Class<IEventTarget>) eventTargetClazz;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * (non-Javadoc)
|
---|
62 | *
|
---|
63 | * @see de.ugoe.cs.autoquest.usability.tasktree.filters.TaskFilter#getId()
|
---|
64 | */
|
---|
65 | @SuppressWarnings("rawtypes")
|
---|
66 | @Override
|
---|
67 | public Predicate filterPredicate() {
|
---|
68 | Predicate<Object> instanceOfIEventTaskPredicate = Predicates.instanceOf(IEventTask.class);
|
---|
69 | Predicate<ITask> taskHoldsInstanceOfFilterArgument =
|
---|
70 | Predicates.compose(Predicates.instanceOf(eventTargetClazz), taskExtractionFunction());
|
---|
71 | return Predicates.and(instanceOfIEventTaskPredicate, taskHoldsInstanceOfFilterArgument);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | *
|
---|
76 | * <p>
|
---|
77 | * Gets the event target of a {@link ITask}.
|
---|
78 | * </p>
|
---|
79 | *
|
---|
80 | * @return event target
|
---|
81 | */
|
---|
82 | private Function<ITask, IEventTarget> taskExtractionFunction() {
|
---|
83 | return new Function<ITask, IEventTarget>() {
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public IEventTarget apply(ITask task) {
|
---|
87 | return ((IEventTask) task).getEventTarget();
|
---|
88 | }
|
---|
89 | };
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|