source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/taskmodel/filter/types/EventTargetFilter.java @ 1319

Last change on this file since 1319 was 1319, checked in by khartmann, 11 years ago
  • Reworked Filters to use the first instance of a task to provide type and target
  • Added a function to extract all tasks matching a given filter
  • Added simple console feedback for matched usability problems
  • Property svn:mime-type set to text/plain
File size: 3.2 KB
RevLine 
[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]15package de.ugoe.cs.autoquest.usability.taskmodel.filter.types;
[1030]16
17import com.google.common.base.Function;
18import com.google.common.base.Predicate;
19import com.google.common.base.Predicates;
20
21import de.ugoe.cs.autoquest.eventcore.IEventTarget;
22import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea;
23import de.ugoe.cs.autoquest.eventcore.guimodel.ITextField;
[1291]24import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText;
[1030]25import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
[1319]26import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
[1152]27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
[1319]28import 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]37public 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}
Note: See TracBrowser for help on using the repository browser.