Changeset 2033 for trunk/autoquest-ui-swt/src/main/java
- Timestamp:
- 07/30/15 14:35:38 (9 years ago)
- Location:
- trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowTaskTreeDialog.java
r1636 r2033 15 15 package de.ugoe.cs.autoquest.ui.swt; 16 16 17 import java.awt.Frame; 17 18 import java.awt.GraphicsDevice; 18 19 import java.awt.GraphicsEnvironment; 20 import java.lang.reflect.Method; 19 21 import java.util.Collection; 20 22 import java.util.Collections; … … 24 26 25 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.awt.SWT_AWT; 26 29 import org.eclipse.swt.custom.SashForm; 30 import org.eclipse.swt.custom.StackLayout; 27 31 import org.eclipse.swt.events.SelectionAdapter; 28 32 import org.eclipse.swt.events.SelectionEvent; … … 30 34 import org.eclipse.swt.events.ShellEvent; 31 35 import org.eclipse.swt.events.ShellListener; 36 import org.eclipse.swt.graphics.Color; 32 37 import org.eclipse.swt.layout.GridData; 33 38 import org.eclipse.swt.layout.GridLayout; 34 39 import org.eclipse.swt.widgets.Button; 35 40 import org.eclipse.swt.widgets.Composite; 41 import org.eclipse.swt.widgets.Control; 36 42 import org.eclipse.swt.widgets.Dialog; 37 43 import org.eclipse.swt.widgets.Display; 38 44 import org.eclipse.swt.widgets.Event; 45 import org.eclipse.swt.widgets.FileDialog; 39 46 import org.eclipse.swt.widgets.Label; 40 47 import org.eclipse.swt.widgets.Listener; 48 import org.eclipse.swt.widgets.Menu; 49 import org.eclipse.swt.widgets.MenuItem; 41 50 import org.eclipse.swt.widgets.Shell; 42 51 import org.eclipse.swt.widgets.TabFolder; … … 45 54 import org.eclipse.swt.widgets.TreeColumn; 46 55 import org.eclipse.swt.widgets.TreeItem; 56 import org.jfree.chart.ChartPanel; 57 import org.jfree.chart.JFreeChart; 47 58 48 59 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; … … 60 71 import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; 61 72 import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric; 73 import de.ugoe.cs.util.console.Console; 62 74 63 75 /** … … 76 88 private ShellListener shellListener; 77 89 78 /** the tab folder containing the instance tree as well as the model tree*/90 /** the tab folder containing the instance tree, the model tree, and the visualizations list */ 79 91 private TabFolder tabFolder; 80 92 … … 85 97 private Tree modelTree; 86 98 99 /** the tree of possible visualizations on the left */ 100 private Tree modelVisualizationTree; 101 102 /** the right hand composite containing either task details or a visualization */ 103 private Composite rightHandComposite; 104 105 /** the stack layout displaying either the task details or a visualization */ 106 private StackLayout rightHandLayout; 107 108 /** the task details composite containing the task details tree, the execution variants, etc.*/ 109 private Composite detailsComposite; 110 87 111 /** the tree of a specific task on the right */ 88 112 private Tree taskDetailsTree; … … 96 120 /** the table containing the parents tasks of a displayed task */ 97 121 private Tree parentTasks; 122 123 /** the visualization composite on the right hand side toggled with the details composite */ 124 private Composite visualizationsComposite; 98 125 99 126 /** the displayed task model */ 100 127 private ITaskModel taskModel; 128 129 /** a boolean indicating if the CTTE export of a task is possible */ 130 private boolean taskExportAvailable = false; 101 131 102 132 /** default expansion listener */ … … 122 152 */ 123 153 public void open() { 154 // check, if export to CTTE is possible 155 try { 156 Class<?> exportClass = this.getClass().getClassLoader().loadClass 157 ("de.ugoe.cs.autoquest.plugin.exports.tasktree.CTTExportUtils"); 158 159 if (exportClass != null) { 160 taskExportAvailable = true; 161 } 162 } 163 catch (ClassNotFoundException e) { 164 // ignore. No export available 165 } 166 124 167 open(null); 125 168 } … … 201 244 mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); 202 245 203 create SessionsAndTasksTabFolder(mainSashForm);204 create TaskDetailsView(mainSashForm);246 createLeftHandSideTabs(mainSashForm); 247 createRightHandSideView(mainSashForm); 205 248 206 249 mainSashForm.setWeights(new int[] { 1, 3 }); … … 241 284 * 242 285 */ 243 private void create SessionsAndTasksTabFolder(SashForm mainSashForm) {286 private void createLeftHandSideTabs(final SashForm mainSashForm) { 244 287 tabFolder = new TabFolder(mainSashForm, SWT.NONE); 245 288 tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); … … 247 290 @Override 248 291 public void widgetSelected(SelectionEvent e) { 249 VisualizationUtils.updateColumnWidths(modelTree); 292 if (tabFolder.getSelectionIndex() == 0) { 293 // task instances tab selected 294 rightHandLayout.topControl = detailsComposite; 295 } 296 else if (tabFolder.getSelectionIndex() == 1) { 297 // task model tab selected 298 rightHandLayout.topControl = detailsComposite; 299 VisualizationUtils.updateColumnWidths(modelTree); 300 } 301 else { 302 rightHandLayout.topControl = visualizationsComposite; 303 } 304 305 rightHandComposite.layout(); 306 rightHandComposite.redraw(); 307 rightHandComposite.update(); 250 308 } 251 309 }); … … 278 336 } 279 337 }); 338 339 if (taskExportAvailable) { 340 VisualizationUtils.addItemSpecificContextMenu 341 (instanceTree, ITask.class, "export to ConcurTaskTree", new SelectionAdapter() 342 { 343 @Override 344 public void widgetSelected(SelectionEvent e) { 345 export((ITask) taskDetailsTree.getSelection()[0].getData()); 346 } 347 }); 348 } 280 349 281 350 buildInstanceTree(); … … 305 374 306 375 modelTreeTab.setControl(modelTree); 307 } 308 376 377 TabItem modelVisualizationTab = new TabItem(tabFolder, SWT.NONE); 378 modelVisualizationTab.setText("Visualizations"); 379 380 modelVisualizationTree = new Tree(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL); 381 382 TreeItem item1 = new TreeItem(modelVisualizationTree, SWT.NULL); 383 item1.setText(TaskTreePlotUtils.TASK_COUNT__EVENT_COVERAGE_PLOT); 384 385 item1 = new TreeItem(modelVisualizationTree, SWT.NULL); 386 item1.setText(TaskTreePlotUtils.ORDERED_TASK_COUNT_PLOT); 387 388 item1 = new TreeItem(modelVisualizationTree, SWT.NULL); 389 item1.setText(TaskTreePlotUtils.CUMULATIVE_TASK_COVERAGE_PLOT); 390 391 Menu menu = modelVisualizationTree.getMenu(); 392 393 if (menu == null) { 394 menu = new Menu(modelVisualizationTree); 395 modelVisualizationTree.setMenu(menu); 396 } 397 398 // show visualization if requested 399 modelVisualizationTree.addSelectionListener(new SelectionAdapter() { 400 @Override 401 public void widgetSelected(SelectionEvent e) { 402 clearVisualization(); 403 TreeItem[] selectedItems = modelVisualizationTree.getSelection(); 404 if (selectedItems.length == 1) { 405 showVisualization(selectedItems[0].getText()); 406 } 407 } 408 }); 409 410 modelVisualizationTab.setControl(modelVisualizationTree); 411 412 // add a context menu for PDF export 413 final Menu finalMenu = menu; 414 MenuItem newItem = new MenuItem(finalMenu, SWT.NONE); 415 newItem.setText("save as PDF"); 416 newItem.addSelectionListener(new SelectionAdapter() { 417 @Override 418 public void widgetSelected(SelectionEvent e) { 419 try { 420 FileDialog dialog = new FileDialog(shell, SWT.SAVE); 421 dialog.setFilterExtensions(new String [] {"*.pdf"}); 422 TaskTreePlotUtils.saveChartToPDF 423 ((JFreeChart) modelVisualizationTree.getSelection()[0].getData(), 424 dialog.open(), 500, 500); 425 } 426 catch (Exception e1) { 427 // TODO Auto-generated catch block 428 e1.printStackTrace(); 429 } 430 } 431 }); 432 } 433 309 434 /** 310 435 * 311 436 */ 312 private void createTaskDetailsView(SashForm mainSashForm) { 313 Composite detailsComposite = new Composite(mainSashForm, SWT.NO_BACKGROUND); 437 private void createRightHandSideView(SashForm mainSashForm) { 438 rightHandComposite = new Composite(mainSashForm, SWT.NO_BACKGROUND); 439 rightHandLayout = new StackLayout(); 440 rightHandComposite.setLayout(rightHandLayout); 441 442 detailsComposite = new Composite(rightHandComposite, SWT.NO_BACKGROUND); 314 443 detailsComposite.setLayout(new GridLayout(1, false)); 315 444 detailsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); … … 328 457 VisualizationUtils.addExpansionListener(taskDetailsTree, defaultExpansionListener); 329 458 330 VisualizationUtils.addItemSpecificContextMenu (taskDetailsTree, ITask.class,331 459 VisualizationUtils.addItemSpecificContextMenu 460 (taskDetailsTree, ITask.class, "show in task list", new SelectionAdapter() 332 461 { 333 462 @Override … … 336 465 } 337 466 }); 467 468 if (taskExportAvailable) { 469 VisualizationUtils.addItemSpecificContextMenu 470 (taskDetailsTree, ITask.class, "export to ConcurTaskTree", new SelectionAdapter() 471 { 472 @Override 473 public void widgetSelected(SelectionEvent e) { 474 export((ITask) taskDetailsTree.getSelection()[0].getData()); 475 } 476 }); 477 } 338 478 339 479 executionVariantsTree = new Tree(detailsTopSashForm, SWT.BORDER | SWT.SINGLE | SWT.WRAP); … … 355 495 (detailsBottomSashForm, "parent tasks", taskModel); 356 496 357 VisualizationUtils.addItemSpecificContextMenu (parentTasks, ITask.class,358 497 VisualizationUtils.addItemSpecificContextMenu 498 (parentTasks, ITask.class, "show in task list", new SelectionAdapter() 359 499 { 360 500 @Override … … 364 504 }); 365 505 506 if (taskExportAvailable) { 507 VisualizationUtils.addItemSpecificContextMenu 508 (parentTasks, ITask.class, "export to ConcurTaskTree", new SelectionAdapter() 509 { 510 @Override 511 public void widgetSelected(SelectionEvent e) { 512 export((ITask) taskDetailsTree.getSelection()[0].getData()); 513 } 514 }); 515 } 516 366 517 involvedTargetsTree = 367 518 VisualizationUtils.createTargetsTree(detailsBottomSashForm, "involved GUI elements"); 519 520 visualizationsComposite = new Composite(rightHandComposite, SWT.NO_BACKGROUND); 521 visualizationsComposite.setLayout(new GridLayout(1, false)); 522 visualizationsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 523 524 new Label(visualizationsComposite, SWT.NONE).setText("Visualization:"); 525 526 rightHandLayout.topControl = detailsComposite; 368 527 369 528 detailsBottomSashForm.setWeights(new int[] { 2, 3 }); … … 590 749 displayTaskDetails(task); 591 750 } 751 752 /** 753 * 754 */ 755 private void export(ITask task) { 756 try { 757 Class<?> exportClass = this.getClass().getClassLoader().loadClass 758 ("de.ugoe.cs.autoquest.plugin.exports.tasktree.CTTExportUtils"); 759 760 Method method = exportClass.getDeclaredMethod("exportToCTT", ITask.class, String.class); 761 762 method.invoke(null, task, task.getId() + "_ctte.xml"); 763 } 764 catch (Exception e) { 765 Console.logException(e); 766 } 767 } 592 768 593 769 /** … … 680 856 } 681 857 } 858 859 /** 860 * 861 */ 862 private void showVisualization(String name) { 863 Color backgroundColor = visualizationsComposite.getBackground(); 864 Composite parent = new Composite(visualizationsComposite, SWT.EMBEDDED); 865 parent.setLayout(new GridLayout(1, false)); 866 parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); 867 868 Frame chartFrame = SWT_AWT.new_Frame(parent); 869 chartFrame.setBackground(new java.awt.Color(backgroundColor.getRed(), 870 backgroundColor.getGreen(), 871 backgroundColor.getBlue())); 872 873 chartFrame.setLayout(new java.awt.GridLayout()); 874 875 List<ITaskModel> models = new LinkedList<>(); 876 models.add(taskModel); 877 878 List<String> names = new LinkedList<>(); 879 names.add(name); 880 881 List<Integer> groups = new LinkedList<>(); 882 groups.add(0); 883 884 JFreeChart chart = TaskTreePlotUtils.createPlot(name, models, names, groups); 885 chartFrame.add(new ChartPanel(chart)); 886 887 modelVisualizationTree.getSelection()[0].setData(chart); 888 889 rightHandComposite.layout(); 890 rightHandComposite.redraw(); 891 rightHandComposite.update(); 892 } 893 894 /** 895 * 896 */ 897 private void clearVisualization() { 898 for (Control child : visualizationsComposite.getChildren()) { 899 child.dispose(); 900 } 901 902 visualizationsComposite.pack(); 903 } 682 904 } -
trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/VisualizationUtils.java
r1921 r2033 116 116 117 117 for (int i = 0; i < metrics.length; i++) { 118 int contextValue = Integer.MIN_VALUE; 119 120 if (parent.getData() instanceof ITask) { 121 contextValue = taskInfo.getMeasureValue(metrics[i]); 122 } 123 124 if (contextValue > Integer.MIN_VALUE) { 125 values[i + 1] = metrics[i].formatValue(contextValue) + "(" + 126 metrics[i].formatValue(taskInfo.getMeasureValue(metrics[i])) + ")"; 127 } 128 else { 129 values[i + 1] = metrics[i].formatValue(taskInfo.getMeasureValue(metrics[i])); 130 } 118 values[i + 1] = metrics[i].formatValue(taskInfo.getMeasureValue(metrics[i])); 131 119 } 132 120
Note: See TracChangeset
for help on using the changeset viewer.