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.HORIZONTAL); |
---|
179 | treeColumn.setWidth(300); |
---|
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 | VisualizationUtils.updateColumnWidths(smellList); |
---|
198 | } |
---|
199 | }); |
---|
200 | |
---|
201 | |
---|
202 | SashForm detailsSashForm = new SashForm(mainSashForm, SWT.VERTICAL); |
---|
203 | detailsSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
204 | |
---|
205 | Composite descriptionComposite = new Composite(detailsSashForm, SWT.NONE); |
---|
206 | descriptionComposite.setLayout(new GridLayout()); |
---|
207 | |
---|
208 | description = new StyledText(descriptionComposite, SWT.READ_ONLY | SWT.BORDER | SWT.WRAP); |
---|
209 | description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
210 | |
---|
211 | SashForm detailsTreesSashForm = new SashForm(detailsSashForm, SWT.HORIZONTAL); |
---|
212 | detailsTreesSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
213 | |
---|
214 | involvedTasks = VisualizationUtils.createTaskDetailsTree |
---|
215 | (detailsTreesSashForm, "involved tasks", usabilityEvalResult.getTaskModel()); |
---|
216 | |
---|
217 | VisualizationUtils.addItemSpecificContextMenu |
---|
218 | (involvedTasks, ITask.class, "show details", new SelectionAdapter() |
---|
219 | { |
---|
220 | @Override |
---|
221 | public void widgetSelected(SelectionEvent e) { |
---|
222 | showTaskTreeDialog.open((ITask) involvedTasks.getSelection()[0].getData()); |
---|
223 | } |
---|
224 | }); |
---|
225 | |
---|
226 | VisualizationUtils.addExpansionListener(involvedTasks, new Listener() { |
---|
227 | public void handleEvent(final Event event) { |
---|
228 | ensureChildren((TreeItem) event.item); |
---|
229 | ((TreeItem) event.item).setExpanded(true); |
---|
230 | } |
---|
231 | }); |
---|
232 | |
---|
233 | involvedTargetsTree = |
---|
234 | VisualizationUtils.createTargetsTree(detailsTreesSashForm, "involved GUI elements"); |
---|
235 | |
---|
236 | VisualizationUtils.addInvolvedTargetsHighlighting(involvedTasks, involvedTargetsTree); |
---|
237 | |
---|
238 | final Composite detailsAssessmentComposite = new Composite(descriptionComposite, SWT.NONE); |
---|
239 | detailsAssessmentComposite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false, 1, 1)); |
---|
240 | detailsAssessmentComposite.setLayout(new GridLayout(5, false)); |
---|
241 | |
---|
242 | assessmentRadioButtons = new Group(detailsAssessmentComposite, SWT.NONE); |
---|
243 | assessmentRadioButtons.setLayout(new RowLayout(SWT.HORIZONTAL)); |
---|
244 | |
---|
245 | final Button unassessedRadioButton = new Button(assessmentRadioButtons, SWT.RADIO); |
---|
246 | unassessedRadioButton.setText("unassessed"); |
---|
247 | unassessedRadioButton.addSelectionListener(new SelectionAdapter() { |
---|
248 | @Override |
---|
249 | public void widgetSelected(SelectionEvent event) { |
---|
250 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
251 | if ((selectedItems.length == 1) && |
---|
252 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
253 | { |
---|
254 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
255 | if (unassessedRadioButton.getSelection()) { |
---|
256 | smell.setManualLabel(ManualLabel.UNCHECKED); |
---|
257 | } |
---|
258 | } |
---|
259 | } |
---|
260 | }); |
---|
261 | |
---|
262 | final Button falsePositiveRadioButton = new Button(assessmentRadioButtons, SWT.RADIO); |
---|
263 | falsePositiveRadioButton.setText("false positive"); |
---|
264 | falsePositiveRadioButton.addSelectionListener(new SelectionAdapter() { |
---|
265 | @Override |
---|
266 | public void widgetSelected(SelectionEvent event) { |
---|
267 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
268 | if ((selectedItems.length == 1) && |
---|
269 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
270 | { |
---|
271 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
272 | if (falsePositiveRadioButton.getSelection()) { |
---|
273 | smell.setManualLabel(ManualLabel.FALSE_POSITIVE); |
---|
274 | } |
---|
275 | } |
---|
276 | } |
---|
277 | }); |
---|
278 | |
---|
279 | final Button truePositiveRadioButton = new Button(assessmentRadioButtons, SWT.RADIO); |
---|
280 | truePositiveRadioButton.setText("true positive"); |
---|
281 | truePositiveRadioButton.addSelectionListener(new SelectionAdapter() { |
---|
282 | @Override |
---|
283 | public void widgetSelected(SelectionEvent event) { |
---|
284 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
285 | if ((selectedItems.length == 1) && |
---|
286 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
287 | { |
---|
288 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
289 | if (truePositiveRadioButton.getSelection()) { |
---|
290 | smell.setManualLabel(ManualLabel.TRUE_POSITIVE); |
---|
291 | } |
---|
292 | } |
---|
293 | } |
---|
294 | }); |
---|
295 | |
---|
296 | new Label(detailsAssessmentComposite, SWT.NONE).setText("Tags:"); |
---|
297 | |
---|
298 | tagCheckBoxParent = new Composite(detailsAssessmentComposite, SWT.NONE); |
---|
299 | tagCheckBoxParent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); |
---|
300 | tagCheckBoxParent.setLayout(new RowLayout()); |
---|
301 | |
---|
302 | recreateTagsSashForm(); |
---|
303 | |
---|
304 | final Text addTagField = new Text(detailsAssessmentComposite, SWT.BORDER); |
---|
305 | addTagField.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
---|
306 | addTagField.setSize(addTagField.computeSize(100, 50)); |
---|
307 | |
---|
308 | final Button addTagButton = new Button(detailsAssessmentComposite, SWT.NONE); |
---|
309 | addTagButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); |
---|
310 | addTagButton.addSelectionListener(new SelectionAdapter() { |
---|
311 | @Override |
---|
312 | public void widgetSelected(SelectionEvent e) { |
---|
313 | String tagName = addTagField.getText(); |
---|
314 | if ((tagName != null) && (!"".equals(tagName)) && (!existingTags.contains(tagName))) { |
---|
315 | existingTags.add(tagName); |
---|
316 | recreateTagsSashForm(); |
---|
317 | } |
---|
318 | } |
---|
319 | }); |
---|
320 | addTagButton.setText("add tag"); |
---|
321 | |
---|
322 | detailsTreesSashForm.setWeights(new int[] { 1, 1 }); |
---|
323 | detailsSashForm.setWeights(new int[] { 1, 3 }); |
---|
324 | mainSashForm.setWeights(new int[] { 1, 3 }); |
---|
325 | |
---|
326 | //indexColumn.pack(); |
---|
327 | //severityColumn.pack(); |
---|
328 | //descriptionColumn.pack(); |
---|
329 | //smellList.pack(); |
---|
330 | } |
---|
331 | |
---|
332 | /** |
---|
333 | * <p> |
---|
334 | * TODO: comment |
---|
335 | * </p> |
---|
336 | * |
---|
337 | */ |
---|
338 | private void recreateTagsSashForm() { |
---|
339 | for (Control child : tagCheckBoxParent.getChildren()) { |
---|
340 | child.dispose(); |
---|
341 | } |
---|
342 | |
---|
343 | if (existingTags.size() > 0) { |
---|
344 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
345 | boolean enabled = (selectedItems.length == 1) && |
---|
346 | (selectedItems[0].getData() instanceof UsabilitySmell); |
---|
347 | |
---|
348 | for (String existingTag : existingTags) { |
---|
349 | Button checkBox = new Button(tagCheckBoxParent, SWT.CHECK); |
---|
350 | checkBox.setText(existingTag); |
---|
351 | checkBox.addSelectionListener(new SelectionAdapter() { |
---|
352 | @Override |
---|
353 | public void widgetSelected(SelectionEvent event) { |
---|
354 | Button btn = (Button) event.getSource(); |
---|
355 | |
---|
356 | TreeItem[] selectedItems = smellList.getSelection(); |
---|
357 | if ((selectedItems.length == 1) && |
---|
358 | (selectedItems[0].getData() instanceof UsabilitySmell)) |
---|
359 | { |
---|
360 | UsabilitySmell smell = (UsabilitySmell) selectedItems[0].getData(); |
---|
361 | |
---|
362 | if (btn.getSelection()) { |
---|
363 | smell.addTag(btn.getText()); |
---|
364 | } |
---|
365 | else { |
---|
366 | smell.removeTag(btn.getText()); |
---|
367 | } |
---|
368 | } |
---|
369 | } |
---|
370 | }); |
---|
371 | |
---|
372 | checkBox.setEnabled(enabled); |
---|
373 | if (enabled) { |
---|
374 | checkBox.setSelection |
---|
375 | (((UsabilitySmell) selectedItems[0].getData()).getTags().contains(existingTag)); |
---|
376 | } |
---|
377 | } |
---|
378 | } |
---|
379 | else { |
---|
380 | new Label(tagCheckBoxParent, SWT.NONE).setText |
---|
381 | ("no tags added yet --> add using the text field and the button on the right"); |
---|
382 | } |
---|
383 | |
---|
384 | tagCheckBoxParent.layout(); |
---|
385 | tagCheckBoxParent.redraw(); |
---|
386 | } |
---|
387 | |
---|
388 | /** |
---|
389 | * convenience method for creating the display of the instances |
---|
390 | */ |
---|
391 | private void buildSmellTree() { |
---|
392 | int groupCount = 5; |
---|
393 | int groupSize = 30; |
---|
394 | |
---|
395 | List<UsabilitySmell> smells = usabilityEvalResult.getAllSmells(); |
---|
396 | |
---|
397 | final Map<String, List<UsabilitySmell>> sortedSmells = new HashMap<>(); |
---|
398 | |
---|
399 | for (UsabilitySmell smell : smells) { |
---|
400 | List<UsabilitySmell> smellList = sortedSmells.get(smell.getBriefDescription()); |
---|
401 | |
---|
402 | if (smellList == null) { |
---|
403 | smellList = new ArrayList<UsabilitySmell>(); |
---|
404 | sortedSmells.put(smell.getBriefDescription(), smellList); |
---|
405 | } |
---|
406 | |
---|
407 | ListIterator<UsabilitySmell> it = smellList.listIterator(); |
---|
408 | boolean added = false; |
---|
409 | |
---|
410 | while (it.hasNext()) { |
---|
411 | if (smell.getIntensity().getEventCoverage() > |
---|
412 | it.next().getIntensity().getEventCoverage()) |
---|
413 | { |
---|
414 | it.previous(); |
---|
415 | it.add(smell); |
---|
416 | added = true; |
---|
417 | break; |
---|
418 | } |
---|
419 | } |
---|
420 | |
---|
421 | if (!added) { |
---|
422 | smellList.add(smell); |
---|
423 | } |
---|
424 | |
---|
425 | // extract the intial list of tags of the smells |
---|
426 | for (String tag : smell.getTags()) { |
---|
427 | if (!existingTags.contains(tag)) { |
---|
428 | existingTags.add(tag); |
---|
429 | } |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | final Map<Integer, Map<String, List<UsabilitySmell>>> allSortedSmells = |
---|
434 | new HashMap<Integer, Map<String, List<UsabilitySmell>>>(); |
---|
435 | |
---|
436 | for (Map.Entry<String, List<UsabilitySmell>> entry : sortedSmells.entrySet()) { |
---|
437 | // we create groupCount groups of size groupSize |
---|
438 | int overallIndex = 0; |
---|
439 | |
---|
440 | for (int i = 0; i < groupCount; i++) { |
---|
441 | List<UsabilitySmell> smellList = new LinkedList<>(); |
---|
442 | for (int j = 0; overallIndex < entry.getValue().size() && |
---|
443 | ((j < groupSize) || (i == (groupCount - 1))); j++) |
---|
444 | { |
---|
445 | UsabilitySmell smell = entry.getValue().get(overallIndex++); |
---|
446 | |
---|
447 | int ratio = smell.getIntensity().getRatio(); |
---|
448 | int eventCoverage = smell.getIntensity().getEventCoverage(); |
---|
449 | int index = 0; |
---|
450 | for (index = 0; index < smellList.size(); index++) { |
---|
451 | UsabilitySmellIntensity candidate = smellList.get(index).getIntensity(); |
---|
452 | if ((ratio == candidate.getRatio()) && |
---|
453 | (eventCoverage > candidate.getEventCoverage())) |
---|
454 | { |
---|
455 | break; |
---|
456 | } |
---|
457 | else if (ratio > candidate.getRatio()) { |
---|
458 | break; |
---|
459 | } |
---|
460 | } |
---|
461 | |
---|
462 | smellList.add(index, smell); |
---|
463 | } |
---|
464 | |
---|
465 | if (smellList.size() > 0) { |
---|
466 | Map<String, List<UsabilitySmell>> smellGroups = allSortedSmells.get(i); |
---|
467 | |
---|
468 | if (smellGroups == null) { |
---|
469 | smellGroups = new HashMap<>(); |
---|
470 | allSortedSmells.put(i, smellGroups); |
---|
471 | } |
---|
472 | |
---|
473 | smellGroups.put(entry.getKey(), smellList); |
---|
474 | } |
---|
475 | } |
---|
476 | } |
---|
477 | |
---|
478 | if (smellList.getListeners(SWT.Expand).length == 0) { |
---|
479 | smellList.addListener(SWT.Expand, new Listener() { |
---|
480 | public void handleEvent(final Event event) { |
---|
481 | ensureChildren((TreeItem) event.item); |
---|
482 | ((TreeItem) event.item).setExpanded(true); |
---|
483 | VisualizationUtils.updateColumnWidths(smellList); |
---|
484 | } |
---|
485 | }); |
---|
486 | } |
---|
487 | |
---|
488 | for (int i = 0; i < allSortedSmells.size(); i++) { |
---|
489 | createRootItem("smells group " + (i + 1), allSortedSmells.get(i)); |
---|
490 | } |
---|
491 | |
---|
492 | } |
---|
493 | |
---|
494 | /** |
---|
495 | * convenience method for creating the display of the instances |
---|
496 | */ |
---|
497 | /*private void buildSmellTree() { |
---|
498 | List<UsabilitySmell> smells = usabilityEvalResult.getAllSmells(); |
---|
499 | |
---|
500 | int[] eventCoverageQuantileGroups = { 990, 975, 950, 0, -1 }; |
---|
501 | int[] minEventCoverages = new int[eventCoverageQuantileGroups.length]; |
---|
502 | int[] maxEventCoverages = new int[eventCoverageQuantileGroups.length]; |
---|
503 | |
---|
504 | final List<Map<String, List<UsabilitySmell>>> sortedSmells = |
---|
505 | new LinkedList<Map<String, List<UsabilitySmell>>>(); |
---|
506 | |
---|
507 | for (int i = 0; i < eventCoverageQuantileGroups.length; i++) { |
---|
508 | sortedSmells.add(new HashMap<String, List<UsabilitySmell>>()); |
---|
509 | } |
---|
510 | |
---|
511 | for (UsabilitySmell smell : smells) { |
---|
512 | int eventCoverageQuantile = smell.getIntensity().getEventCoverageQuantile(); |
---|
513 | |
---|
514 | for (int i = 0; i < eventCoverageQuantileGroups.length; i++) { |
---|
515 | if (eventCoverageQuantile >= eventCoverageQuantileGroups[i]) { |
---|
516 | Map<String, List<UsabilitySmell>> smellMap = sortedSmells.get(i); |
---|
517 | |
---|
518 | List<UsabilitySmell> smellList = smellMap.get(smell.getBriefDescription()); |
---|
519 | |
---|
520 | if (smellList == null) { |
---|
521 | smellList = new ArrayList<UsabilitySmell>(); |
---|
522 | smellMap.put(smell.getBriefDescription(), smellList); |
---|
523 | } |
---|
524 | |
---|
525 | int ratio = smell.getIntensity().getRatio(); |
---|
526 | int eventCoverage = smell.getIntensity().getEventCoverage(); |
---|
527 | int index = 0; |
---|
528 | for (index = 0; index < smellList.size(); index++) { |
---|
529 | UsabilitySmellIntensity candidate = smellList.get(index).getIntensity(); |
---|
530 | if ((ratio == candidate.getRatio()) && |
---|
531 | (eventCoverage > candidate.getEventCoverage())) |
---|
532 | { |
---|
533 | break; |
---|
534 | } |
---|
535 | else if (ratio > candidate.getRatio()) { |
---|
536 | break; |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | smellList.add(index, smell); |
---|
541 | |
---|
542 | if (minEventCoverages[i] == 0) { |
---|
543 | minEventCoverages[i] = smell.getIntensity().getEventCoverage(); |
---|
544 | maxEventCoverages[i] = smell.getIntensity().getEventCoverage(); |
---|
545 | } |
---|
546 | else { |
---|
547 | minEventCoverages[i] = Math.min |
---|
548 | (minEventCoverages[i], smell.getIntensity().getEventCoverage()); |
---|
549 | maxEventCoverages[i] = Math.max |
---|
550 | (maxEventCoverages[i], smell.getIntensity().getEventCoverage()); |
---|
551 | } |
---|
552 | |
---|
553 | break; |
---|
554 | } |
---|
555 | } |
---|
556 | } |
---|
557 | |
---|
558 | if (smellList.getListeners(SWT.Expand).length == 0) { |
---|
559 | smellList.addListener(SWT.Expand, new Listener() { |
---|
560 | public void handleEvent(final Event event) { |
---|
561 | ensureChildren((TreeItem) event.item); |
---|
562 | ((TreeItem) event.item).setExpanded(true); |
---|
563 | } |
---|
564 | }); |
---|
565 | } |
---|
566 | |
---|
567 | double taskPercentages = 0; |
---|
568 | double taskPercentagesCoveredByPreceedingGroups = 0; |
---|
569 | |
---|
570 | for (int i = 0; i < eventCoverageQuantileGroups.length; i++) { |
---|
571 | taskPercentages = ((1000 - eventCoverageQuantileGroups[i]) / 10.0) - |
---|
572 | taskPercentagesCoveredByPreceedingGroups; |
---|
573 | |
---|
574 | if (eventCoverageQuantileGroups[i] > -1) { |
---|
575 | createRootItem("smells for " + taskPercentages + "% of tasks covering " + |
---|
576 | minEventCoverages[i] + " to " + maxEventCoverages[i] + |
---|
577 | " recorded events", sortedSmells.get(i)); |
---|
578 | } |
---|
579 | else { |
---|
580 | createRootItem("other smells not related to specific tasks", sortedSmells.get(i)); |
---|
581 | |
---|
582 | } |
---|
583 | |
---|
584 | taskPercentagesCoveredByPreceedingGroups += taskPercentages; |
---|
585 | } |
---|
586 | |
---|
587 | } |
---|
588 | |
---|
589 | /** |
---|
590 | * |
---|
591 | */ |
---|
592 | private void createRootItem(String name, Map<String, List<UsabilitySmell>> smells) { |
---|
593 | TreeItem smellItem = new TreeItem(smellList, SWT.NULL); |
---|
594 | |
---|
595 | int count = 0; |
---|
596 | for (Map.Entry<String, List<UsabilitySmell>> entry : smells.entrySet()) { |
---|
597 | count += entry.getValue().size(); |
---|
598 | } |
---|
599 | |
---|
600 | smellItem.setText(name + " (" + count + " smells)"); |
---|
601 | smellItem.setData(smells); |
---|
602 | |
---|
603 | if (count > 0) { |
---|
604 | // simulate a child |
---|
605 | new TreeItem(smellItem, SWT.NULL); |
---|
606 | } |
---|
607 | } |
---|
608 | |
---|
609 | /** |
---|
610 | * |
---|
611 | */ |
---|
612 | private void clearSmellDetails() { |
---|
613 | description.setText(""); |
---|
614 | involvedTargetsTree.removeAll(); |
---|
615 | involvedTasks.removeAll(); |
---|
616 | |
---|
617 | for (Control child : assessmentRadioButtons.getChildren()) { |
---|
618 | if (child instanceof Button) { |
---|
619 | child.setEnabled(false); |
---|
620 | ((Button) child).setSelection(false); |
---|
621 | } |
---|
622 | } |
---|
623 | |
---|
624 | for (Control child : tagCheckBoxParent.getChildren()) { |
---|
625 | if (child instanceof Button) { |
---|
626 | child.setEnabled(false); |
---|
627 | ((Button) child).setSelection(false); |
---|
628 | } |
---|
629 | } |
---|
630 | } |
---|
631 | |
---|
632 | /** |
---|
633 | * |
---|
634 | */ |
---|
635 | private void displaySmellDetails(UsabilitySmell smell) { |
---|
636 | clearSmellDetails(); |
---|
637 | |
---|
638 | FontData data = description.getFont().getFontData()[0]; |
---|
639 | int height = (int) (data.getHeight() * 1.5); |
---|
640 | Font defaultFont = new Font |
---|
641 | (description.getDisplay(), data.getName(), height, data.getStyle()); |
---|
642 | |
---|
643 | Font boldFont = new Font |
---|
644 | (description.getDisplay(), data.getName(), height, data.getStyle() | SWT.BOLD); |
---|
645 | |
---|
646 | for (Object fragment : smell.getDescriptionFragments()) { |
---|
647 | int color; |
---|
648 | Font font; |
---|
649 | |
---|
650 | if (fragment instanceof String) { |
---|
651 | color = SWT.COLOR_BLACK; |
---|
652 | font = defaultFont; |
---|
653 | } |
---|
654 | else { |
---|
655 | color = SWT.COLOR_DARK_GREEN; |
---|
656 | font = boldFont; |
---|
657 | } |
---|
658 | |
---|
659 | int initialLength = description.getText().length(); |
---|
660 | |
---|
661 | if (fragment instanceof Collection<?>) { |
---|
662 | int counter = 1; |
---|
663 | for (Object elem : ((Collection<?>) fragment)) { |
---|
664 | description.append("\n"); |
---|
665 | description.append(Integer.toString(counter++)); |
---|
666 | description.append(".: "); |
---|
667 | description.append(elem.toString()); |
---|
668 | } |
---|
669 | } |
---|
670 | else { |
---|
671 | description.append(fragment.toString()); |
---|
672 | } |
---|
673 | |
---|
674 | StyleRange styleRange = new StyleRange |
---|
675 | (initialLength, description.getText().length() - initialLength, |
---|
676 | description.getDisplay().getSystemColor(color), null); |
---|
677 | |
---|
678 | styleRange.font = font; |
---|
679 | |
---|
680 | description.setStyleRange(styleRange); |
---|
681 | description.append(" "); |
---|
682 | } |
---|
683 | description.setLeftMargin(50); |
---|
684 | description.setRightMargin(50); |
---|
685 | description.setTopMargin(50); |
---|
686 | description.setBottomMargin(50); |
---|
687 | |
---|
688 | |
---|
689 | StyleRange styleRange = new StyleRange(); |
---|
690 | styleRange.font = new Font(description.getDisplay(), "Courier", 12, SWT.NORMAL); |
---|
691 | description.setStyleRange(styleRange); |
---|
692 | |
---|
693 | assessmentRadioButtons.getChildren()[0].setEnabled(true); |
---|
694 | ((Button) assessmentRadioButtons.getChildren()[0]).setSelection |
---|
695 | (smell.getManualLabel() == ManualLabel.UNCHECKED); |
---|
696 | |
---|
697 | assessmentRadioButtons.getChildren()[1].setEnabled(true); |
---|
698 | ((Button) assessmentRadioButtons.getChildren()[1]).setSelection |
---|
699 | (smell.getManualLabel() == ManualLabel.FALSE_POSITIVE); |
---|
700 | |
---|
701 | assessmentRadioButtons.getChildren()[2].setEnabled(true); |
---|
702 | ((Button) assessmentRadioButtons.getChildren()[2]).setSelection |
---|
703 | (smell.getManualLabel() == ManualLabel.TRUE_POSITIVE); |
---|
704 | |
---|
705 | for (Control child : tagCheckBoxParent.getChildren()) { |
---|
706 | if (child instanceof Button) { |
---|
707 | child.setEnabled(true); |
---|
708 | ((Button) child).setSelection(smell.getTags().contains(((Button) child).getText())); |
---|
709 | } |
---|
710 | } |
---|
711 | |
---|
712 | List<ITask> involvedTaskList = getInvolvedTasks(smell); |
---|
713 | for (ITask involvedTask : involvedTaskList) { |
---|
714 | VisualizationUtils.createTreeItemFor |
---|
715 | (involvedTask, involvedTasks, usabilityEvalResult.getTaskModel(), true); |
---|
716 | } |
---|
717 | |
---|
718 | List<IEventTarget> involvedTargets = getInvolvedTargets(smell); |
---|
719 | if (involvedTargets.size() <= 0) { |
---|
720 | for (ITask involvedTask : involvedTaskList) { |
---|
721 | VisualizationUtils.getInvolvedTargets(involvedTask, involvedTargets); |
---|
722 | } |
---|
723 | } |
---|
724 | |
---|
725 | VisualizationUtils.addInvolvedTargets(involvedTargetsTree, involvedTargets); |
---|
726 | |
---|
727 | int weightLeft = involvedTaskList.size() == 0 ? 1 : |
---|
728 | Math.min(4, Math.max(3, involvedTaskList.size())); |
---|
729 | int weightRight = involvedTargets.size() == 0 ? 1 : |
---|
730 | Math.min(3, Math.max(1, involvedTargets.size())); |
---|
731 | ((SashForm) involvedTasks.getParent()).setWeights(new int[] { weightLeft, weightRight }); |
---|
732 | |
---|
733 | VisualizationUtils.expandAll(involvedTasks, true); |
---|
734 | VisualizationUtils.updateColumnWidths(involvedTasks); |
---|
735 | } |
---|
736 | |
---|
737 | /** |
---|
738 | * |
---|
739 | */ |
---|
740 | private void ensureChildren(TreeItem parent) { |
---|
741 | if ((parent.getItemCount() == 0) || (parent.getItems()[0].getData() != null)) { |
---|
742 | return; |
---|
743 | } |
---|
744 | |
---|
745 | for (int i = 0; i < parent.getItems().length; i++) { |
---|
746 | parent.getItems()[i].dispose(); |
---|
747 | } |
---|
748 | |
---|
749 | if (parent.getData() instanceof Map<?, ?>) { |
---|
750 | @SuppressWarnings("unchecked") |
---|
751 | Map<String, List<UsabilitySmell>> map = |
---|
752 | (Map<String, List<UsabilitySmell>>) parent.getData(); |
---|
753 | |
---|
754 | for (Map.Entry<String, List<UsabilitySmell>> entry : map.entrySet()) { |
---|
755 | TreeItem child = new TreeItem(parent, SWT.NULL); |
---|
756 | child.setText(entry.getKey() + " (" + entry.getValue().size() + " smells)"); |
---|
757 | child.setData(entry); |
---|
758 | |
---|
759 | if (entry.getValue().size() > 0) { |
---|
760 | // simulate child |
---|
761 | new TreeItem(child, SWT.NULL); |
---|
762 | } |
---|
763 | } |
---|
764 | } |
---|
765 | else if (parent.getData() instanceof Map.Entry<?, ?>) { |
---|
766 | @SuppressWarnings("unchecked") |
---|
767 | Map.Entry<String, List<UsabilitySmell>> entry = |
---|
768 | (Map.Entry<String, List<UsabilitySmell>>) parent.getData(); |
---|
769 | |
---|
770 | int count = 0; |
---|
771 | for (UsabilitySmell smell : entry.getValue()) { |
---|
772 | TreeItem child = new TreeItem(parent, SWT.NULL); |
---|
773 | child.setData(smell); |
---|
774 | child.setText(++count + ": ratio = " + smell.getIntensity().getRatio() + |
---|
775 | ", covered events = " + smell.getIntensity().getEventCoverage()); |
---|
776 | } |
---|
777 | } |
---|
778 | else if (parent.getData() instanceof ITask) { |
---|
779 | ITask task = (ITask) parent.getData(); |
---|
780 | |
---|
781 | if (task instanceof IStructuringTemporalRelationship) { |
---|
782 | for (ITask subTask : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
783 | VisualizationUtils.createTreeItemFor |
---|
784 | (subTask, parent, usabilityEvalResult.getTaskModel(), true); |
---|
785 | } |
---|
786 | } |
---|
787 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
788 | VisualizationUtils.createTreeItemFor |
---|
789 | (((IMarkingTemporalRelationship) task).getMarkedTask(), parent, |
---|
790 | usabilityEvalResult.getTaskModel(), true); |
---|
791 | } |
---|
792 | } |
---|
793 | } |
---|
794 | |
---|
795 | /** |
---|
796 | * |
---|
797 | */ |
---|
798 | private List<ITask> getInvolvedTasks(UsabilitySmell smell) { |
---|
799 | System.out.println(smell.getSmellingTask()); |
---|
800 | |
---|
801 | List<Object> fragments = smell.getDescriptionFragments(); |
---|
802 | List<ITask> involvedTasks = new ArrayList<ITask>(); |
---|
803 | |
---|
804 | for (Object fragment : fragments) { |
---|
805 | if (fragment instanceof ITask) { |
---|
806 | involvedTasks.add((ITask) fragment); |
---|
807 | } |
---|
808 | } |
---|
809 | |
---|
810 | return involvedTasks; |
---|
811 | } |
---|
812 | |
---|
813 | /** |
---|
814 | * |
---|
815 | */ |
---|
816 | private List<IEventTarget> getInvolvedTargets(UsabilitySmell smell) { |
---|
817 | List<Object> fragments = smell.getDescriptionFragments(); |
---|
818 | List<IEventTarget> involvedTargets = new ArrayList<IEventTarget>(); |
---|
819 | |
---|
820 | for (Object fragment : fragments) { |
---|
821 | if (fragment instanceof IEventTarget) { |
---|
822 | involvedTargets.add((IEventTarget) fragment); |
---|
823 | } |
---|
824 | else if (fragment instanceof Collection<?>) { |
---|
825 | for (Object elem : (Collection<?>) fragment) { |
---|
826 | if (elem instanceof IEventTarget) { |
---|
827 | involvedTargets.add((IEventTarget) elem); |
---|
828 | } |
---|
829 | } |
---|
830 | } |
---|
831 | } |
---|
832 | |
---|
833 | return involvedTargets; |
---|
834 | } |
---|
835 | } |
---|