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.IEventTaskInstance;
|
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
|
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * <p>
|
---|
32 | * Event target filter for {@link EventTask}s.
|
---|
33 | * </p>
|
---|
34 | *
|
---|
35 | * @author Alexander Deicke
|
---|
36 | */
|
---|
37 | public enum EventTargetFilter implements TaskFilter<IEventTarget> {
|
---|
38 |
|
---|
39 | TEXT_FIELD(ITextField.class),
|
---|
40 |
|
---|
41 | TEXT_AREA(ITextArea.class),
|
---|
42 |
|
---|
43 | SPAN(HTMLText.class);
|
---|
44 |
|
---|
45 | private Class<? extends IEventTarget> eventTargetClazz;
|
---|
46 |
|
---|
47 | private EventTargetFilter(Class<? extends IEventTarget> eventTargetClazz) {
|
---|
48 | this.eventTargetClazz = eventTargetClazz;
|
---|
49 | }
|
---|
50 |
|
---|
51 | /*
|
---|
52 | * (non-Javadoc)
|
---|
53 | *
|
---|
54 | * @see de.ugoe.cs.autoquest.usability.tasktree.filters.TaskFilter#getId()
|
---|
55 | */
|
---|
56 | @SuppressWarnings("unchecked")
|
---|
57 | @Override
|
---|
58 | public Class<IEventTarget> clazz() {
|
---|
59 | return (Class<IEventTarget>) eventTargetClazz;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * (non-Javadoc)
|
---|
64 | *
|
---|
65 | * @see de.ugoe.cs.autoquest.usability.tasktree.filters.TaskFilter#getId()
|
---|
66 | */
|
---|
67 | @SuppressWarnings("rawtypes")
|
---|
68 | @Override
|
---|
69 | public Predicate filterPredicate() {
|
---|
70 | Predicate<Object> instanceOfIEventTaskPredicate = Predicates.instanceOf(IEventTask.class);
|
---|
71 | Predicate<ITask> taskHoldsInstanceOfFilterArgument =
|
---|
72 | Predicates.compose(Predicates.instanceOf(eventTargetClazz), taskExtractionFunction());
|
---|
73 | return Predicates.and(instanceOfIEventTaskPredicate, taskHoldsInstanceOfFilterArgument);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | *
|
---|
78 | * <p>
|
---|
79 | * Gets the event target of a {@link ITask}.
|
---|
80 | * </p>
|
---|
81 | *
|
---|
82 | * @return event target
|
---|
83 | */
|
---|
84 | private Function<ITask, IEventTarget> taskExtractionFunction() {
|
---|
85 | return new Function<ITask, IEventTarget>() {
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public IEventTarget apply(ITask task) {
|
---|
89 | // XXX: Use the type of the first instance provided
|
---|
90 | ITaskInstance firstInstance = task.getInstances().iterator().next();
|
---|
91 | return ((IEventTaskInstance) firstInstance).getEvent().getTarget();
|
---|
92 | }
|
---|
93 | };
|
---|
94 | }
|
---|
95 |
|
---|
96 | }
|
---|