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
Line 
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
15package de.ugoe.cs.autoquest.usability.taskmodel.filter.types;
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;
24import de.ugoe.cs.autoquest.plugin.html.guimodel.HTMLText;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
26import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
27import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
28import 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 */
37public 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}
Note: See TracBrowser for help on using the repository browser.