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