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.ui.swt; |
---|
16 | |
---|
17 | import java.awt.GraphicsDevice; |
---|
18 | import java.awt.GraphicsEnvironment; |
---|
19 | import java.util.ArrayList; |
---|
20 | import java.util.Collection; |
---|
21 | import java.util.Collections; |
---|
22 | import java.util.HashMap; |
---|
23 | import java.util.LinkedList; |
---|
24 | import java.util.List; |
---|
25 | import java.util.ListIterator; |
---|
26 | import java.util.Map; |
---|
27 | |
---|
28 | import org.eclipse.swt.SWT; |
---|
29 | import org.eclipse.swt.custom.SashForm; |
---|
30 | import org.eclipse.swt.custom.StyleRange; |
---|
31 | import org.eclipse.swt.custom.StyledText; |
---|
32 | import org.eclipse.swt.events.SelectionAdapter; |
---|
33 | import org.eclipse.swt.events.SelectionEvent; |
---|
34 | import org.eclipse.swt.events.ShellAdapter; |
---|
35 | import org.eclipse.swt.events.ShellEvent; |
---|
36 | import org.eclipse.swt.graphics.Font; |
---|
37 | import org.eclipse.swt.graphics.FontData; |
---|
38 | import org.eclipse.swt.layout.GridData; |
---|
39 | import org.eclipse.swt.layout.GridLayout; |
---|
40 | import org.eclipse.swt.layout.RowLayout; |
---|
41 | import org.eclipse.swt.widgets.Button; |
---|
42 | import org.eclipse.swt.widgets.Composite; |
---|
43 | import org.eclipse.swt.widgets.Control; |
---|
44 | import org.eclipse.swt.widgets.Dialog; |
---|
45 | import org.eclipse.swt.widgets.Display; |
---|
46 | import org.eclipse.swt.widgets.Event; |
---|
47 | import org.eclipse.swt.widgets.Group; |
---|
48 | import org.eclipse.swt.widgets.Label; |
---|
49 | import org.eclipse.swt.widgets.Listener; |
---|
50 | import org.eclipse.swt.widgets.Shell; |
---|
51 | import org.eclipse.swt.widgets.Text; |
---|
52 | import org.eclipse.swt.widgets.Tree; |
---|
53 | import org.eclipse.swt.widgets.TreeColumn; |
---|
54 | import org.eclipse.swt.widgets.TreeItem; |
---|
55 | |
---|
56 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
57 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; |
---|
58 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
59 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
60 | import de.ugoe.cs.autoquest.usability.UsabilitySmell; |
---|
61 | import de.ugoe.cs.autoquest.usability.UsabilitySmell.ManualLabel; |
---|
62 | import de.ugoe.cs.autoquest.usability.UsabilitySmellIntensity; |
---|
63 | import de.ugoe.cs.autoquest.usability.UsabilityEvaluationResult; |
---|
64 | |
---|
65 | /** |
---|
66 | * <p> |
---|
67 | * a dialog to inspect the results of a usability evaluation |
---|
68 | * TODO update comments |
---|
69 | * </p> |
---|
70 | * |
---|
71 | * @author Patrick Harms |
---|
72 | */ |
---|
73 | public class ShowUsabilityEvaluationResultDialog extends Dialog { |
---|
74 | |
---|
75 | /** the main shell */ |
---|
76 | protected Shell shell; |
---|
77 | |
---|
78 | /** the table containing all smells */ |
---|
79 | private Tree smellList; |
---|
80 | |
---|
81 | /** the description label of a selected smell */ |
---|
82 | private StyledText description; |
---|
83 | |
---|
84 | /** the tree of involved GUI elements of a specific smell on the right */ |
---|
85 | private Tree involvedTargetsTree; |
---|
86 | |
---|
87 | /** the table containing the involved tasks of a displayed smell */ |
---|
88 | private Tree involvedTasks; |
---|
89 | |
---|
90 | /** the radio button group for assessing if a smell is true positive or not */ |
---|
91 | private Group assessmentRadioButtons; |
---|
92 | |
---|
93 | /** the list of all different tags given for smells */ |
---|
94 | private List<String> existingTags = new LinkedList<>(); |
---|
95 | |
---|
96 | /** the parent of all check boxes for tag representation */ |
---|
97 | private Composite tagCheckBoxParent; |
---|
98 | |
---|
99 | /** the displayed usability evaluation result */ |
---|
100 | private UsabilityEvaluationResult usabilityEvalResult; |
---|
101 | |
---|
102 | /** task tree dialog to show task details */ |
---|
103 | private ShowTaskTreeDialog showTaskTreeDialog; |
---|
104 | |
---|
105 | /** |
---|
106 | * creates the dialog |
---|
107 | */ |
---|
108 | public ShowUsabilityEvaluationResultDialog(Shell parent, |
---|
109 | int style, |
---|
110 | UsabilityEvaluationResult usabilityEvalResult, |
---|
111 | String dataSetName) |
---|
112 | { |
---|
113 | super(parent, style); |
---|
114 | setText("Usability Evaluation Result " + dataSetName); |
---|
115 | this.usabilityEvalResult = usabilityEvalResult; |
---|
116 | |
---|
117 | for (UsabilitySmell smell : usabilityEvalResult.getAllSmells()) { |
---|
118 | for (String tag : smell.getTags()) { |
---|
119 | if (!existingTags.contains(tag)) { |
---|
120 | existingTags.add(tag); |
---|
121 | } |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | Collections.sort(existingTags); |
---|
126 | } |
---|
127 | |
---|
128 | /** |
---|
129 | * displays the dialog |
---|
130 | */ |
---|
131 | public void open() { |
---|
132 | showTaskTreeDialog = new ShowTaskTreeDialog |
---|
133 | (super.getParent(), SWT.NONE, usabilityEvalResult.getTaskModel(), |
---|
134 | "task details of usability smells"); |
---|
135 | |
---|
136 | createContents(); |
---|
137 | shell.open(); |
---|
138 | shell.layout(); |
---|
139 | |
---|
140 | shell.addShellListener(new ShellAdapter() { |
---|
141 | @Override |
---|
142 | public void shellClosed(ShellEvent e) { |
---|
143 | showTaskTreeDialog.dispose(); |
---|
144 | } |
---|
145 | }); |
---|
146 | |
---|
147 | Display display = getParent().getDisplay(); |
---|
148 | while (!shell.isDisposed()) { |
---|
149 | if (!display.readAndDispatch()) { |
---|
150 | display.sleep(); |
---|
151 | } |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * creates the two views, one on the task instances on the left, on on the task models on the |
---|
157 | * right. Also adds a selection adapter to the task instances so that for a selected task |
---|
158 | * instance always the respective model is presented. |
---|
159 | */ |
---|
160 | private void createContents() { |
---|
161 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER); |
---|
162 | GraphicsDevice gd = |
---|
163 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); |
---|
164 | |
---|
165 | shell.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); |
---|
166 | shell.setText(getText()); |
---|
167 | |
---|
168 | shell.setLayout(new GridLayout(1, false)); |
---|
169 | |
---|
170 | SashForm mainSashForm = new SashForm(shell, SWT.HORIZONTAL); |
---|
171 | mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
172 | |
---|
173 | smellList = new Tree(mainSashForm, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL); |
---|
174 | smellList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
175 | smellList.setHeaderVisible(true); |
---|
176 | smellList.setLinesVisible(true); |
---|
177 | |
---|
178 | TreeColumn treeColumn = new TreeColumn(smellList, SWT.NONE); |
---|
179 | treeColumn.setWidth(200); |
---|
180 | treeColumn.setText("smells"); |
---|
181 | |
---|
182 | buildSmellTree(); |
---|
183 | |
---|
184 | smellList.addSelectionListener(new SelectionAdapter() { |
---|
185 | @Override |
---|
186 | public void widgetSelected(SelectionEvent e) { |
---|
187 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
188 | if ((selectedItems.length == 1) && |
---|
189 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
190 | { |
---|
191 | displaySmellDetails((UsabilitySmell) selectedItems[0].getData()); |
---|
192 | } |
---|
193 | else { |
---|
194 | clearSmellDetails(); |
---|
195 | } |
---|
196 | } |
---|
197 | }); |
---|
198 | |
---|
199 | SashForm detailsSashForm = new SashForm(mainSashForm, SWT.VERTICAL); |
---|
200 | detailsSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
201 | |
---|
202 | Composite descriptionComposite = new Composite(detailsSashForm, SWT.NONE); |
---|
203 | descriptionComposite.setLayout(new GridLayout()); |
---|
204 | |
---|
205 | description = new StyledText(descriptionComposite, SWT.READ_ONLY | SWT.BORDER | SWT.WRAP); |
---|
206 | description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
207 | |
---|
208 | SashForm detailsTreesSashForm = new SashForm(detailsSashForm, SWT.HORIZONTAL); |
---|
209 | detailsTreesSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
210 | |
---|
211 | involvedTasks = VisualizationUtils.createTaskDetailsTree |
---|
212 | (detailsTreesSashForm, "involved tasks", usabilityEvalResult.getTaskModel()); |
---|
213 | |
---|
214 | VisualizationUtils.addItemSpecificContextMenu |
---|
215 | (involvedTasks, ITask.class, "show details", new SelectionAdapter() |
---|
216 | { |
---|
217 | @Override |
---|
218 | public void widgetSelected(SelectionEvent e) { |
---|
219 | showTaskTreeDialog.open((ITask) involvedTasks.getSelection()[0].getData()); |
---|
220 | } |
---|
221 | }); |
---|
222 | |
---|
223 | VisualizationUtils.addExpansionListener(involvedTasks, new Listener() { |
---|
224 | public void handleEvent(final Event event) { |
---|
225 | ensureChildren((TreeItem) event.item); |
---|
226 | ((TreeItem) event.item).setExpanded(true); |
---|
227 | } |
---|
228 | }); |
---|
229 | |
---|
230 | involvedTargetsTree = |
---|
231 | VisualizationUtils.createTargetsTree(detailsTreesSashForm, "involved GUI elements"); |
---|
232 | |
---|
233 | VisualizationUtils.addInvolvedTargetsHighlighting(involvedTasks, involvedTargetsTree); |
---|
234 | |
---|
235 | final Composite detailsAssessmentComposite = new Composite(descriptionComposite, SWT.NONE); |
---|
236 | detailsAssessmentComposite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1)); |
---|
237 | detailsAssessmentComposite.setLayout(new GridLayout(5, false)); |
---|
238 | |
---|
239 | assessmentRadioButtons = new Group(detailsAssessmentComposite, SWT.NONE); |
---|
240 | assessmentRadioButtons.setLayout(new RowLayout(SWT.HORIZONTAL)); |
---|
241 | |
---|
242 | final Button unassessedRadioButton = new Button(assessmentRadioButtons, SWT.RADIO); |
---|
243 | unassessedRadioButton.setText("unassessed"); |
---|
244 | unassessedRadioButton.addSelectionListener(new SelectionAdapter() { |
---|
245 | @Override |
---|
246 | public void widgetSelected(SelectionEvent event) { |
---|
247 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
248 | if ((selectedItems.length == 1) && |
---|
249 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
250 | { |
---|
251 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
252 | if (unassessedRadioButton.getSelection()) { |
---|
253 | smell.setManualLabel(ManualLabel.UNCHECKED); |
---|
254 | } |
---|
255 | } |
---|
256 | } |
---|
257 | }); |
---|
258 | |
---|
259 | final Button falsePositiveRadioButton = new Button(assessmentRadioButtons, SWT.RADIO); |
---|
260 | falsePositiveRadioButton.setText("false positive"); |
---|
261 | falsePositiveRadioButton.addSelectionListener(new SelectionAdapter() { |
---|
262 | @Override |
---|
263 | public void widgetSelected(SelectionEvent event) { |
---|
264 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
265 | if ((selectedItems.length == 1) && |
---|
266 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
267 | { |
---|
268 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
269 | if (falsePositiveRadioButton.getSelection()) { |
---|
270 | smell.setManualLabel(ManualLabel.FALSE_POSITIVE); |
---|
271 | } |
---|
272 | } |
---|
273 | } |
---|
274 | }); |
---|
275 | |
---|
276 | final Button truePositiveRadioButton = new Button(assessmentRadioButtons, SWT.RADIO); |
---|
277 | truePositiveRadioButton.setText("true positive"); |
---|
278 | truePositiveRadioButton.addSelectionListener(new SelectionAdapter() { |
---|
279 | @Override |
---|
280 | public void widgetSelected(SelectionEvent event) { |
---|
281 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
282 | if ((selectedItems.length == 1) && |
---|
283 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
284 | { |
---|
285 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
286 | if (truePositiveRadioButton.getSelection()) { |
---|
287 | smell.setManualLabel(ManualLabel.TRUE_POSITIVE); |
---|
288 | } |
---|
289 | } |
---|
290 | } |
---|
291 | }); |
---|
292 | |
---|
293 | new Label(detailsAssessmentComposite, SWT.NONE).setText("Tags:"); |
---|
294 | |
---|
295 | tagCheckBoxParent = new Composite(detailsAssessmentComposite, SWT.NONE); |
---|
296 | tagCheckBoxParent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
---|
297 | tagCheckBoxParent.setLayout(new RowLayout()); |
---|
298 | |
---|
299 | recreateTagsSashForm(); |
---|
300 | |
---|
301 | final Text addTagField = new Text(detailsAssessmentComposite, SWT.BORDER); |
---|
302 | addTagField.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
---|
303 | addTagField.setSize(addTagField.computeSize(100, 50)); |
---|
304 | |
---|
305 | final Button addTagButton = new Button(detailsAssessmentComposite, SWT.NONE); |
---|
306 | addTagButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
---|
307 | addTagButton.addSelectionListener(new SelectionAdapter() { |
---|
308 | @Override |
---|
309 | public void widgetSelected(SelectionEvent e) { |
---|
310 | String tagName = addTagField.getText(); |
---|
311 | if ((tagName != null) && (!"".equals(tagName)) && (!existingTags.contains(tagName))) { |
---|
312 | existingTags.add(tagName); |
---|
313 | recreateTagsSashForm(); |
---|
314 | } |
---|
315 | } |
---|
316 | }); |
---|
317 | addTagButton.setText("add tag"); |
---|
318 | |
---|
319 | detailsTreesSashForm.setWeights(new int[] { 1, 1 }); |
---|
320 | detailsSashForm.setWeights(new int[] { 1, 3 }); |
---|
321 | mainSashForm.setWeights(new int[] { 1, 3 }); |
---|
322 | |
---|
323 | //indexColumn.pack(); |
---|
324 | //severityColumn.pack(); |
---|
325 | //descriptionColumn.pack(); |
---|
326 | //smellList.pack(); |
---|
327 | } |
---|
328 | |
---|
329 | /** |
---|
330 | * <p> |
---|
331 | * TODO: comment |
---|
332 | * </p> |
---|
333 | * |
---|
334 | */ |
---|
335 | private void recreateTagsSashForm() { |
---|
336 | for (Control child : tagCheckBoxParent.getChildren()) { |
---|
337 | child.dispose(); |
---|
338 | } |
---|
339 | |
---|
340 | if (existingTags.size() > 0) { |
---|
341 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
342 | boolean enabled = (selectedItems.length == 1) && |
---|
343 | (selectedItems[0].getData() instanceof UsabilitySmell); |
---|
344 | |
---|
345 | for (String existingTag : existingTags) { |
---|
346 | Button checkBox = new Button(tagCheckBoxParent, SWT.CHECK); |
---|
347 | checkBox.setText(existingTag); |
---|
348 | checkBox.addSelectionListener(new SelectionAdapter() { |
---|
349 | @Override |
---|
350 | public void widgetSelected(SelectionEvent event) { |
---|
351 | Button btn = (Button) event.getSource(); |
---|
352 | |
---|
353 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
354 | if ((selectedItems.length == 1) && |
---|
355 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
356 | { |
---|
357 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
358 | |
---|
359 | if (btn.getSelection()) { |
---|
360 | smell.addTag(btn.getText()); |
---|
361 | } |
---|
362 | else { |
---|
363 | smell.removeTag(btn.getText()); |
---|
364 | } |
---|
365 | } |
---|
366 | } |
---|
367 | }); |
---|
368 | |
---|
369 | checkBox.setEnabled(enabled); |
---|
370 | if (enabled) { |
---|
371 | checkBox.setSelection |
---|
372 | (((UsabilitySmell) selectedItems[0].getData()).getTags().contains(existingTag)); |
---|
373 | } |
---|
374 | } |
---|
375 | } |
---|
376 | else { |
---|
377 | new Label(tagCheckBoxParent, SWT.NONE).setText |
---|
378 | ("no tags added yet --> add using the text field and the button on the right"); |
---|
379 | } |
---|
380 | |
---|
381 | tagCheckBoxParent.layout(); |
---|
382 | tagCheckBoxParent.redraw(); |
---|
383 | } |
---|
384 | |
---|
385 | /** |
---|
386 | * convenience method for creating the display of the instances |
---|
387 | */ |
---|
388 | private void buildSmellTree() { |
---|
389 | int groupCount = 5; |
---|
390 | int groupSize = 30; |
---|
391 | |
---|
392 | List<UsabilitySmell> smells = usabilityEvalResult.getAllSmells(); |
---|
393 | |
---|
394 | final Map<String, List<UsabilitySmell>> sortedSmells = new HashMap<>(); |
---|
395 | |
---|
396 | for (UsabilitySmell smell : smells) { |
---|
397 | List<UsabilitySmell> smellList = sortedSmells.get(smell.getBriefDescription()); |
---|
398 | |
---|
399 | if (smellList == null) { |
---|
400 | smellList = new ArrayList<UsabilitySmell>(); |
---|
401 | sortedSmells.put(smell.getBriefDescription(), smellList); |
---|
402 | } |
---|
403 | |
---|
404 | ListIterator<UsabilitySmell> it = smellList.listIterator(); |
---|
405 | boolean added = false; |
---|
406 | |
---|
407 | while (it.hasNext()) { |
---|
408 | if (smell.getIntensity().getEventCoverage() > |
---|
409 | it.next().getIntensity().getEventCoverage()) |
---|
410 | { |
---|
411 | it.previous(); |
---|
412 | it.add(smell); |
---|
413 | added = true; |
---|
414 | break; |
---|
415 | } |
---|
416 | } |
---|
417 | |
---|
418 | if (!added) { |
---|
419 | smellList.add(smell); |
---|
420 | } |
---|
421 | |
---|
422 | // extract the intial list of tags of the smells |
---|
423 | for (String tag : smell.getTags()) { |
---|
424 | if (!existingTags.contains(tag)) { |
---|
425 | existingTags.add(tag); |
---|
426 | } |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | final Map<Integer, Map<String, List<UsabilitySmell>>> allSortedSmells = |
---|
431 | new HashMap<Integer, Map<String, List<UsabilitySmell>>>(); |
---|
432 | |
---|
433 | for (Map.Entry<String, List<UsabilitySmell>> entry : sortedSmells.entrySet()) { |
---|
434 | // we create groupCount groups of size groupSize |
---|
435 | int overallIndex = 0; |
---|
436 | |
---|
437 | for (int i = 0; i < groupCount; i++) { |
---|
438 | List<UsabilitySmell> smellList = new LinkedList<>(); |
---|
439 | for (int j = 0; overallIndex < entry.getValue().size() && |
---|
440 | ((j < groupSize) || (i == (groupCount - 1))); j++) |
---|
441 | { |
---|
442 | UsabilitySmell smell = entry.getValue().get(overallIndex++); |
---|
443 | |
---|
444 | int ratio = smell.getIntensity().getRatio(); |
---|
445 | int eventCoverage = smell.getIntensity().getEventCoverage(); |
---|
446 | int index = 0; |
---|
447 | for (index = 0; index < smellList.size(); index++) { |
---|
448 | UsabilitySmellIntensity candidate = smellList.get(index).getIntensity(); |
---|
449 | if ((ratio == candidate.getRatio()) && |
---|
450 | (eventCoverage > candidate.getEventCoverage())) |
---|
451 | { |
---|
452 | break; |
---|
453 | } |
---|
454 | else if (ratio > candidate.getRatio()) { |
---|
455 | break; |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | smellList.add(index, smell); |
---|
460 | } |
---|
461 | |
---|
462 | if (smellList.size() > 0) { |
---|
463 | Map<String, List<UsabilitySmell>> smellGroups = allSortedSmells.get(i); |
---|
464 | |
---|
465 | if (smellGroups == null) { |
---|
466 | smellGroups = new HashMap<>(); |
---|
467 | allSortedSmells.put(i, smellGroups); |
---|
468 | } |
---|
469 | |
---|
470 | smellGroups.put(entry.getKey(), smellList); |
---|
471 | } |
---|
472 | } |
---|
473 | } |
---|
474 | |
---|
475 | if (smellList.getListeners(SWT.Expand).length == 0) { |
---|
476 | smellList.addListener(SWT.Expand, new Listener() { |
---|
477 | public void handleEvent(final Event event) { |
---|
478 | ensureChildren((TreeItem) event.item); |
---|
479 | ((TreeItem) event.item).setExpanded(true); |
---|
480 | } |
---|
481 | }); |
---|
482 | } |
---|
483 | |
---|
484 | for (int i = 0; i < allSortedSmells.size(); i++) { |
---|
485 | createRootItem("smells group " + (i + 1), allSortedSmells.get(i)); |
---|
486 | } |
---|
487 | |
---|
488 | } |
---|
489 | |
---|
490 | /** |
---|
491 | * convenience method for creating the display of the instances |
---|
492 | */ |
---|
493 | /*private void buildSmellTree() { |
---|
494 | List<UsabilitySmell> smells = usabilityEvalResult.getAllSmells(); |
---|
495 | |
---|
496 | int[] eventCoverageQuantileGroups = { 990, 975, 950, 0, -1 }; |
---|
497 | int[] minEventCoverages = new int[eventCoverageQuantileGroups.length]; |
---|
498 | int[] maxEventCoverages = new int[eventCoverageQuantileGroups.length]; |
---|
499 | |
---|
500 | final List<Map<String, List<UsabilitySmell>>> sortedSmells = |
---|
501 | new LinkedList<Map<String, List<UsabilitySmell>>>(); |
---|
502 | |
---|
503 | for (int i = 0; i < eventCoverageQuantileGroups.length; i++) { |
---|
504 | sortedSmells.add(new HashMap<String, List<UsabilitySmell>>()); |
---|
505 | } |
---|
506 | |
---|
507 | for (UsabilitySmell smell : smells) { |
---|
508 | int eventCoverageQuantile = smell.getIntensity().getEventCoverageQuantile(); |
---|
509 | |
---|
510 | for (int i = 0; i < eventCoverageQuantileGroups.length; i++) { |
---|
511 | if (eventCoverageQuantile >= eventCoverageQuantileGroups[i]) { |
---|
512 | Map<String, List<UsabilitySmell>> smellMap = sortedSmells.get(i); |
---|
513 | |
---|
514 | List<UsabilitySmell> smellList = smellMap.get(smell.getBriefDescription()); |
---|
515 | |
---|
516 | if (smellList == null) { |
---|
517 | smellList = new ArrayList<UsabilitySmell>(); |
---|
518 | smellMap.put(smell.getBriefDescription(), smellList); |
---|
519 | } |
---|
520 | |
---|
521 | int ratio = smell.getIntensity().getRatio(); |
---|
522 | int eventCoverage = smell.getIntensity().getEventCoverage(); |
---|
523 | int index = 0; |
---|
524 | for (index = 0; index < smellList.size(); index++) { |
---|
525 | UsabilitySmellIntensity candidate = smellList.get(index).getIntensity(); |
---|
526 | if ((ratio == candidate.getRatio()) && |
---|
527 | (eventCoverage > candidate.getEventCoverage())) |
---|
528 | { |
---|
529 | break; |
---|
530 | } |
---|
531 | else if (ratio > candidate.getRatio()) { |
---|
532 | break; |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | smellList.add(index, smell); |
---|
537 | |
---|
538 | if (minEventCoverages[i] == 0) { |
---|
539 | minEventCoverages[i] = smell.getIntensity().getEventCoverage(); |
---|
540 | maxEventCoverages[i] = smell.getIntensity().getEventCoverage(); |
---|
541 | } |
---|
542 | else { |
---|
543 | minEventCoverages[i] = Math.min |
---|
544 | (minEventCoverages[i], smell.getIntensity().getEventCoverage()); |
---|
545 | maxEventCoverages[i] = Math.max |
---|
546 | (maxEventCoverages[i], smell.getIntensity().getEventCoverage()); |
---|
547 | } |
---|
548 | |
---|
549 | break; |
---|
550 | } |
---|
551 | } |
---|
552 | } |
---|
553 | |
---|
554 | if (smellList.getListeners(SWT.Expand).length == 0) { |
---|
555 | smellList.addListener(SWT.Expand, new Listener() { |
---|
556 | public void handleEvent(final Event event) { |
---|
557 | ensureChildren((TreeItem) event.item); |
---|
558 | ((TreeItem) event.item).setExpanded(true); |
---|
559 | } |
---|
560 | }); |
---|
561 | } |
---|
562 | |
---|
563 | double taskPercentages = 0; |
---|
564 | double taskPercentagesCoveredByPreceedingGroups = 0; |
---|
565 | |
---|
566 | for (int i = 0; i < eventCoverageQuantileGroups.length; i++) { |
---|
567 | taskPercentages = ((1000 - eventCoverageQuantileGroups[i]) / 10.0) - |
---|
568 | taskPercentagesCoveredByPreceedingGroups; |
---|
569 | |
---|
570 | if (eventCoverageQuantileGroups[i] > -1) { |
---|
571 | createRootItem("smells for " + taskPercentages + "% of tasks covering " + |
---|
572 | minEventCoverages[i] + " to " + maxEventCoverages[i] + |
---|
573 | " recorded events", sortedSmells.get(i)); |
---|
574 | } |
---|
575 | else { |
---|
576 | createRootItem("other smells not related to specific tasks", sortedSmells.get(i)); |
---|
577 | |
---|
578 | } |
---|
579 | |
---|
580 | taskPercentagesCoveredByPreceedingGroups += taskPercentages; |
---|
581 | } |
---|
582 | |
---|
583 | } |
---|
584 | |
---|
585 | /** |
---|
586 | * |
---|
587 | */ |
---|
588 | private void createRootItem(String name, Map<String, List<UsabilitySmell>> smells) { |
---|
589 | TreeItem smellItem = new TreeItem(smellList, SWT.NULL); |
---|
590 | |
---|
591 | int count = 0; |
---|
592 | for (Map.Entry<String, List<UsabilitySmell>> entry : smells.entrySet()) { |
---|
593 | count += entry.getValue().size(); |
---|
594 | } |
---|
595 | |
---|
596 | smellItem.setText(name + " (" + count + " smells)"); |
---|
597 | smellItem.setData(smells); |
---|
598 | |
---|
599 | if (count > 0) { |
---|
600 | // simulate a child |
---|
601 | new TreeItem(smellItem, SWT.NULL); |
---|
602 | } |
---|
603 | } |
---|
604 | |
---|
605 | /** |
---|
606 | * |
---|
607 | */ |
---|
608 | private void clearSmellDetails() { |
---|
609 | description.setText(""); |
---|
610 | involvedTargetsTree.removeAll(); |
---|
611 | involvedTasks.removeAll(); |
---|
612 | |
---|
613 | for (Control child : assessmentRadioButtons.getChildren()) { |
---|
614 | if (child instanceof Button) { |
---|
615 | child.setEnabled(false); |
---|
616 | ((Button) child).setSelection(false); |
---|
617 | } |
---|
618 | } |
---|
619 | |
---|
620 | for (Control child : tagCheckBoxParent.getChildren()) { |
---|
621 | if (child instanceof Button) { |
---|
622 | child.setEnabled(false); |
---|
623 | ((Button) child).setSelection(false); |
---|
624 | } |
---|
625 | } |
---|
626 | } |
---|
627 | |
---|
628 | /** |
---|
629 | * |
---|
630 | */ |
---|
631 | private void displaySmellDetails(UsabilitySmell smell) { |
---|
632 | clearSmellDetails(); |
---|
633 | |
---|
634 | FontData data = description.getFont().getFontData()[0]; |
---|
635 | int height = (int) (data.getHeight() * 1.5); |
---|
636 | Font defaultFont = new Font |
---|
637 | (description.getDisplay(), data.getName(), height, data.getStyle()); |
---|
638 | |
---|
639 | Font boldFont = new Font |
---|
640 | (description.getDisplay(), data.getName(), height, data.getStyle() | SWT.BOLD); |
---|
641 | |
---|
642 | for (Object fragment : smell.getDescriptionFragments()) { |
---|
643 | int color; |
---|
644 | Font font; |
---|
645 | |
---|
646 | if (fragment instanceof String) { |
---|
647 | color = SWT.COLOR_BLACK; |
---|
648 | font = defaultFont; |
---|
649 | } |
---|
650 | else { |
---|
651 | color = SWT.COLOR_DARK_GREEN; |
---|
652 | font = boldFont; |
---|
653 | } |
---|
654 | |
---|
655 | int initialLength = description.getText().length(); |
---|
656 | |
---|
657 | if (fragment instanceof Collection<?>) { |
---|
658 | int counter = 1; |
---|
659 | for (Object elem : ((Collection<?>) fragment)) { |
---|
660 | description.append("\n"); |
---|
661 | description.append(Integer.toString(counter++)); |
---|
662 | description.append(".: "); |
---|
663 | description.append(elem.toString()); |
---|
664 | } |
---|
665 | } |
---|
666 | else { |
---|
667 | description.append(fragment.toString()); |
---|
668 | } |
---|
669 | |
---|
670 | StyleRange styleRange = new StyleRange |
---|
671 | (initialLength, description.getText().length() - initialLength, |
---|
672 | description.getDisplay().getSystemColor(color), null); |
---|
673 | |
---|
674 | styleRange.font = font; |
---|
675 | |
---|
676 | description.setStyleRange(styleRange); |
---|
677 | description.append(" "); |
---|
678 | } |
---|
679 | description.setLeftMargin(50); |
---|
680 | description.setRightMargin(50); |
---|
681 | description.setTopMargin(50); |
---|
682 | description.setBottomMargin(50); |
---|
683 | |
---|
684 | |
---|
685 | StyleRange styleRange = new StyleRange(); |
---|
686 | styleRange.font = new Font(description.getDisplay(), "Courier", 12, SWT.NORMAL); |
---|
687 | description.setStyleRange(styleRange); |
---|
688 | |
---|
689 | assessmentRadioButtons.getChildren()[0].setEnabled(true); |
---|
690 | ((Button) assessmentRadioButtons.getChildren()[0]).setSelection |
---|
691 | (smell.getManualLabel() == ManualLabel.UNCHECKED); |
---|
692 | |
---|
693 | assessmentRadioButtons.getChildren()[1].setEnabled(true); |
---|
694 | ((Button) assessmentRadioButtons.getChildren()[1]).setSelection |
---|
695 | (smell.getManualLabel() == ManualLabel.FALSE_POSITIVE); |
---|
696 | |
---|
697 | assessmentRadioButtons.getChildren()[2].setEnabled(true); |
---|
698 | ((Button) assessmentRadioButtons.getChildren()[2]).setSelection |
---|
699 | (smell.getManualLabel() == ManualLabel.TRUE_POSITIVE); |
---|
700 | |
---|
701 | for (Control child : tagCheckBoxParent.getChildren()) { |
---|
702 | if (child instanceof Button) { |
---|
703 | child.setEnabled(true); |
---|
704 | ((Button) child).setSelection(smell.getTags().contains(((Button) child).getText())); |
---|
705 | } |
---|
706 | } |
---|
707 | |
---|
708 | List<ITask> involvedTaskList = getInvolvedTasks(smell); |
---|
709 | for (ITask involvedTask : involvedTaskList) { |
---|
710 | VisualizationUtils.createTreeItemFor |
---|
711 | (involvedTask, involvedTasks, usabilityEvalResult.getTaskModel(), true); |
---|
712 | } |
---|
713 | |
---|
714 | List<IEventTarget> involvedTargets = getInvolvedTargets(smell); |
---|
715 | if (involvedTargets.size() <= 0) { |
---|
716 | for (ITask involvedTask : involvedTaskList) { |
---|
717 | VisualizationUtils.getInvolvedTargets(involvedTask, involvedTargets); |
---|
718 | } |
---|
719 | } |
---|
720 | |
---|
721 | VisualizationUtils.addInvolvedTargets(involvedTargetsTree, involvedTargets); |
---|
722 | |
---|
723 | int weightLeft = involvedTaskList.size() == 0 ? 1 : |
---|
724 | Math.min(4, Math.max(3, involvedTaskList.size())); |
---|
725 | int weightRight = involvedTargets.size() == 0 ? 1 : |
---|
726 | Math.min(3, Math.max(1, involvedTargets.size())); |
---|
727 | ((SashForm) involvedTasks.getParent()).setWeights(new int[] { weightLeft, weightRight }); |
---|
728 | |
---|
729 | VisualizationUtils.expandAll(involvedTasks, true); |
---|
730 | VisualizationUtils.updateColumnWidths(involvedTasks); |
---|
731 | } |
---|
732 | |
---|
733 | /** |
---|
734 | * |
---|
735 | */ |
---|
736 | private void ensureChildren(TreeItem parent) { |
---|
737 | if ((parent.getItemCount() == 0) || (parent.getItems()[0].getData() != null)) { |
---|
738 | return; |
---|
739 | } |
---|
740 | |
---|
741 | for (int i = 0; i < parent.getItems().length; i++) { |
---|
742 | parent.getItems()[i].dispose(); |
---|
743 | } |
---|
744 | |
---|
745 | if (parent.getData() instanceof Map<?, ?>) { |
---|
746 | @SuppressWarnings("unchecked") |
---|
747 | Map<String, List<UsabilitySmell>> map = |
---|
748 | (Map<String, List<UsabilitySmell>>) parent.getData(); |
---|
749 | |
---|
750 | for (Map.Entry<String, List<UsabilitySmell>> entry : map.entrySet()) { |
---|
751 | TreeItem child = new TreeItem(parent, SWT.NULL); |
---|
752 | child.setText(entry.getKey() + " (" + entry.getValue().size() + " smells)"); |
---|
753 | child.setData(entry); |
---|
754 | |
---|
755 | if (entry.getValue().size() > 0) { |
---|
756 | // simulate child |
---|
757 | new TreeItem(child, SWT.NULL); |
---|
758 | } |
---|
759 | } |
---|
760 | } |
---|
761 | else if (parent.getData() instanceof Map.Entry<?, ?>) { |
---|
762 | @SuppressWarnings("unchecked") |
---|
763 | Map.Entry<String, List<UsabilitySmell>> entry = |
---|
764 | (Map.Entry<String, List<UsabilitySmell>>) parent.getData(); |
---|
765 | |
---|
766 | int count = 0; |
---|
767 | for (UsabilitySmell smell : entry.getValue()) { |
---|
768 | TreeItem child = new TreeItem(parent, SWT.NULL); |
---|
769 | child.setData(smell); |
---|
770 | child.setText(++count + ": ratio = " + smell.getIntensity().getRatio() + |
---|
771 | ", covered events = " + smell.getIntensity().getEventCoverage()); |
---|
772 | } |
---|
773 | } |
---|
774 | else if (parent.getData() instanceof ITask) { |
---|
775 | ITask task = (ITask) parent.getData(); |
---|
776 | |
---|
777 | if (task instanceof IStructuringTemporalRelationship) { |
---|
778 | for (ITask subTask : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
779 | VisualizationUtils.createTreeItemFor |
---|
780 | (subTask, parent, usabilityEvalResult.getTaskModel(), true); |
---|
781 | } |
---|
782 | } |
---|
783 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
784 | VisualizationUtils.createTreeItemFor |
---|
785 | (((IMarkingTemporalRelationship) task).getMarkedTask(), parent, |
---|
786 | usabilityEvalResult.getTaskModel(), true); |
---|
787 | } |
---|
788 | } |
---|
789 | } |
---|
790 | |
---|
791 | /** |
---|
792 | * |
---|
793 | */ |
---|
794 | private List<ITask> getInvolvedTasks(UsabilitySmell smell) { |
---|
795 | List<Object> fragments = smell.getDescriptionFragments(); |
---|
796 | List<ITask> involvedTasks = new ArrayList<ITask>(); |
---|
797 | |
---|
798 | for (Object fragment : fragments) { |
---|
799 | if (fragment instanceof ITask) { |
---|
800 | involvedTasks.add((ITask) fragment); |
---|
801 | } |
---|
802 | } |
---|
803 | |
---|
804 | return involvedTasks; |
---|
805 | } |
---|
806 | |
---|
807 | /** |
---|
808 | * |
---|
809 | */ |
---|
810 | private List<IEventTarget> getInvolvedTargets(UsabilitySmell smell) { |
---|
811 | List<Object> fragments = smell.getDescriptionFragments(); |
---|
812 | List<IEventTarget> involvedTargets = new ArrayList<IEventTarget>(); |
---|
813 | |
---|
814 | for (Object fragment : fragments) { |
---|
815 | if (fragment instanceof IEventTarget) { |
---|
816 | involvedTargets.add((IEventTarget) fragment); |
---|
817 | } |
---|
818 | else if (fragment instanceof Collection<?>) { |
---|
819 | for (Object elem : (Collection<?>) fragment) { |
---|
820 | if (elem instanceof IEventTarget) { |
---|
821 | involvedTargets.add((IEventTarget) elem); |
---|
822 | } |
---|
823 | } |
---|
824 | } |
---|
825 | } |
---|
826 | |
---|
827 | return involvedTargets; |
---|
828 | } |
---|
829 | } |
---|