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