[1094] | 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 | |
---|
[1424] | 17 | import java.awt.GraphicsDevice; |
---|
| 18 | import java.awt.GraphicsEnvironment; |
---|
[1153] | 19 | import java.util.Collection; |
---|
[1262] | 20 | import java.util.Collections; |
---|
| 21 | import java.util.Comparator; |
---|
| 22 | import java.util.LinkedList; |
---|
[1146] | 23 | import java.util.List; |
---|
| 24 | |
---|
[1094] | 25 | import org.eclipse.swt.SWT; |
---|
[1146] | 26 | import org.eclipse.swt.custom.SashForm; |
---|
[1094] | 27 | import org.eclipse.swt.events.SelectionAdapter; |
---|
| 28 | import org.eclipse.swt.events.SelectionEvent; |
---|
[1424] | 29 | import org.eclipse.swt.events.ShellAdapter; |
---|
| 30 | import org.eclipse.swt.events.ShellEvent; |
---|
| 31 | import org.eclipse.swt.events.ShellListener; |
---|
[1094] | 32 | import org.eclipse.swt.layout.GridData; |
---|
| 33 | import org.eclipse.swt.layout.GridLayout; |
---|
| 34 | import org.eclipse.swt.widgets.Button; |
---|
[1424] | 35 | import org.eclipse.swt.widgets.Composite; |
---|
[1094] | 36 | import org.eclipse.swt.widgets.Dialog; |
---|
| 37 | import org.eclipse.swt.widgets.Display; |
---|
[1153] | 38 | import org.eclipse.swt.widgets.Event; |
---|
[1424] | 39 | import org.eclipse.swt.widgets.Label; |
---|
[1153] | 40 | import org.eclipse.swt.widgets.Listener; |
---|
[1094] | 41 | import org.eclipse.swt.widgets.Shell; |
---|
[1424] | 42 | import org.eclipse.swt.widgets.TabFolder; |
---|
| 43 | import org.eclipse.swt.widgets.TabItem; |
---|
[1094] | 44 | import org.eclipse.swt.widgets.Tree; |
---|
[1424] | 45 | import org.eclipse.swt.widgets.TreeColumn; |
---|
[1094] | 46 | import org.eclipse.swt.widgets.TreeItem; |
---|
| 47 | |
---|
[1424] | 48 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
[1146] | 49 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; |
---|
[1424] | 50 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
[1294] | 51 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; |
---|
[1424] | 52 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
[1294] | 53 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; |
---|
[1424] | 54 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
[1146] | 55 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; |
---|
| 56 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
| 57 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
| 58 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList; |
---|
| 59 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
| 60 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
[1636] | 61 | import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric; |
---|
[1094] | 62 | |
---|
| 63 | /** |
---|
| 64 | * <p> |
---|
[1275] | 65 | * a dialog to inspect the tasks and task instances of a task model |
---|
[1094] | 66 | * </p> |
---|
| 67 | * |
---|
| 68 | * @author Patrick Harms |
---|
| 69 | */ |
---|
| 70 | public class ShowTaskTreeDialog extends Dialog { |
---|
| 71 | |
---|
[1275] | 72 | /** the main shell */ |
---|
[1424] | 73 | private Shell shell; |
---|
[1094] | 74 | |
---|
[1424] | 75 | /** the listener for the main shell to prevent disposing required */ |
---|
| 76 | private ShellListener shellListener; |
---|
| 77 | |
---|
| 78 | /** the tab folder containing the instance tree as well as the model tree */ |
---|
| 79 | private TabFolder tabFolder; |
---|
| 80 | |
---|
[1275] | 81 | /** the tree of task instances on the left */ |
---|
[1146] | 82 | private Tree instanceTree; |
---|
| 83 | |
---|
[1424] | 84 | /** the tree of tasks on the left */ |
---|
[1146] | 85 | private Tree modelTree; |
---|
[1424] | 86 | |
---|
| 87 | /** the tree of a specific task on the right */ |
---|
| 88 | private Tree taskDetailsTree; |
---|
[1094] | 89 | |
---|
[1424] | 90 | /** the tree of execution variants of a specific task on the right */ |
---|
| 91 | private Tree executionVariantsTree; |
---|
| 92 | |
---|
| 93 | /** the tree of involved GUI elements of a specific task on the right bottom */ |
---|
[1495] | 94 | private Tree involvedTargetsTree; |
---|
[1424] | 95 | |
---|
| 96 | /** the table containing the parents tasks of a displayed task */ |
---|
| 97 | private Tree parentTasks; |
---|
| 98 | |
---|
[1275] | 99 | /** the displayed task model */ |
---|
[1424] | 100 | private ITaskModel taskModel; |
---|
| 101 | |
---|
| 102 | /** default expansion listener */ |
---|
| 103 | private Listener defaultExpansionListener = new Listener() { |
---|
| 104 | public void handleEvent(final Event event) { |
---|
| 105 | ensureChildren((TreeItem) event.item); |
---|
| 106 | ((TreeItem) event.item).setExpanded(true); |
---|
| 107 | } |
---|
| 108 | }; |
---|
[1094] | 109 | |
---|
| 110 | /** |
---|
[1275] | 111 | * creates the dialog |
---|
[1094] | 112 | */ |
---|
[1146] | 113 | public ShowTaskTreeDialog(Shell parent, int style, ITaskModel taskModel, String taskTreeName) { |
---|
[1094] | 114 | super(parent, style); |
---|
[1146] | 115 | setText("Task Model " + taskTreeName); |
---|
| 116 | this.taskModel = taskModel; |
---|
[1094] | 117 | } |
---|
| 118 | |
---|
| 119 | /** |
---|
[1275] | 120 | * displays the dialog |
---|
[1424] | 121 | * @param task |
---|
[1094] | 122 | */ |
---|
| 123 | public void open() { |
---|
[1424] | 124 | open(null); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | /** |
---|
| 128 | * displays the dialog with a specific task opened |
---|
| 129 | * @param task |
---|
| 130 | */ |
---|
| 131 | public void open(ITask task) { |
---|
| 132 | if (shell == null) { |
---|
| 133 | createContents(); |
---|
| 134 | shell.open(); |
---|
| 135 | shell.layout(); |
---|
| 136 | |
---|
| 137 | VisualizationUtils.updateColumnWidths(taskDetailsTree); |
---|
| 138 | } |
---|
| 139 | else { |
---|
| 140 | shell.setVisible(true); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if (task != null) { |
---|
| 144 | shellListener = new ShellAdapter() { |
---|
| 145 | @Override |
---|
| 146 | public void shellClosed(ShellEvent e) { |
---|
| 147 | e.doit = false; |
---|
| 148 | shell.setVisible(false); |
---|
| 149 | } |
---|
| 150 | }; |
---|
| 151 | |
---|
| 152 | shell.addShellListener(shellListener); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | if (task != null) { |
---|
| 156 | navigateTo(task); |
---|
| 157 | } |
---|
| 158 | |
---|
[1094] | 159 | Display display = getParent().getDisplay(); |
---|
[1424] | 160 | while (!shell.isDisposed() && shell.isVisible()) { |
---|
[1094] | 161 | if (!display.readAndDispatch()) { |
---|
| 162 | display.sleep(); |
---|
| 163 | } |
---|
| 164 | } |
---|
[1424] | 165 | |
---|
| 166 | if (task == null) { |
---|
| 167 | dispose(); |
---|
| 168 | } |
---|
[1094] | 169 | } |
---|
| 170 | |
---|
| 171 | /** |
---|
[1424] | 172 | * disposes the dialog if it is not used anymore |
---|
| 173 | */ |
---|
| 174 | public void dispose() { |
---|
| 175 | if ((shell != null) && (!shell.isDisposed())) { |
---|
| 176 | if (shellListener != null) { |
---|
| 177 | shell.removeShellListener(shellListener); |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | shell.dispose(); |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
[1275] | 185 | * creates the two views, one on the task instances on the left, on on the task models on the |
---|
| 186 | * right. Also adds a selection adapter to the task instances so that for a selected task |
---|
| 187 | * instance always the respective model is presented. |
---|
[1094] | 188 | */ |
---|
| 189 | private void createContents() { |
---|
[1424] | 190 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER); |
---|
| 191 | |
---|
| 192 | GraphicsDevice gd = |
---|
| 193 | GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); |
---|
| 194 | |
---|
| 195 | shell.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); |
---|
[1094] | 196 | shell.setText(getText()); |
---|
| 197 | |
---|
| 198 | shell.setLayout(new GridLayout(4, false)); |
---|
[1146] | 199 | |
---|
[1424] | 200 | SashForm mainSashForm = new SashForm(shell, SWT.HORIZONTAL); |
---|
| 201 | mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); |
---|
[1146] | 202 | |
---|
[1424] | 203 | createSessionsAndTasksTabFolder(mainSashForm); |
---|
| 204 | createTaskDetailsView(mainSashForm); |
---|
| 205 | |
---|
| 206 | mainSashForm.setWeights(new int[] { 1, 3 }); |
---|
| 207 | |
---|
| 208 | Button btnExpandAll = new Button(shell, SWT.NONE); |
---|
| 209 | btnExpandAll.addSelectionListener(new SelectionAdapter() { |
---|
| 210 | @Override |
---|
| 211 | public void widgetSelected(SelectionEvent e) { |
---|
| 212 | if (tabFolder.getSelectionIndex() == 0) { |
---|
| 213 | VisualizationUtils.expandAll(instanceTree, true); |
---|
| 214 | } |
---|
| 215 | else { |
---|
| 216 | VisualizationUtils.expandAll(modelTree, true); |
---|
| 217 | } |
---|
| 218 | } |
---|
| 219 | }); |
---|
| 220 | btnExpandAll.setText("Expand all"); |
---|
| 221 | |
---|
| 222 | Button btnCollapseAll = new Button(shell, SWT.NONE); |
---|
| 223 | btnCollapseAll.addSelectionListener(new SelectionAdapter() { |
---|
| 224 | @Override |
---|
| 225 | public void widgetSelected(SelectionEvent e) { |
---|
| 226 | if (tabFolder.getSelectionIndex() == 0) { |
---|
| 227 | VisualizationUtils.expandAll(instanceTree, false); |
---|
| 228 | } |
---|
| 229 | else { |
---|
| 230 | VisualizationUtils.expandAll(modelTree, false); |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | }); |
---|
| 234 | btnCollapseAll.setText("Collapse all"); |
---|
| 235 | |
---|
| 236 | new Label(shell, SWT.NONE); |
---|
| 237 | new Label(shell, SWT.NONE); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | /** |
---|
| 241 | * |
---|
| 242 | */ |
---|
| 243 | private void createSessionsAndTasksTabFolder(SashForm mainSashForm) { |
---|
| 244 | tabFolder = new TabFolder(mainSashForm, SWT.NONE); |
---|
| 245 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
| 246 | tabFolder.addSelectionListener(new SelectionAdapter() { |
---|
| 247 | @Override |
---|
| 248 | public void widgetSelected(SelectionEvent e) { |
---|
| 249 | VisualizationUtils.updateColumnWidths(modelTree); |
---|
| 250 | } |
---|
| 251 | }); |
---|
| 252 | |
---|
| 253 | TabItem instanceTreeTab = new TabItem(tabFolder, SWT.NONE); |
---|
| 254 | instanceTreeTab.setText("Task Instances"); |
---|
| 255 | |
---|
| 256 | instanceTree = new Tree(tabFolder, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL); |
---|
[1146] | 257 | instanceTree.addSelectionListener(new SelectionAdapter() { |
---|
| 258 | @Override |
---|
| 259 | public void widgetSelected(SelectionEvent e) { |
---|
| 260 | TreeItem[] selectedItems = instanceTree.getSelection(); |
---|
[1424] | 261 | if ((selectedItems.length == 1) && |
---|
| 262 | (selectedItems[0].getData() instanceof ITaskInstance)) |
---|
| 263 | { |
---|
| 264 | displayTaskDetails(((ITaskInstance) selectedItems[0].getData()).getTask()); |
---|
[1146] | 265 | } |
---|
[1424] | 266 | else { |
---|
| 267 | clearTaskDetails(); |
---|
| 268 | } |
---|
[1146] | 269 | } |
---|
| 270 | }); |
---|
[1094] | 271 | |
---|
[1424] | 272 | VisualizationUtils.addItemSpecificContextMenu |
---|
| 273 | (instanceTree, ITaskInstance.class, "show in task list", new SelectionAdapter() |
---|
| 274 | { |
---|
| 275 | @Override |
---|
| 276 | public void widgetSelected(SelectionEvent e) { |
---|
| 277 | navigateTo(((ITaskInstance) instanceTree.getSelection()[0].getData()).getTask()); |
---|
| 278 | } |
---|
| 279 | }); |
---|
| 280 | |
---|
[1146] | 281 | buildInstanceTree(); |
---|
[1424] | 282 | instanceTreeTab.setControl(instanceTree); |
---|
[1094] | 283 | |
---|
[1424] | 284 | TabItem modelTreeTab = new TabItem(tabFolder, SWT.NONE); |
---|
| 285 | modelTreeTab.setText("Tasks"); |
---|
| 286 | |
---|
| 287 | modelTree = |
---|
| 288 | VisualizationUtils.createTaskDetailsTree(tabFolder, "tasks in model", taskModel); |
---|
| 289 | |
---|
| 290 | // show task details if requested |
---|
| 291 | modelTree.addSelectionListener(new SelectionAdapter() { |
---|
| 292 | @Override |
---|
| 293 | public void widgetSelected(SelectionEvent e) { |
---|
| 294 | TreeItem[] selectedItems = modelTree.getSelection(); |
---|
| 295 | if ((selectedItems.length == 1) && (selectedItems[0].getData() instanceof ITask)) { |
---|
| 296 | displayTaskDetails((ITask) selectedItems[0].getData()); |
---|
| 297 | } |
---|
| 298 | else { |
---|
| 299 | clearTaskDetails(); |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | }); |
---|
| 303 | |
---|
[1153] | 304 | buildModelTree(taskModel); |
---|
[1424] | 305 | |
---|
| 306 | modelTreeTab.setControl(modelTree); |
---|
| 307 | } |
---|
[1094] | 308 | |
---|
[1424] | 309 | /** |
---|
| 310 | * |
---|
| 311 | */ |
---|
| 312 | private void createTaskDetailsView(SashForm mainSashForm) { |
---|
| 313 | Composite detailsComposite = new Composite(mainSashForm, SWT.NO_BACKGROUND); |
---|
| 314 | detailsComposite.setLayout(new GridLayout(1, false)); |
---|
| 315 | detailsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
| 316 | |
---|
| 317 | new Label(detailsComposite, SWT.NONE).setText("Task Details:"); |
---|
| 318 | |
---|
| 319 | SashForm detailsSashForm = new SashForm(detailsComposite, SWT.VERTICAL); |
---|
| 320 | detailsSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
| 321 | |
---|
| 322 | SashForm detailsTopSashForm = new SashForm(detailsSashForm, SWT.HORIZONTAL); |
---|
| 323 | detailsTopSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
| 324 | |
---|
| 325 | taskDetailsTree = |
---|
| 326 | VisualizationUtils.createTaskDetailsTree(detailsTopSashForm, "task details", taskModel); |
---|
| 327 | |
---|
| 328 | VisualizationUtils.addExpansionListener(taskDetailsTree, defaultExpansionListener); |
---|
| 329 | |
---|
| 330 | VisualizationUtils.addItemSpecificContextMenu(taskDetailsTree, ITask.class, |
---|
| 331 | "show in task list", new SelectionAdapter() |
---|
| 332 | { |
---|
[1094] | 333 | @Override |
---|
| 334 | public void widgetSelected(SelectionEvent e) { |
---|
[1424] | 335 | navigateTo((ITask) taskDetailsTree.getSelection()[0].getData()); |
---|
[1094] | 336 | } |
---|
| 337 | }); |
---|
[1424] | 338 | |
---|
| 339 | executionVariantsTree = new Tree(detailsTopSashForm, SWT.BORDER | SWT.SINGLE | SWT.WRAP); |
---|
| 340 | executionVariantsTree.setHeaderVisible(true); |
---|
| 341 | |
---|
| 342 | TreeColumn taskColumn = new TreeColumn(executionVariantsTree, SWT.NONE); |
---|
| 343 | taskColumn.setText("instance variants"); |
---|
| 344 | taskColumn.setAlignment(SWT.LEFT); |
---|
[1094] | 345 | |
---|
[1424] | 346 | // load the correct children on expansion |
---|
| 347 | VisualizationUtils.addExpansionListener(executionVariantsTree, defaultExpansionListener); |
---|
| 348 | |
---|
| 349 | detailsTopSashForm.setWeights(new int[] { 3, 2 }); |
---|
| 350 | |
---|
| 351 | SashForm detailsBottomSashForm = new SashForm(detailsSashForm, SWT.HORIZONTAL); |
---|
| 352 | detailsBottomSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); |
---|
| 353 | |
---|
| 354 | parentTasks = VisualizationUtils.createTaskDetailsTree |
---|
| 355 | (detailsBottomSashForm, "parent tasks", taskModel); |
---|
| 356 | |
---|
| 357 | VisualizationUtils.addItemSpecificContextMenu(parentTasks, ITask.class, |
---|
| 358 | "show in task list", new SelectionAdapter() |
---|
| 359 | { |
---|
[1094] | 360 | @Override |
---|
| 361 | public void widgetSelected(SelectionEvent e) { |
---|
[1424] | 362 | navigateTo((ITask) parentTasks.getSelection()[0].getData()); |
---|
[1094] | 363 | } |
---|
| 364 | }); |
---|
| 365 | |
---|
[1495] | 366 | involvedTargetsTree = |
---|
| 367 | VisualizationUtils.createTargetsTree(detailsBottomSashForm, "involved GUI elements"); |
---|
[1424] | 368 | |
---|
| 369 | detailsBottomSashForm.setWeights(new int[] { 2, 3 }); |
---|
| 370 | detailsSashForm.setWeights(new int[] { 1, 1 }); |
---|
[1094] | 371 | } |
---|
| 372 | |
---|
| 373 | /** |
---|
[1275] | 374 | * convenience method for creating the display of the instances |
---|
[1094] | 375 | */ |
---|
[1146] | 376 | private void buildInstanceTree() { |
---|
| 377 | List<IUserSession> sessions = taskModel.getUserSessions(); |
---|
[1424] | 378 | |
---|
| 379 | // load the correct children on expansion |
---|
| 380 | VisualizationUtils.addExpansionListener(instanceTree, defaultExpansionListener); |
---|
| 381 | |
---|
[1146] | 382 | TreeItem root = new TreeItem(instanceTree, SWT.NULL); |
---|
| 383 | root.setText(sessions.size() + " sessions"); |
---|
[1153] | 384 | root.setData(taskModel); |
---|
[1146] | 385 | |
---|
| 386 | for (IUserSession session : sessions) { |
---|
| 387 | buildInstanceTree(root, session); |
---|
| 388 | } |
---|
[1424] | 389 | |
---|
| 390 | root.setExpanded(true); |
---|
[1094] | 391 | } |
---|
| 392 | |
---|
| 393 | /** |
---|
[1275] | 394 | * convenience method for creating the display of the instances |
---|
[1094] | 395 | */ |
---|
[1294] | 396 | private void buildInstanceTree(TreeItem currentParent, IUserSession session) { |
---|
[1424] | 397 | TreeItem item = new TreeItem(currentParent, SWT.NULL); |
---|
| 398 | item.setText(session.toString()); |
---|
| 399 | item.setData(session); |
---|
[1146] | 400 | |
---|
[1424] | 401 | // simulate a child |
---|
| 402 | new TreeItem(item, SWT.NULL); |
---|
[1146] | 403 | } |
---|
| 404 | |
---|
| 405 | /** |
---|
[1275] | 406 | * convenience method for creating the display of the task model |
---|
[1146] | 407 | */ |
---|
[1153] | 408 | private void buildModelTree(ITaskModel taskModel) { |
---|
[1424] | 409 | Collection<ITask> allTasks = taskModel.getTasks(); |
---|
[1153] | 410 | |
---|
[1424] | 411 | List<ITask> sequences = new LinkedList<ITask>(); |
---|
| 412 | List<ITask> iterations = new LinkedList<ITask>(); |
---|
| 413 | List<ITask> selections = new LinkedList<ITask>(); |
---|
| 414 | List<ITask> optionals = new LinkedList<ITask>(); |
---|
| 415 | List<ITask> others = new LinkedList<ITask>(); |
---|
[1153] | 416 | |
---|
| 417 | TreeItem root = new TreeItem(modelTree, SWT.NULL); |
---|
[1424] | 418 | root.setText(allTasks.size() + " tasks in model"); |
---|
[1153] | 419 | root.setData(taskModel); |
---|
| 420 | |
---|
[1424] | 421 | createSortedTaskLists(allTasks, sequences, iterations, selections, optionals, others); |
---|
[1153] | 422 | |
---|
[1424] | 423 | //allTasks = createSortedTaskList(allTasks); |
---|
[1153] | 424 | |
---|
[1424] | 425 | createModelTreeItemFor(sequences, sequences.size() + " Sequences", root); |
---|
| 426 | createModelTreeItemFor(iterations, iterations.size() + " Iterations", root); |
---|
| 427 | createModelTreeItemFor(selections, selections.size() + " Selections", root); |
---|
| 428 | createModelTreeItemFor(optionals, optionals.size() + " Optionals", root); |
---|
| 429 | createModelTreeItemFor(others, others.size() + " other Tasks", root); |
---|
| 430 | |
---|
[1153] | 431 | root.setExpanded(true); |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | /** |
---|
[1424] | 435 | * |
---|
[1153] | 436 | */ |
---|
[1424] | 437 | private void createSortedTaskLists(Collection<ITask> allTasks, |
---|
| 438 | List<ITask> sequences, |
---|
| 439 | List<ITask> iterations, |
---|
| 440 | List<ITask> selections, |
---|
| 441 | List<ITask> optionals, |
---|
| 442 | List<ITask> others) |
---|
| 443 | { |
---|
| 444 | List<ITask> toAdd; |
---|
[1153] | 445 | |
---|
[1424] | 446 | for (ITask task : allTasks) { |
---|
| 447 | if (task instanceof ISequence) { |
---|
| 448 | toAdd = sequences; |
---|
| 449 | } |
---|
| 450 | else if (task instanceof IIteration) { |
---|
| 451 | toAdd = iterations; |
---|
| 452 | } |
---|
| 453 | else if (task instanceof ISelection) { |
---|
| 454 | toAdd = selections; |
---|
| 455 | } |
---|
| 456 | else if (task instanceof IOptional) { |
---|
| 457 | toAdd = optionals; |
---|
| 458 | } |
---|
| 459 | else { |
---|
| 460 | toAdd = others; |
---|
| 461 | } |
---|
| 462 | |
---|
[1636] | 463 | int taskValue = taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE); |
---|
[1424] | 464 | int start = 0; |
---|
| 465 | int end = toAdd.size(); |
---|
| 466 | int center = 0; |
---|
[1636] | 467 | int centerValue; |
---|
[1424] | 468 | |
---|
| 469 | while (start != end) { |
---|
| 470 | center = start + ((end - start) / 2); |
---|
| 471 | |
---|
| 472 | if ((center != start) || (center != end)) { |
---|
[1636] | 473 | //centerValue = toAdd.get(center).getInstances().size(); |
---|
| 474 | centerValue = taskModel.getTaskInfo(toAdd.get(center)).getMeasureValue |
---|
| 475 | (TaskMetric.EVENT_COVERAGE); |
---|
[1424] | 476 | |
---|
[1636] | 477 | if (centerValue > taskValue) { |
---|
[1424] | 478 | start = Math.max(center, start + 1); |
---|
| 479 | } |
---|
[1636] | 480 | else if (centerValue < taskValue) { |
---|
[1424] | 481 | end = Math.min(center, end - 1); |
---|
| 482 | } |
---|
| 483 | else { |
---|
| 484 | // add the event directly where the center is, as the count of the center |
---|
| 485 | // and the new task are equal |
---|
| 486 | end = center; |
---|
| 487 | start = end; |
---|
| 488 | break; |
---|
| 489 | } |
---|
| 490 | } |
---|
| 491 | else { |
---|
| 492 | // add the event to the position denoted by the add index |
---|
| 493 | break; |
---|
| 494 | } |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | toAdd.add(start, task); |
---|
| 498 | } |
---|
[1146] | 499 | } |
---|
| 500 | |
---|
| 501 | /** |
---|
[1424] | 502 | * |
---|
[1146] | 503 | */ |
---|
[1424] | 504 | private void clearTaskDetails() { |
---|
| 505 | taskDetailsTree.removeAll(); |
---|
| 506 | executionVariantsTree.removeAll(); |
---|
[1495] | 507 | involvedTargetsTree.removeAll(); |
---|
[1424] | 508 | parentTasks.removeAll(); |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | /** |
---|
| 512 | * |
---|
| 513 | */ |
---|
| 514 | private void displayTaskDetails(ITask task) { |
---|
| 515 | clearTaskDetails(); |
---|
[1146] | 516 | |
---|
[1424] | 517 | VisualizationUtils.createTreeItemFor(task, taskDetailsTree, taskModel, true); |
---|
| 518 | VisualizationUtils.expandAll(taskDetailsTree, true); |
---|
[1153] | 519 | |
---|
[1424] | 520 | // do it twice. Otherwise, it doesn't work |
---|
| 521 | VisualizationUtils.updateColumnWidths(taskDetailsTree); |
---|
[1262] | 522 | |
---|
[1424] | 523 | Collection<Collection<ITaskInstance>> executionVariants = task.getExecutionVariants(); |
---|
| 524 | List<Collection<ITaskInstance>> sortedExecutionVariants = |
---|
| 525 | new LinkedList<Collection<ITaskInstance>>(executionVariants); |
---|
| 526 | |
---|
| 527 | Collections.sort(sortedExecutionVariants, new Comparator<Collection<ITaskInstance>>() { |
---|
[1262] | 528 | @Override |
---|
[1424] | 529 | public int compare(Collection<ITaskInstance> list1, Collection<ITaskInstance> list2) { |
---|
| 530 | return list2.size() - list1.size(); |
---|
[1262] | 531 | } |
---|
| 532 | }); |
---|
| 533 | |
---|
[1424] | 534 | int counter = 1; |
---|
| 535 | for (Collection<ITaskInstance> variant : sortedExecutionVariants) { |
---|
| 536 | TreeItem item = new TreeItem(executionVariantsTree, SWT.NULL); |
---|
| 537 | if (variant.size() > 1) { |
---|
| 538 | item.setText("variant " + counter++ + " (executed " + variant.size() + " times)"); |
---|
| 539 | } |
---|
| 540 | else { |
---|
| 541 | item.setText("variant " + counter++ + " (executed once)"); |
---|
| 542 | } |
---|
| 543 | item.setData(variant); |
---|
| 544 | |
---|
| 545 | createTreeItemFor(variant.iterator().next(), item); |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | VisualizationUtils.expandAll(executionVariantsTree, true); |
---|
| 549 | VisualizationUtils.updateColumnWidths(executionVariantsTree); |
---|
| 550 | |
---|
| 551 | addParentTasks(task); |
---|
| 552 | VisualizationUtils.updateColumnWidths(parentTasks); |
---|
| 553 | |
---|
[1495] | 554 | VisualizationUtils.addInvolvedTargets(involvedTargetsTree, task); |
---|
[1153] | 555 | } |
---|
| 556 | |
---|
| 557 | /** |
---|
[1424] | 558 | * |
---|
[1153] | 559 | */ |
---|
[1424] | 560 | private void addParentTasks(ITask task) { |
---|
| 561 | for (ITask candidate : taskModel.getTasks()) { |
---|
| 562 | if (((candidate instanceof IStructuringTemporalRelationship) && |
---|
| 563 | (((IStructuringTemporalRelationship) candidate).getChildren().contains(task))) || |
---|
| 564 | ((candidate instanceof IMarkingTemporalRelationship) && |
---|
| 565 | (((IMarkingTemporalRelationship) candidate).getMarkedTask().equals(task)))) |
---|
| 566 | { |
---|
| 567 | VisualizationUtils.createTreeItemFor(candidate, parentTasks, taskModel, false); |
---|
[1094] | 568 | } |
---|
| 569 | } |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | /** |
---|
[1424] | 573 | * |
---|
[1094] | 574 | */ |
---|
[1424] | 575 | private void navigateTo(ITask task) { |
---|
| 576 | tabFolder.setSelection(1); |
---|
[1153] | 577 | |
---|
[1424] | 578 | OUTER: |
---|
| 579 | for (TreeItem sublist : modelTree.getItem(0).getItems()) { |
---|
| 580 | for (TreeItem taskItem : sublist.getItems()) { |
---|
| 581 | if (task.equals(taskItem.getData())) { |
---|
| 582 | modelTree.setSelection(taskItem); |
---|
| 583 | sublist.setExpanded(true); |
---|
| 584 | VisualizationUtils.updateColumnWidths(modelTree); |
---|
| 585 | break OUTER; |
---|
| 586 | } |
---|
[1153] | 587 | } |
---|
| 588 | } |
---|
[1424] | 589 | |
---|
| 590 | displayTaskDetails(task); |
---|
[1094] | 591 | } |
---|
| 592 | |
---|
[1153] | 593 | /** |
---|
[1275] | 594 | * ensures, that the children of a specific node are loaded |
---|
[1153] | 595 | */ |
---|
| 596 | private void ensureChildren(TreeItem parent) { |
---|
[1424] | 597 | TreeItem[] items = parent.getItems(); |
---|
| 598 | if ((items == null) || (items.length == 0) || (items[0].getData() == null)) { |
---|
| 599 | if (items != null) { |
---|
| 600 | for (int i = 0; i < items.length; i++) { |
---|
| 601 | items[i].dispose(); |
---|
[1153] | 602 | } |
---|
[1424] | 603 | } |
---|
[1153] | 604 | |
---|
[1424] | 605 | if (parent.getData() instanceof ITask) { |
---|
[1153] | 606 | ITask task = (ITask) parent.getData(); |
---|
| 607 | |
---|
| 608 | if (task instanceof IStructuringTemporalRelationship) { |
---|
| 609 | for (ITask subTask : ((IStructuringTemporalRelationship) task).getChildren()) { |
---|
[1424] | 610 | VisualizationUtils.createTreeItemFor(subTask, parent, taskModel, true); |
---|
[1153] | 611 | } |
---|
| 612 | } |
---|
| 613 | else if (task instanceof IMarkingTemporalRelationship) { |
---|
[1424] | 614 | VisualizationUtils.createTreeItemFor |
---|
| 615 | (((IMarkingTemporalRelationship) task).getMarkedTask(), parent, |
---|
| 616 | taskModel, true); |
---|
[1153] | 617 | } |
---|
| 618 | } |
---|
[1424] | 619 | else if (parent.getData() instanceof List<?>) { |
---|
| 620 | @SuppressWarnings("unchecked") |
---|
| 621 | List<ITask> tasks = (List<ITask>) parent.getData(); |
---|
| 622 | for (ITask task : tasks) { |
---|
| 623 | VisualizationUtils.createTreeItemFor(task, parent, taskModel, false); |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | else if (parent.getData() instanceof ITaskInstanceList) { |
---|
| 627 | for (ITaskInstance subInstance : (ITaskInstanceList) parent.getData()) { |
---|
| 628 | createTreeItemFor(subInstance, parent); |
---|
| 629 | } |
---|
| 630 | } |
---|
| 631 | else if (parent.getData() instanceof ITaskInstance) { |
---|
| 632 | ITaskInstance instance = (ITaskInstance) parent.getData(); |
---|
| 633 | |
---|
| 634 | if (instance instanceof ISelectionInstance) { |
---|
| 635 | if (((ISelectionInstance) instance).getChild() != null) { |
---|
| 636 | createTreeItemFor(((ISelectionInstance) instance).getChild(), parent); |
---|
| 637 | } |
---|
| 638 | } |
---|
| 639 | else if (instance instanceof IOptionalInstance) { |
---|
| 640 | if (((IOptionalInstance) instance).getChild() != null) { |
---|
| 641 | createTreeItemFor(((IOptionalInstance) instance).getChild(), parent); |
---|
| 642 | } |
---|
| 643 | } |
---|
| 644 | } |
---|
[1153] | 645 | } |
---|
| 646 | } |
---|
| 647 | |
---|
| 648 | /** |
---|
[1424] | 649 | * |
---|
| 650 | */ |
---|
| 651 | private void createModelTreeItemFor(List<ITask> taskList, String name, TreeItem parent) { |
---|
| 652 | TreeItem item = new TreeItem(parent, SWT.NULL); |
---|
| 653 | item.setText(name); |
---|
| 654 | item.setData(taskList); |
---|
| 655 | |
---|
| 656 | // simulate a child |
---|
| 657 | if (taskList.size() > 0) { |
---|
| 658 | for (ITask task : taskList) { |
---|
| 659 | VisualizationUtils.createTreeItemFor(task, item, taskModel, false); |
---|
| 660 | } |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | /** |
---|
[1275] | 665 | * convenience method to create a tree item for a task |
---|
[1153] | 666 | */ |
---|
[1424] | 667 | private void createTreeItemFor(ITaskInstance taskInstance, |
---|
| 668 | TreeItem parent) |
---|
| 669 | { |
---|
[1153] | 670 | TreeItem item = new TreeItem(parent, SWT.NULL); |
---|
[1424] | 671 | item.setText(taskInstance.toString()); |
---|
| 672 | item.setData(taskInstance); |
---|
[1153] | 673 | |
---|
| 674 | // simulate a child |
---|
[1424] | 675 | if ((taskInstance instanceof ITaskInstanceList) || |
---|
| 676 | (taskInstance instanceof ISelectionInstance) || |
---|
| 677 | (taskInstance instanceof IOptionalInstance)) |
---|
[1153] | 678 | { |
---|
| 679 | new TreeItem(item, SWT.NULL); |
---|
| 680 | } |
---|
| 681 | } |
---|
[1094] | 682 | } |
---|