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 | |
---|
15 | package de.ugoe.cs.autoquest.usability; |
---|
16 | |
---|
17 | import java.util.Collection; |
---|
18 | import java.util.HashMap; |
---|
19 | import java.util.HashSet; |
---|
20 | import java.util.List; |
---|
21 | import java.util.Map; |
---|
22 | import java.util.Set; |
---|
23 | |
---|
24 | import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox; |
---|
25 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
26 | import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor; |
---|
27 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; |
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; |
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric; |
---|
35 | |
---|
36 | /** |
---|
37 | * TODO comment |
---|
38 | * |
---|
39 | * @version $Revision: $ $Date: 16.07.2012$ |
---|
40 | * @author 2012, last modified by $Author: pharms$ |
---|
41 | */ |
---|
42 | public class CheckBoxMultipleSelectionRule implements UsabilityEvaluationRule { |
---|
43 | |
---|
44 | /* |
---|
45 | * (non-Javadoc) |
---|
46 | * |
---|
47 | * @see de.ugoe.cs.usability.UsabilityEvaluationRule#evaluate(TaskTree) |
---|
48 | */ |
---|
49 | @Override |
---|
50 | public UsabilityEvaluationResult evaluate(ITaskModel taskModel) { |
---|
51 | ValueChangeStatistics statistics = new ValueChangeStatistics(); |
---|
52 | |
---|
53 | calculateStatistics(taskModel.getTasks(), statistics); |
---|
54 | |
---|
55 | statistics.condenseCheckBoxGroups(); |
---|
56 | |
---|
57 | UsabilityEvaluationResult results = new UsabilityEvaluationResult(taskModel); |
---|
58 | analyzeStatistics(statistics, taskModel, results); |
---|
59 | |
---|
60 | return results; |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | * |
---|
65 | */ |
---|
66 | private void analyzeStatistics(ValueChangeStatistics statistics, |
---|
67 | ITaskModel taskModel, |
---|
68 | UsabilityEvaluationResult results) |
---|
69 | { |
---|
70 | Map<IGUIElement, List<IGUIElement>> checkBoxGroups = statistics.getCheckBoxGroups(); |
---|
71 | |
---|
72 | CHECK_NEXT_GROUP: |
---|
73 | for (List<IGUIElement> group : checkBoxGroups.values()) { |
---|
74 | Set<ITask> tasksUsingGroup = new HashSet<>(); |
---|
75 | |
---|
76 | for (IGUIElement checkBox : group) { |
---|
77 | Set<ITask> tasksUsingCheckBox = getTasksUsingCheckBox(checkBox, taskModel); |
---|
78 | |
---|
79 | for (ITask taskUsingCheckBox : tasksUsingCheckBox) { |
---|
80 | if (tasksUsingGroup.contains(taskUsingCheckBox)) { |
---|
81 | continue CHECK_NEXT_GROUP; |
---|
82 | } |
---|
83 | else { |
---|
84 | tasksUsingGroup.add(taskUsingCheckBox); |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | if (tasksUsingGroup.size() > 0) { |
---|
90 | int eventCoverage = 0; |
---|
91 | int allRecordedEvents = 0; |
---|
92 | |
---|
93 | for (ITask task : tasksUsingGroup) { |
---|
94 | if (task instanceof IEventTask) { |
---|
95 | eventCoverage += |
---|
96 | taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | for (ITask task : taskModel.getTasks()) { |
---|
101 | if (task instanceof IEventTask) { |
---|
102 | allRecordedEvents += |
---|
103 | taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity |
---|
109 | ((int) (1000 * eventCoverage / allRecordedEvents), eventCoverage, -1); |
---|
110 | |
---|
111 | if (intensity != null) { |
---|
112 | Map<String, Object> parameters = new HashMap<String, Object>(); |
---|
113 | parameters.put("radioButtons", group); |
---|
114 | |
---|
115 | results.addSmell |
---|
116 | (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, |
---|
117 | parameters); |
---|
118 | } |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * |
---|
125 | */ |
---|
126 | private Set<ITask> getTasksUsingCheckBox(final IGUIElement checkBox, ITaskModel taskModel) { |
---|
127 | final Set<ITask> tasksUsingCheckBox = new HashSet<ITask>(); |
---|
128 | |
---|
129 | for (ITask candidate : taskModel.getTasks()) { |
---|
130 | candidate.accept(new DefaultTaskTraversingVisitor() { |
---|
131 | @Override |
---|
132 | public void visit(IEventTask eventTask) { |
---|
133 | if (!eventTask.getInstances().isEmpty()) { |
---|
134 | IEventTaskInstance instance = |
---|
135 | (IEventTaskInstance) eventTask.getInstances().iterator().next(); |
---|
136 | |
---|
137 | if (checkBox.equals(instance.getEvent().getTarget())) { |
---|
138 | tasksUsingCheckBox.add(eventTask); |
---|
139 | } |
---|
140 | } |
---|
141 | } |
---|
142 | |
---|
143 | @Override |
---|
144 | public void visit(IStructuringTemporalRelationship relationship) { |
---|
145 | if (tasksUsingCheckBox.contains(relationship)) { |
---|
146 | return; |
---|
147 | } |
---|
148 | else { |
---|
149 | for (ITask child : relationship.getChildren()) { |
---|
150 | if (tasksUsingCheckBox.contains(child)) { |
---|
151 | tasksUsingCheckBox.add(relationship); |
---|
152 | return; |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | super.visit(relationship); |
---|
157 | |
---|
158 | for (ITask child : relationship.getChildren()) { |
---|
159 | if (tasksUsingCheckBox.contains(child)) { |
---|
160 | tasksUsingCheckBox.add(relationship); |
---|
161 | break; |
---|
162 | } |
---|
163 | } |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | @Override |
---|
168 | public void visit(IMarkingTemporalRelationship relationship) { |
---|
169 | if (tasksUsingCheckBox.contains(relationship)) { |
---|
170 | return; |
---|
171 | } |
---|
172 | else { |
---|
173 | if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) { |
---|
174 | tasksUsingCheckBox.add(relationship); |
---|
175 | return; |
---|
176 | } |
---|
177 | |
---|
178 | super.visit(relationship); |
---|
179 | |
---|
180 | if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) { |
---|
181 | tasksUsingCheckBox.add(relationship); |
---|
182 | return; |
---|
183 | } |
---|
184 | } |
---|
185 | } |
---|
186 | }); |
---|
187 | } |
---|
188 | |
---|
189 | return tasksUsingCheckBox; |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * |
---|
194 | */ |
---|
195 | private void calculateStatistics(Collection<ITask> tasks, |
---|
196 | ValueChangeStatistics statistics) |
---|
197 | { |
---|
198 | for (ITask task : tasks) { |
---|
199 | if (task instanceof IEventTask) { |
---|
200 | for (ITaskInstance taskInstance : task.getInstances()) { |
---|
201 | statistics.addValueChange((IEventTaskInstance) taskInstance); |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | /** |
---|
208 | * |
---|
209 | */ |
---|
210 | private static class ValueChangeStatistics { |
---|
211 | |
---|
212 | /** */ |
---|
213 | private Set<IGUIElement> checkBoxes = new HashSet<>(); |
---|
214 | |
---|
215 | /** */ |
---|
216 | private Map<IGUIElement, List<IGUIElement>> checkBoxGroups = new HashMap<>(); |
---|
217 | |
---|
218 | /** |
---|
219 | * |
---|
220 | */ |
---|
221 | private void addValueChange(IEventTaskInstance instance) { |
---|
222 | IGUIElement target = (IGUIElement) instance.getEvent().getTarget(); |
---|
223 | |
---|
224 | if (target instanceof ICheckBox) { |
---|
225 | checkBoxes.add(target); |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | /** |
---|
230 | * |
---|
231 | */ |
---|
232 | private void condenseCheckBoxGroups() { |
---|
233 | checkBoxGroups = RuleUtils.getGroups(checkBoxes, 3); |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * |
---|
238 | */ |
---|
239 | private Map<IGUIElement, List<IGUIElement>> getCheckBoxGroups() { |
---|
240 | return checkBoxGroups; |
---|
241 | } |
---|
242 | |
---|
243 | } |
---|
244 | |
---|
245 | } |
---|