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