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