source: trunk/autoquest-core-usability-evaluation/src/main/java/de/ugoe/cs/autoquest/usability/tasktree/filters/EventTargetFilter.java @ 1135

Last change on this file since 1135 was 1135, checked in by adeicke, 11 years ago

Restructuring of package structure.

  • Property svn:mime-type set to text/plain
File size: 2.5 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.tasktree.filters;
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.tasktrees.treeifc.IEventTask;
25import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskTreeNode;
26
27/**
28 * <p>
29 * TODO comment
30 * </p>
31 *
32 * @author Alexander Deicke
33 */
34public enum EventTargetFilter implements TaskTreeNodeFilter<IEventTarget> {
35
36    TEXT_FIELD(ITextField.class),
37
38    TEXT_AREA(ITextArea.class);
39
40    private Class<? extends IEventTarget> eventTargetClazz;
41
42    private EventTargetFilter(Class<? extends IEventTarget> eventTargetClazz) {
43        this.eventTargetClazz = eventTargetClazz;
44    }
45
46    @SuppressWarnings("unchecked")
47    @Override
48    public Class<IEventTarget> clazz() {
49        return (Class<IEventTarget>) eventTargetClazz;
50    }
51
52    @SuppressWarnings("rawtypes")
53    @Override
54    public Predicate filterPredicate() {
55        Predicate<Object> instanceOfIEventTaskPredicate = Predicates.instanceOf(IEventTask.class);
56        Predicate<ITaskTreeNode> nodeHoldsInstanceOfFilterArgument =
57            Predicates.compose(Predicates.instanceOf(eventTargetClazz), nodeExtractionFunction());
58        return Predicates.and(instanceOfIEventTaskPredicate, nodeHoldsInstanceOfFilterArgument);
59    }
60
61    private Function<ITaskTreeNode, IEventTarget> nodeExtractionFunction() {
62        return new Function<ITaskTreeNode, IEventTarget>() {
63
64            @Override
65            public IEventTarget apply(ITaskTreeNode treeNode) {
66                return ((IEventTask) treeNode).getEventTarget();
67            }
68        };
69    }
70
71}
Note: See TracBrowser for help on using the repository browser.