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.Frame; |
---|
18 | import java.awt.GraphicsDevice; |
---|
19 | import java.awt.GraphicsEnvironment; |
---|
20 | import java.awt.Toolkit; |
---|
21 | import java.awt.datatransfer.Clipboard; |
---|
22 | import java.awt.datatransfer.StringSelection; |
---|
23 | import java.lang.reflect.Method; |
---|
24 | import java.util.ArrayList; |
---|
25 | import java.util.Collection; |
---|
26 | import java.util.Collections; |
---|
27 | import java.util.Comparator; |
---|
28 | import java.util.LinkedList; |
---|
29 | import java.util.List; |
---|
30 | |
---|
31 | import org.eclipse.swt.SWT; |
---|
32 | import org.eclipse.swt.awt.SWT_AWT; |
---|
33 | import org.eclipse.swt.custom.SashForm; |
---|
34 | import org.eclipse.swt.custom.StackLayout; |
---|
35 | import org.eclipse.swt.events.SelectionAdapter; |
---|
36 | import org.eclipse.swt.events.SelectionEvent; |
---|
37 | import org.eclipse.swt.events.ShellAdapter; |
---|
38 | import org.eclipse.swt.events.ShellEvent; |
---|
39 | import org.eclipse.swt.events.ShellListener; |
---|
40 | import org.eclipse.swt.graphics.Color; |
---|
41 | import org.eclipse.swt.layout.GridData; |
---|
42 | import org.eclipse.swt.layout.GridLayout; |
---|
43 | import org.eclipse.swt.widgets.Button; |
---|
44 | import org.eclipse.swt.widgets.Composite; |
---|
45 | import org.eclipse.swt.widgets.Control; |
---|
46 | import org.eclipse.swt.widgets.Dialog; |
---|
47 | import org.eclipse.swt.widgets.Display; |
---|
48 | import org.eclipse.swt.widgets.Event; |
---|
49 | import org.eclipse.swt.widgets.FileDialog; |
---|
50 | import org.eclipse.swt.widgets.Label; |
---|
51 | import org.eclipse.swt.widgets.Listener; |
---|
52 | import org.eclipse.swt.widgets.Menu; |
---|
53 | import org.eclipse.swt.widgets.MenuItem; |
---|
54 | import org.eclipse.swt.widgets.Shell; |
---|
55 | import org.eclipse.swt.widgets.TabFolder; |
---|
56 | import org.eclipse.swt.widgets.TabItem; |
---|
57 | import org.eclipse.swt.widgets.Tree; |
---|
58 | import org.eclipse.swt.widgets.TreeColumn; |
---|
59 | import org.eclipse.swt.widgets.TreeItem; |
---|
60 | import org.jfree.chart.ChartPanel; |
---|
61 | import org.jfree.chart.JFreeChart; |
---|
62 | |
---|
63 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
64 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; |
---|
65 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
66 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; |
---|
67 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
68 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
69 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
70 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
71 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
72 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
73 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; |
---|
74 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
75 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
76 | import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric; |
---|
77 | import de.ugoe.cs.util.console.Console; |
---|
78 | |
---|
79 | /** |
---|
80 | * <p> |
---|
81 | * a dialog to inspect the tasks and task instances of a task model |
---|
82 | * </p> |
---|
83 | * |
---|
84 | * @author Patrick Harms |
---|
85 | */ |
---|
86 | public class ShowTaskTreeDialog extends Dialog { |
---|
87 | |
---|
88 | /** the main shell */ |
---|
89 | private Shell shell; |
---|
90 | |
---|
91 | /** the listener for the main shell to prevent disposing required */ |
---|
92 | private ShellListener shellListener; |
---|
93 | |
---|
94 | /** the tab folder containing the instance tree, the model tree, and the visualizations list */ |
---|
95 | private TabFolder tabFolder; |
---|
96 | |
---|
97 | /** the tree of task instances on the left */ |
---|
98 | private Tree instanceTree; |
---|
99 | |
---|
100 | /** the tree of tasks on the left */ |
---|
101 | private Tree modelTree; |
---|
102 | |
---|
103 | /** the tree of possible visualizations on the left */ |
---|
104 | private Tree modelVisualizationTree; |
---|
105 | |
---|
106 | /** the right hand composite containing either task details or a visualization */ |
---|
107 | private Composite rightHandComposite; |
---|
108 | |
---|
109 | /** the stack layout displaying either the task details or a visualization */ |
---|
110 | private StackLayout rightHandLayout; |
---|
111 | |
---|
112 | /** the task details composite containing the task details tree, the execution variants, etc.*/ |
---|
113 | private Composite detailsComposite; |
---|
114 | |
---|
115 | /** the tree of a specific task on the right */ |
---|
116 | private Tree taskDetailsTree; |
---|
117 | |
---|
118 | /** the tree of execution variants of a specific task on the right */ |
---|
119 | private Tree executionVariantsTree; |
---|
120 | |
---|
121 | /** the tree of involved GUI elements of a specific task on the right bottom */ |
---|
122 | private Tree involvedTargetsTree; |
---|
123 | |
---|
124 | /** the table containing the parents tasks of a displayed task */ |
---|
125 | private Tree parentTasks; |
---|
126 | |
---|
127 | /** the visualization composite on the right hand side toggled with the details composite */ |
---|
128 | private Composite visualizationsComposite; |
---|
129 | |
---|
130 | /** the displayed task model */ |
---|
131 | private ITaskModel taskModel; |
---|
132 | |
---|
133 | /** a boolean indicating if the CTTE export of a task is possible */ |
---|
134 | private boolean taskExportAvailable = false; |
---|
135 | |
---|
136 | /** default expansion listener */ |
---|
137 | private Listener defaultExpansionListener = new Listener() { |
---|
138 | public void handleEvent(final Event event) { |
---|
139 | ensureChildren((TreeItem) event.item); |
---|
140 | ((TreeItem) event.item).setExpanded(true); |
---|
141 | } |
---|
142 | }; |
---|
143 | |
---|
144 | /** |
---|
145 | * creates the dialog |
---|
146 | */ |
---|
147 | public ShowTaskTreeDialog(Shell parent, int style, ITaskModel taskModel, String taskTreeName) { |
---|
148 | super(parent, style); |
---|
149 | setText("Task Model " + taskTreeName); |
---|
150 | this.taskModel = taskModel; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * displays the dialog |
---|
155 | * @param task |
---|
156 | */ |
---|
157 | public void open() { |
---|
158 | // check, if export to CTTE is possible |
---|
159 | try { |
---|
160 | Class<?> exportClass = this.getClass().getClassLoader().loadClass |
---|
161 | ("de.ugoe.cs.autoquest.plugin.exports.tasktree.CTTExportUtils"); |
---|
162 | |
---|
163 | if (exportClass != null) { |
---|
164 | taskExportAvailable = true; |
---|
165 | } |
---|
166 | } |
---|
167 | catch (ClassNotFoundException e) { |
---|
168 | // ignore. No export available |
---|
169 | } |
---|
170 | |
---|
171 | open(null); |
---|
172 | } |
---|
173 | |
---|
174 | /** |
---|
175 | * displays the dialog with a specific task opened |
---|
176 | * @param task |
---|
177 | */ |
---|
178 | public void open(ITask task) { |
---|
179 | if (shell == null) { |
---|
180 | createContents(); |
---|
181 | shell.open(); |
---|
182 | shell.layout(); |
---|
183 | |
---|
184 | VisualizationUtils.updateColumnWidths(taskDetailsTree); |
---|
185 | } |
---|
186 | else { |
---|
187 | shell.setVisible(true); |
---|
188 | } |
---|
189 | |
---|
190 | if (task != null) { |
---|
191 | shellListener = new ShellAdapter() { |
---|
192 | @Override |
---|
193 | public void shellClosed(ShellEvent e) { |
---|
194 | e.doit = false; |
---|
195 | shell.setVisible(false); |
---|
196 | } |
---|
197 | }; |
---|
198 | |
---|
199 | shell.addShellListener(shellListener); |
---|
200 | } |
---|
201 | |
---|
202 | if (task != null) { |
---|
203 | navigateTo(task); |
---|
204 | } |
---|
205 | |
---|
206 | Display display = getParent().getDisplay(); |
---|
207 | while (!shell.isDisposed() && shell.isVisible()) { |
---|
208 | if (!display.readAndDispatch()) { |
---|
209 | display.sleep(); |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | if (task == null) { |
---|
214 | dispose(); |
---|
215 | } |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * disposes the dialog if it is not used anymore |
---|
220 | */ |
---|
221 | public void dispose() { |
---|
222 | if ((shell != null) && (!shell.isDisposed())) { |
---|
223 | if (shellListener != null) { |
---|
224 | shell.removeShellListener(shellListener); |
---|
225 | } |
---|
226 | |
---|
227 | shell.dispose(); |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | /** |
---|
232 | * creates the two views, one on the task instances on the left, on on the task models on the |
---|
233 | * right. Also adds a selection adapter to the task instances so that for a selected task |
---|
234 | * instance always the respective model is presented. |
---|
235 | */ |
---|
236 | private void createContents() { |
---|
237 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER); |
---|
238 | |
---|
239 | GraphicsDevice gd = |
---|
240 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); |
---|
241 | |
---|
242 | shell.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); |
---|
243 | shell.setText(getText()); |
---|
244 | |
---|
245 | shell.setLayout(new GridLayout(4, false)); |
---|
246 | |
---|
247 | SashForm mainSashForm = new SashForm(shell, SWT.HORIZONTAL); |
---|
248 | mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); |
---|
249 | |
---|
250 | createLeftHandSideTabs(mainSashForm); |
---|
251 | createRightHandSideView(mainSashForm); |
---|
252 | |
---|
253 | mainSashForm.setWeights(new int[] { 1, 3 }); |
---|
254 | |
---|
255 | Button btnExpandAll = new Button(shell, SWT.NONE); |
---|
256 | btnExpandAll.addSelectionListener(new SelectionAdapter() { |
---|
257 | @Override |
---|
258 | public void widgetSelected(SelectionEvent e) { |
---|
259 | if (tabFolder.getSelectionIndex() == 0) { |
---|
260 | VisualizationUtils.expandAll(instanceTree, true); |
---|
261 | } |
---|
262 | else { |
---|
263 | VisualizationUtils.expandAll(modelTree, true); |
---|
264 | } |
---|
265 | } |
---|
266 | }); |
---|
267 | btnExpandAll.setText("Expand all"); |
---|
268 | |
---|
269 | Button btnCollapseAll = new Button(shell, SWT.NONE); |
---|
270 | btnCollapseAll.addSelectionListener(new SelectionAdapter() { |
---|
271 | @Override |
---|
272 | public void widgetSelected(SelectionEvent e) { |
---|
273 | if (tabFolder.getSelectionIndex() == 0) { |
---|
274 | VisualizationUtils.expandAll(instanceTree, false); |
---|
275 | } |
---|
276 | else { |
---|
277 | VisualizationUtils.expandAll(modelTree, false); |
---|
278 | } |
---|
279 | } |
---|
280 | }); |
---|
281 | btnCollapseAll.setText("Collapse all"); |
---|
282 | |
---|
283 | new Label(shell, SWT.NONE); |
---|
284 | new Label(shell, SWT.NONE); |
---|
285 | } |
---|
286 | |
---|
287 | /** |
---|
288 | * |
---|
289 | */ |
---|
290 | private void createLeftHandSideTabs(final SashForm mainSashForm) { |
---|
291 | tabFolder = new TabFolder(mainSashForm, SWT.NONE); |
---|
292 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
293 | tabFolder.addSelectionListener(new SelectionAdapter() { |
---|
294 | @Override |
---|
295 | public void widgetSelected(SelectionEvent e) { |
---|
296 | if (tabFolder.getSelectionIndex() == 0) { |
---|
297 | // task instances tab selected |
---|
298 | rightHandLayout.topControl = detailsComposite; |
---|
299 | } |
---|
300 | else if (tabFolder.getSelectionIndex() == 1) { |
---|
301 | // task model tab selected |
---|
302 | rightHandLayout.topControl = detailsComposite; |
---|
303 | VisualizationUtils.updateColumnWidths(modelTree); |
---|
304 | } |
---|
305 | else { |
---|
306 | rightHandLayout.topControl = visualizationsComposite; |
---|
307 | } |
---|
308 | |
---|
309 | rightHandComposite.layout(); |
---|
310 | rightHandComposite.redraw(); |
---|
311 | rightHandComposite.update(); |
---|
312 | } |
---|
313 | }); |
---|
314 | |
---|
315 | TabItem instanceTreeTab = new TabItem(tabFolder, SWT.NONE); |
---|
316 | instanceTreeTab.setText("Task Instances"); |
---|
317 | |
---|
318 | instanceTree = new Tree(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL); |
---|
319 | instanceTree.addSelectionListener(new SelectionAdapter() { |
---|
320 | @Override |
---|
321 | public void widgetSelected(SelectionEvent e) { |
---|
322 | TreeItem[] selectedItems = instanceTree.getSelection(); |
---|
323 | if ((selectedItems.length == 1) && |
---|
324 | (selectedItems[0].getData() instanceof ITaskInstance)) |
---|
325 | { |
---|
326 | displayTaskDetails(((ITaskInstance) selectedItems[0].getData()).getTask()); |
---|
327 | } |
---|
328 | else { |
---|
329 | clearTaskDetails(); |
---|
330 | } |
---|
331 | } |
---|
332 | }); |
---|
333 | |
---|
334 | VisualizationUtils.addItemSpecificContextMenu |
---|
335 | (instanceTree, ITaskInstance.class, "show in task list", new SelectionAdapter() |
---|
336 | { |
---|
337 | @Override |
---|
338 | public void widgetSelected(SelectionEvent e) { |
---|
339 | navigateTo(((ITaskInstance) instanceTree.getSelection()[0].getData()).getTask()); |
---|
340 | } |
---|
341 | }); |
---|
342 | |
---|
343 | if (taskExportAvailable) { |
---|
344 | VisualizationUtils.addItemSpecificContextMenu |
---|
345 | (instanceTree, ITask.class, "export to ConcurTaskTree", new SelectionAdapter() |
---|
346 | { |
---|
347 | @Override |
---|
348 | public void widgetSelected(SelectionEvent e) { |
---|
349 | export((ITask) taskDetailsTree.getSelection()[0].getData()); |
---|
350 | } |
---|
351 | }); |
---|
352 | } |
---|
353 | |
---|
354 | VisualizationUtils.addItemSpecificContextMenu |
---|
355 | (instanceTree, ITask.class, "copy to clipboard", new SelectionAdapter() |
---|
356 | { |
---|
357 | @Override |
---|
358 | public void widgetSelected(SelectionEvent e) { |
---|
359 | StringSelection stringSelection = new StringSelection |
---|
360 | (taskDetailsTree.getSelection()[0].getData().toString()); |
---|
361 | Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); |
---|
362 | clpbrd.setContents(stringSelection, null); |
---|
363 | } |
---|
364 | }); |
---|
365 | |
---|
366 | buildInstanceTree(); |
---|
367 | instanceTreeTab.setControl(instanceTree); |
---|
368 | |
---|
369 | TabItem modelTreeTab = new TabItem(tabFolder, SWT.NONE); |
---|
370 | modelTreeTab.setText("Tasks"); |
---|
371 | |
---|
372 | modelTree = |
---|
373 | VisualizationUtils.createTaskDetailsTree(tabFolder, "tasks in model", taskModel); |
---|
374 | |
---|
375 | // show task details if requested |
---|
376 | modelTree.addSelectionListener(new SelectionAdapter() { |
---|
377 | @Override |
---|
378 | public void widgetSelected(SelectionEvent e) { |
---|
379 | TreeItem[] selectedItems = modelTree.getSelection(); |
---|
380 | if ((selectedItems.length == 1) && (selectedItems[0].getData() instanceof ITask)) { |
---|
381 | displayTaskDetails((ITask) selectedItems[0].getData()); |
---|
382 | } |
---|
383 | else { |
---|
384 | clearTaskDetails(); |
---|
385 | } |
---|
386 | } |
---|
387 | }); |
---|
388 | |
---|
389 | buildModelTree(taskModel); |
---|
390 | |
---|
391 | modelTreeTab.setControl(modelTree); |
---|
392 | |
---|
393 | TabItem modelVisualizationTab = new TabItem(tabFolder, SWT.NONE); |
---|
394 | modelVisualizationTab.setText("Visualizations"); |
---|
395 | |
---|
396 | modelVisualizationTree = new Tree(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL); |
---|
397 | |
---|
398 | TreeItem item1 = new TreeItem(modelVisualizationTree, SWT.NULL); |
---|
399 | item1.setText(TaskTreePlotUtils.TASK_COUNT__EVENT_COVERAGE_PLOT); |
---|
400 | |
---|
401 | item1 = new TreeItem(modelVisualizationTree, SWT.NULL); |
---|
402 | item1.setText(TaskTreePlotUtils.ORDERED_TASK_COUNT_PLOT); |
---|
403 | |
---|
404 | item1 = new TreeItem(modelVisualizationTree, SWT.NULL); |
---|
405 | item1.setText(TaskTreePlotUtils.CUMULATIVE_TASK_COVERAGE_PLOT); |
---|
406 | |
---|
407 | Menu menu = modelVisualizationTree.getMenu(); |
---|
408 | |
---|
409 | if (menu == null) { |
---|
410 | menu = new Menu(modelVisualizationTree); |
---|
411 | modelVisualizationTree.setMenu(menu); |
---|
412 | } |
---|
413 | |
---|
414 | // show visualization if requested |
---|
415 | modelVisualizationTree.addSelectionListener(new SelectionAdapter() { |
---|
416 | @Override |
---|
417 | public void widgetSelected(SelectionEvent e) { |
---|
418 | clearVisualization(); |
---|
419 | TreeItem[] selectedItems = modelVisualizationTree.getSelection(); |
---|
420 | if (selectedItems.length == 1) { |
---|
421 | showVisualization(selectedItems[0].getText()); |
---|
422 | } |
---|
423 | } |
---|
424 | }); |
---|
425 | |
---|
426 | modelVisualizationTab.setControl(modelVisualizationTree); |
---|
427 | |
---|
428 | // add a context menu for PDF export |
---|
429 | final Menu finalMenu = menu; |
---|
430 | MenuItem newItem = new MenuItem(finalMenu, SWT.NONE); |
---|
431 | newItem.setText("save as PDF"); |
---|
432 | newItem.addSelectionListener(new SelectionAdapter() { |
---|
433 | @Override |
---|
434 | public void widgetSelected(SelectionEvent e) { |
---|
435 | try { |
---|
436 | FileDialog dialog = new FileDialog(shell, SWT.SAVE); |
---|
437 | dialog.setFilterExtensions(new String [] {"*.pdf"}); |
---|
438 | TaskTreePlotUtils.saveChartToPDF |
---|
439 | ((JFreeChart) modelVisualizationTree.getSelection()[0].getData(), |
---|
440 | dialog.open(), 500, 500); |
---|
441 | } |
---|
442 | catch (Exception e1) { |
---|
443 | // TODO Auto-generated catch block |
---|
444 | e1.printStackTrace(); |
---|
445 | } |
---|
446 | } |
---|
447 | }); |
---|
448 | } |
---|
449 | |
---|
450 | /** |
---|
451 | * |
---|
452 | */ |
---|
453 | private void createRightHandSideView(SashForm mainSashForm) { |
---|
454 | rightHandComposite = new Composite(mainSashForm, SWT.NO_BACKGROUND); |
---|
455 | rightHandLayout = new StackLayout(); |
---|
456 | rightHandComposite.setLayout(rightHandLayout); |
---|
457 | |
---|
458 | detailsComposite = new Composite(rightHandComposite, SWT.NO_BACKGROUND); |
---|
459 | detailsComposite.setLayout(new GridLayout(1, false)); |
---|
460 | detailsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
461 | |
---|
462 | new Label(detailsComposite, SWT.NONE).setText("Task Details:"); |
---|
463 | |
---|
464 | SashForm detailsSashForm = new SashForm(detailsComposite, SWT.VERTICAL); |
---|
465 | detailsSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
466 | |
---|
467 | SashForm detailsTopSashForm = new SashForm(detailsSashForm, SWT.HORIZONTAL); |
---|
468 | detailsTopSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
469 | |
---|
470 | taskDetailsTree = |
---|
471 | VisualizationUtils.createTaskDetailsTree(detailsTopSashForm, "task details", taskModel); |
---|
472 | |
---|
473 | VisualizationUtils.addExpansionListener(taskDetailsTree, defaultExpansionListener); |
---|
474 | |
---|
475 | VisualizationUtils.addItemSpecificContextMenu |
---|
476 | (taskDetailsTree, ITask.class, "show in task list", new SelectionAdapter() |
---|
477 | { |
---|
478 | @Override |
---|
479 | public void widgetSelected(SelectionEvent e) { |
---|
480 | navigateTo((ITask) taskDetailsTree.getSelection()[0].getData()); |
---|
481 | } |
---|
482 | }); |
---|
483 | |
---|
484 | if (taskExportAvailable) { |
---|
485 | VisualizationUtils.addItemSpecificContextMenu |
---|
486 | (taskDetailsTree, ITask.class, "export to ConcurTaskTree", new SelectionAdapter() |
---|
487 | { |
---|
488 | @Override |
---|
489 | public void widgetSelected(SelectionEvent e) { |
---|
490 | export((ITask) taskDetailsTree.getSelection()[0].getData()); |
---|
491 | } |
---|
492 | }); |
---|
493 | } |
---|
494 | |
---|
495 | VisualizationUtils.addItemSpecificContextMenu |
---|
496 | (taskDetailsTree, ITask.class, "copy to clipboard", new SelectionAdapter() |
---|
497 | { |
---|
498 | @Override |
---|
499 | public void widgetSelected(SelectionEvent e) { |
---|
500 | StringSelection stringSelection = new StringSelection |
---|
501 | (taskDetailsTree.getSelection()[0].getData().toString()); |
---|
502 | Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); |
---|
503 | clpbrd.setContents(stringSelection, null); |
---|
504 | } |
---|
505 | }); |
---|
506 | |
---|
507 | executionVariantsTree = new Tree(detailsTopSashForm, SWT.BORDER | SWT.SINGLE | SWT.WRAP); |
---|
508 | executionVariantsTree.setHeaderVisible(true); |
---|
509 | |
---|
510 | TreeColumn taskColumn = new TreeColumn(executionVariantsTree, SWT.NONE); |
---|
511 | taskColumn.setText("instance variants"); |
---|
512 | taskColumn.setAlignment(SWT.LEFT); |
---|
513 | |
---|
514 | // load the correct children on expansion |
---|
515 | VisualizationUtils.addExpansionListener(executionVariantsTree, defaultExpansionListener); |
---|
516 | |
---|
517 | detailsTopSashForm.setWeights(new int[] { 3, 2 }); |
---|
518 | |
---|
519 | SashForm detailsBottomSashForm = new SashForm(detailsSashForm, SWT.HORIZONTAL); |
---|
520 | detailsBottomSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
521 | |
---|
522 | parentTasks = VisualizationUtils.createTaskDetailsTree |
---|
523 | (detailsBottomSashForm, "parent tasks", taskModel); |
---|
524 | |
---|
525 | VisualizationUtils.addItemSpecificContextMenu |
---|
526 | (parentTasks, ITask.class, "show in task list", new SelectionAdapter() |
---|
527 | { |
---|
528 | @Override |
---|
529 | public void widgetSelected(SelectionEvent e) { |
---|
530 | navigateTo((ITask) parentTasks.getSelection()[0].getData()); |
---|
531 | } |
---|
532 | }); |
---|
533 | |
---|
534 | if (taskExportAvailable) { |
---|
535 | VisualizationUtils.addItemSpecificContextMenu |
---|
536 | (parentTasks, ITask.class, "export to ConcurTaskTree", new SelectionAdapter() |
---|
537 | { |
---|
538 | @Override |
---|
539 | public void widgetSelected(SelectionEvent e) { |
---|
540 | export((ITask) taskDetailsTree.getSelection()[0].getData()); |
---|
541 | } |
---|
542 | }); |
---|
543 | } |
---|
544 | |
---|
545 | VisualizationUtils.addItemSpecificContextMenu |
---|
546 | (parentTasks, ITask.class, "copy to clipboard", new SelectionAdapter() |
---|
547 | { |
---|
548 | @Override |
---|
549 | public void widgetSelected(SelectionEvent e) { |
---|
550 | StringSelection stringSelection = new StringSelection |
---|
551 | (taskDetailsTree.getSelection()[0].getData().toString()); |
---|
552 | Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard(); |
---|
553 | clpbrd.setContents(stringSelection, null); |
---|
554 | } |
---|
555 | }); |
---|
556 | |
---|
557 | involvedTargetsTree = |
---|
558 | VisualizationUtils.createTargetsTree(detailsBottomSashForm, "involved GUI elements"); |
---|
559 | |
---|
560 | visualizationsComposite = new Composite(rightHandComposite, SWT.NO_BACKGROUND); |
---|
561 | visualizationsComposite.setLayout(new GridLayout(1, false)); |
---|
562 | visualizationsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
563 | |
---|
564 | new Label(visualizationsComposite, SWT.NONE).setText("Visualization:"); |
---|
565 | |
---|
566 | rightHandLayout.topControl = detailsComposite; |
---|
567 | |
---|
568 | detailsBottomSashForm.setWeights(new int[] { 2, 3 }); |
---|
569 | detailsSashForm.setWeights(new int[] { 1, 1 }); |
---|
570 | } |
---|
571 | |
---|
572 | /** |
---|
573 | * convenience method for creating the display of the instances |
---|
574 | */ |
---|
575 | private void buildInstanceTree() { |
---|
576 | List<IUserSession> sessions = taskModel.getUserSessions(); |
---|
577 | |
---|
578 | // load the correct children on expansion |
---|
579 | VisualizationUtils.addExpansionListener(instanceTree, defaultExpansionListener); |
---|
580 | |
---|
581 | TreeItem root = new TreeItem(instanceTree, SWT.NULL); |
---|
582 | root.setText(sessions.size() + " sessions"); |
---|
583 | root.setData(taskModel); |
---|
584 | |
---|
585 | // simulate a child |
---|
586 | new TreeItem(root, SWT.NULL); |
---|
587 | |
---|
588 | /*for (IUserSession session : sessions) { |
---|
589 | buildInstanceTree(root, session); |
---|
590 | }*/ |
---|
591 | |
---|
592 | root.setExpanded(false); |
---|
593 | } |
---|
594 | |
---|
595 | /** |
---|
596 | * convenience method for creating the display of the instances |
---|
597 | */ |
---|
598 | private void buildInstanceTree(TreeItem currentParent, IUserSession session) { |
---|
599 | TreeItem item = new TreeItem(currentParent, SWT.NULL); |
---|
600 | item.setText(session.toString()); |
---|
601 | item.setData(session); |
---|
602 | |
---|
603 | // simulate a child |
---|
604 | new TreeItem(item, SWT.NULL); |
---|
605 | } |
---|
606 | |
---|
607 | /** |
---|
608 | * convenience method for creating the display of the task model |
---|
609 | */ |
---|
610 | private void buildModelTree(ITaskModel taskModel) { |
---|
611 | VisualizationUtils.addExpansionListener(modelTree, defaultExpansionListener); |
---|
612 | |
---|
613 | Collection<ITask> allTasks = taskModel.getTasks(); |
---|
614 | |
---|
615 | List<ITask> sequences = new ArrayList<ITask>(); |
---|
616 | List<ITask> iterations = new ArrayList<ITask>(); |
---|
617 | List<ITask> selections = new ArrayList<ITask>(); |
---|
618 | List<ITask> optionals = new ArrayList<ITask>(); |
---|
619 | List<ITask> others = new ArrayList<ITask>(); |
---|
620 | |
---|
621 | TreeItem root = new TreeItem(modelTree, SWT.NULL); |
---|
622 | root.setText(allTasks.size() + " tasks in model"); |
---|
623 | root.setData(taskModel); |
---|
624 | |
---|
625 | createSortedTaskLists(allTasks, sequences, iterations, selections, optionals, others); |
---|
626 | |
---|
627 | //allTasks = createSortedTaskList(allTasks); |
---|
628 | |
---|
629 | createModelTreeItemFor(sequences, sequences.size() + " Sequences", root); |
---|
630 | createModelTreeItemFor(iterations, iterations.size() + " Iterations", root); |
---|
631 | createModelTreeItemFor(selections, selections.size() + " Selections", root); |
---|
632 | createModelTreeItemFor(optionals, optionals.size() + " Optionals", root); |
---|
633 | createModelTreeItemFor(others, others.size() + " other Tasks", root); |
---|
634 | |
---|
635 | root.setExpanded(true); |
---|
636 | } |
---|
637 | |
---|
638 | /** |
---|
639 | * |
---|
640 | */ |
---|
641 | private void createSortedTaskLists(Collection<ITask> allTasks, |
---|
642 | List<ITask> sequences, |
---|
643 | List<ITask> iterations, |
---|
644 | List<ITask> selections, |
---|
645 | List<ITask> optionals, |
---|
646 | List<ITask> others) |
---|
647 | { |
---|
648 | List<ITask> toAdd; |
---|
649 | |
---|
650 | for (ITask task : allTasks) { |
---|
651 | if (task instanceof ISequence) { |
---|
652 | toAdd = sequences; |
---|
653 | } |
---|
654 | else if (task instanceof IIteration) { |
---|
655 | toAdd = iterations; |
---|
656 | } |
---|
657 | else if (task instanceof ISelection) { |
---|
658 | toAdd = selections; |
---|
659 | } |
---|
660 | else if (task instanceof IOptional) { |
---|
661 | toAdd = optionals; |
---|
662 | } |
---|
663 | else { |
---|
664 | toAdd = others; |
---|
665 | } |
---|
666 | |
---|
667 | int taskValue = taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); |
---|
668 | int start = 0; |
---|
669 | int end = toAdd.size(); |
---|
670 | int center = 0; |
---|
671 | int centerValue; |
---|
672 | |
---|
673 | while (start != end) { |
---|
674 | center = start + ((end - start) / 2); |
---|
675 | |
---|
676 | if ((center != start) || (center != end)) { |
---|
677 | //centerValue = toAdd.get(center).getInstances().size(); |
---|
678 | centerValue = taskModel.getTaskInfo(toAdd.get(center)).getMeasureValue |
---|
679 | (TaskMetric.EVENT_COVERAGE); |
---|
680 | |
---|
681 | if (centerValue > taskValue) { |
---|
682 | start = Math.max(center, start + 1); |
---|
683 | } |
---|
684 | else if (centerValue < taskValue) { |
---|
685 | end = Math.min(center, end - 1); |
---|
686 | } |
---|
687 | else { |
---|
688 | // add the event directly where the center is, as the count of the center |
---|
689 | // and the new task are equal |
---|
690 | end = center; |
---|
691 | start = end; |
---|
692 | break; |
---|
693 | } |
---|
694 | } |
---|
695 | else { |
---|
696 | // add the event to the position denoted by the add index |
---|
697 | break; |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | toAdd.add(start, task); |
---|
702 | } |
---|
703 | } |
---|
704 | |
---|
705 | /** |
---|
706 | * |
---|
707 | */ |
---|
708 | private void clearTaskDetails() { |
---|
709 | taskDetailsTree.removeAll(); |
---|
710 | executionVariantsTree.removeAll(); |
---|
711 | involvedTargetsTree.removeAll(); |
---|
712 | parentTasks.removeAll(); |
---|
713 | } |
---|
714 | |
---|
715 | /** |
---|
716 | * |
---|
717 | */ |
---|
718 | private void displayTaskDetails(ITask task) { |
---|
719 | clearTaskDetails(); |
---|
720 | |
---|
721 | VisualizationUtils.createTreeItemFor(task, taskDetailsTree, taskModel, true); |
---|
722 | VisualizationUtils.expandAll(taskDetailsTree, true); |
---|
723 | |
---|
724 | // do it twice. Otherwise, it doesn't work |
---|
725 | VisualizationUtils.updateColumnWidths(taskDetailsTree); |
---|
726 | |
---|
727 | Collection<Collection<ITaskInstance>> executionVariants = task.getExecutionVariants(); |
---|
728 | List<Collection<ITaskInstance>> sortedExecutionVariants = |
---|
729 | new LinkedList<Collection<ITaskInstance>>(executionVariants); |
---|
730 | |
---|
731 | Collections.sort(sortedExecutionVariants, new Comparator<Collection<ITaskInstance>>() { |
---|
732 | @Override |
---|
733 | public int compare(Collection<ITaskInstance> list1, Collection<ITaskInstance> list2) { |
---|
734 | return list2.size() - list1.size(); |
---|
735 | } |
---|
736 | }); |
---|
737 | |
---|
738 | int counter = 1; |
---|
739 | for (Collection<ITaskInstance> variant : sortedExecutionVariants) { |
---|
740 | TreeItem item = new TreeItem(executionVariantsTree, SWT.NULL); |
---|
741 | if (variant.size() > 1) { |
---|
742 | item.setText("variant " + counter++ + " (executed " + variant.size() + " times)"); |
---|
743 | } |
---|
744 | else { |
---|
745 | item.setText("variant " + counter++ + " (executed once)"); |
---|
746 | } |
---|
747 | item.setData(variant); |
---|
748 | |
---|
749 | createTreeItemFor(variant.iterator().next(), item); |
---|
750 | } |
---|
751 | |
---|
752 | VisualizationUtils.expandAll(executionVariantsTree, true); |
---|
753 | VisualizationUtils.updateColumnWidths(executionVariantsTree); |
---|
754 | |
---|
755 | addParentTasks(task); |
---|
756 | VisualizationUtils.updateColumnWidths(parentTasks); |
---|
757 | |
---|
758 | VisualizationUtils.addInvolvedTargets(involvedTargetsTree, task); |
---|
759 | } |
---|
760 | |
---|
761 | /** |
---|
762 | * |
---|
763 | */ |
---|
764 | private void addParentTasks(ITask task) { |
---|
765 | for (ITask candidate : taskModel.getTasks()) { |
---|
766 | if (((candidate instanceof IStructuringTemporalRelationship) && |
---|
767 | (((IStructuringTemporalRelationship) candidate).getChildren().contains(task))) || |
---|
768 | ((candidate instanceof IMarkingTemporalRelationship) && |
---|
769 | (((IMarkingTemporalRelationship) candidate).getMarkedTask().equals(task)))) |
---|
770 | { |
---|
771 | VisualizationUtils.createTreeItemFor(candidate, parentTasks, taskModel, false); |
---|
772 | } |
---|
773 | } |
---|
774 | } |
---|
775 | |
---|
776 | /** |
---|
777 | * |
---|
778 | */ |
---|
779 | private void navigateTo(ITask task) { |
---|
780 | tabFolder.setSelection(1); |
---|
781 | |
---|
782 | OUTER: |
---|
783 | for (TreeItem sublist : modelTree.getItem(0).getItems()) { |
---|
784 | for (TreeItem taskItem : sublist.getItems()) { |
---|
785 | if (task.equals(taskItem.getData())) { |
---|
786 | modelTree.setSelection(taskItem); |
---|
787 | sublist.setExpanded(true); |
---|
788 | VisualizationUtils.updateColumnWidths(modelTree); |
---|
789 | break OUTER; |
---|
790 | } |
---|
791 | } |
---|
792 | } |
---|
793 | |
---|
794 | displayTaskDetails(task); |
---|
795 | } |
---|
796 | |
---|
797 | /** |
---|
798 | * |
---|
799 | */ |
---|
800 | private void export(ITask task) { |
---|
801 | try { |
---|
802 | Class<?> exportClass = this.getClass().getClassLoader().loadClass |
---|
803 | ("de.ugoe.cs.autoquest.plugin.exports.tasktree.CTTExportUtils"); |
---|
804 | |
---|
805 | Method method = exportClass.getDeclaredMethod("exportToCTT", ITask.class, String.class); |
---|
806 | |
---|
807 | method.invoke(null, task, task.getId() + "_ctte.xml"); |
---|
808 | } |
---|
809 | catch (Exception e) { |
---|
810 | Console.logException(e); |
---|
811 | } |
---|
812 | } |
---|
813 | |
---|
814 | /** |
---|
815 | * ensures, that the children of a specific node are loaded |
---|
816 | */ |
---|
817 | private void ensureChildren(TreeItem parent) { |
---|
818 | TreeItem[] items = parent.getItems(); |
---|
819 | if ((items == null) || (items.length == 0) || (items[0].getData() == null)) { |
---|
820 | if (items != null) { |
---|
821 | for (int i = 0; i < items.length; i++) { |
---|
822 | items[i].dispose(); |
---|
823 | } |
---|
824 | } |
---|
825 | |
---|
826 | if (parent.getData() instanceof ITask) { |
---|
827 | ITask task = (ITask) parent.getData(); |
---|
828 | |
---|
829 | if (task instanceof IStructuringTemporalRelationship) { |
---|
830 | for (ITask subTask : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
831 | VisualizationUtils.createTreeItemFor(subTask, parent, taskModel, true); |
---|
832 | } |
---|
833 | } |
---|
834 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
835 | VisualizationUtils.createTreeItemFor |
---|
836 | (((IMarkingTemporalRelationship) task).getMarkedTask(), parent, |
---|
837 | taskModel, true); |
---|
838 | } |
---|
839 | } |
---|
840 | else if (parent.getData() instanceof List<?>) { |
---|
841 | @SuppressWarnings("unchecked") |
---|
842 | List<ITask> tasks = (List<ITask>) parent.getData(); |
---|
843 | for (ITask task : tasks) { |
---|
844 | VisualizationUtils.createTreeItemFor(task, parent, taskModel, false); |
---|
845 | } |
---|
846 | } |
---|
847 | else if (parent.getData() instanceof ITaskInstanceList) { |
---|
848 | for (ITaskInstance subInstance : (ITaskInstanceList) parent.getData()) { |
---|
849 | createTreeItemFor(subInstance, parent); |
---|
850 | } |
---|
851 | } |
---|
852 | else if (parent.getData() instanceof ITaskInstance) { |
---|
853 | ITaskInstance instance = (ITaskInstance) parent.getData(); |
---|
854 | |
---|
855 | if (instance instanceof ISelectionInstance) { |
---|
856 | if (((ISelectionInstance) instance).getChild() != null) { |
---|
857 | createTreeItemFor(((ISelectionInstance) instance).getChild(), parent); |
---|
858 | } |
---|
859 | } |
---|
860 | else if (instance instanceof IOptionalInstance) { |
---|
861 | if (((IOptionalInstance) instance).getChild() != null) { |
---|
862 | createTreeItemFor(((IOptionalInstance) instance).getChild(), parent); |
---|
863 | } |
---|
864 | } |
---|
865 | } |
---|
866 | else if (parent.getData() instanceof ITaskModel) { |
---|
867 | ITaskModel taskModel = (ITaskModel) parent.getData(); |
---|
868 | |
---|
869 | for (IUserSession session : taskModel.getUserSessions()) { |
---|
870 | buildInstanceTree(parent, session); |
---|
871 | } |
---|
872 | } |
---|
873 | } |
---|
874 | } |
---|
875 | |
---|
876 | /** |
---|
877 | * |
---|
878 | */ |
---|
879 | private void createModelTreeItemFor(List<ITask> taskList, String name, TreeItem parent) { |
---|
880 | TreeItem item = new TreeItem(parent, SWT.NULL); |
---|
881 | item.setText(name); |
---|
882 | item.setData(taskList); |
---|
883 | |
---|
884 | // simulate a child |
---|
885 | if (taskList.size() > 0) { |
---|
886 | new TreeItem(item, SWT.NULL); |
---|
887 | /*for (ITask task : taskList) { |
---|
888 | VisualizationUtils.createTreeItemFor(task, item, taskModel, false); |
---|
889 | }*/ |
---|
890 | } |
---|
891 | } |
---|
892 | |
---|
893 | /** |
---|
894 | * convenience method to create a tree item for a task |
---|
895 | */ |
---|
896 | private void createTreeItemFor(ITaskInstance taskInstance, |
---|
897 | TreeItem parent) |
---|
898 | { |
---|
899 | TreeItem item = new TreeItem(parent, SWT.NULL); |
---|
900 | item.setText(taskInstance.toString()); |
---|
901 | item.setData(taskInstance); |
---|
902 | |
---|
903 | // simulate a child |
---|
904 | if ((taskInstance instanceof ITaskInstanceList) || |
---|
905 | (taskInstance instanceof ISelectionInstance) || |
---|
906 | (taskInstance instanceof IOptionalInstance)) |
---|
907 | { |
---|
908 | new TreeItem(item, SWT.NULL); |
---|
909 | } |
---|
910 | } |
---|
911 | |
---|
912 | /** |
---|
913 | * |
---|
914 | */ |
---|
915 | private void showVisualization(String name) { |
---|
916 | Color backgroundColor = visualizationsComposite.getBackground(); |
---|
917 | Composite parent = new Composite(visualizationsComposite, SWT.EMBEDDED); |
---|
918 | parent.setLayout(new GridLayout(1, false)); |
---|
919 | parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
920 | |
---|
921 | Frame chartFrame = SWT_AWT.new_Frame(parent); |
---|
922 | chartFrame.setBackground(new java.awt.Color(backgroundColor.getRed(), |
---|
923 | backgroundColor.getGreen(), |
---|
924 | backgroundColor.getBlue())); |
---|
925 | |
---|
926 | chartFrame.setLayout(new java.awt.GridLayout()); |
---|
927 | |
---|
928 | List<ITaskModel> models = new LinkedList<>(); |
---|
929 | models.add(taskModel); |
---|
930 | |
---|
931 | List<String> names = new LinkedList<>(); |
---|
932 | names.add(name); |
---|
933 | |
---|
934 | List<Integer> groups = new LinkedList<>(); |
---|
935 | groups.add(0); |
---|
936 | |
---|
937 | JFreeChart chart = TaskTreePlotUtils.createPlot(name, models, names, groups); |
---|
938 | chartFrame.add(new ChartPanel(chart)); |
---|
939 | |
---|
940 | modelVisualizationTree.getSelection()[0].setData(chart); |
---|
941 | |
---|
942 | rightHandComposite.layout(); |
---|
943 | rightHandComposite.redraw(); |
---|
944 | rightHandComposite.update(); |
---|
945 | } |
---|
946 | |
---|
947 | /** |
---|
948 | * |
---|
949 | */ |
---|
950 | private void clearVisualization() { |
---|
951 | for (Control child : visualizationsComposite.getChildren()) { |
---|
952 | child.dispose(); |
---|
953 | } |
---|
954 | |
---|
955 | visualizationsComposite.pack(); |
---|
956 | } |
---|
957 | } |
---|