Changeset 1153
- Timestamp:
- 04/12/13 15:28:50 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowTaskTreeDialog.java
r1146 r1153 15 15 package de.ugoe.cs.autoquest.ui.swt; 16 16 17 import java.util.Collection; 18 import java.util.HashSet; 17 19 import java.util.List; 20 import java.util.Set; 18 21 19 22 import org.eclipse.swt.SWT; … … 26 29 import org.eclipse.swt.widgets.Dialog; 27 30 import org.eclipse.swt.widgets.Display; 31 import org.eclipse.swt.widgets.Event; 32 import org.eclipse.swt.widgets.Listener; 28 33 import org.eclipse.swt.widgets.Shell; 29 34 import org.eclipse.swt.widgets.Tree; … … 90 95 private void createContents() { 91 96 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 92 shell.setSize( 450, 300);97 shell.setSize(750, 800); 93 98 shell.setText(getText()); 94 99 95 100 shell.setLayout(new GridLayout(4, false)); 96 101 97 SashForm sashForm = new SashForm(shell, SWT. VERTICAL);102 SashForm sashForm = new SashForm(shell, SWT.HORIZONTAL); 98 103 sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1)); 99 104 … … 104 109 modelTree.removeAll(); 105 110 TreeItem[] selectedItems = instanceTree.getSelection(); 106 if ((selectedItems.length == 1) && 107 (selectedItems[0].getData() instanceof ITaskInstance)) 108 { 109 buildModelTree((ITaskInstance) selectedItems[0].getData()); 111 if (selectedItems.length == 1) { 112 if (selectedItems[0].getData() instanceof ITaskInstance) { 113 buildModelTree((ITaskInstance) selectedItems[0].getData()); 114 } 115 else if (selectedItems[0].getData() instanceof ITaskModel) { 116 buildModelTree((ITaskModel) selectedItems[0].getData()); 117 } 110 118 } 111 119 } … … 115 123 116 124 modelTree = new Tree(sashForm, SWT.BORDER | SWT.MULTI); 125 buildModelTree(taskModel); 117 126 118 127 Button btnExpandAll = new Button(shell, SWT.NONE); … … 149 158 TreeItem root = new TreeItem(instanceTree, SWT.NULL); 150 159 root.setText(sessions.size() + " sessions"); 151 root.setData( sessions);160 root.setData(taskModel); 152 161 153 162 for (IUserSession session : sessions) { … … 167 176 buildInstanceTree(child, childTask); 168 177 } 178 } 179 180 /** 181 * 182 */ 183 private void buildModelTree(ITaskModel taskModel) { 184 modelTree.removeAll(); 185 186 // load the correct children on expansion 187 if (modelTree.getListeners(SWT.Expand).length == 0) { 188 modelTree.addListener(SWT.Expand, new Listener() { 189 public void handleEvent(final Event event) { 190 ensureChildren((TreeItem) event.item); 191 ((TreeItem) event.item).setExpanded(true); 192 } 193 }); 194 } 195 196 Collection<ITask> tasks = taskModel.getTasks(); 197 198 TreeItem root = new TreeItem(modelTree, SWT.NULL); 199 root.setText(tasks.size() + " tasks in model"); 200 root.setData(taskModel); 201 202 tasks = determineRootTasks(tasks); 203 204 for (ITask task : tasks) { 205 createTreeItemFor(task, root); 206 } 207 208 root.setExpanded(true); 169 209 } 170 210 … … 178 218 root.setData(taskInstance); 179 219 180 buildModelTree(taskInstance.getTask(), root); 181 expandAll(root, true); 182 } 183 184 /** 185 * 186 */ 187 private void buildModelTree(ITask task, TreeItem parent) { 188 TreeItem node = new TreeItem(parent, SWT.NULL); 189 node.setText(task.toString()); 190 node.setData(task); 191 220 createTreeItemFor(taskInstance.getTask(), root); 221 222 expandAll(root, true, 20); 223 } 224 225 /** 226 * 227 */ 228 private Collection<ITask> determineRootTasks(Collection<ITask> tasks) { 229 Set<ITask> result = new HashSet<ITask>(tasks); 230 231 for (ITask task : tasks) { 232 removeChildren(task, result); 233 } 234 235 return result; 236 } 237 238 /** 239 * 240 */ 241 private void removeChildren(ITask task, Set<ITask> result) { 192 242 if (task instanceof IStructuringTemporalRelationship) { 193 for (ITask subTask: ((IStructuringTemporalRelationship) task).getChildren()) {194 buildModelTree(subTask, node);243 for (ITask child : ((IStructuringTemporalRelationship) task).getChildren()) { 244 result.remove(child); 195 245 } 196 246 } 197 247 else if (task instanceof IMarkingTemporalRelationship) { 198 buildModelTree(((IMarkingTemporalRelationship) task).getMarkedTask(), node);248 result.remove(((IMarkingTemporalRelationship) task).getMarkedTask()); 199 249 } 200 250 } … … 205 255 private void expandAll(Tree tree, boolean expanded) { 206 256 for (TreeItem item : tree.getItems()) { 207 expandAll(item, expanded); 208 } 209 } 210 211 /** 212 * 213 */ 214 private void expandAll(TreeItem item, boolean expanded) { 215 item.setExpanded(expanded); 216 for (TreeItem childItem : item.getItems()) { 217 expandAll(childItem, expanded); 257 expandAll(item, expanded, Integer.MAX_VALUE); 258 } 259 } 260 261 /** 262 * 263 */ 264 private void expandAll(TreeItem item, boolean expanded, int maxChildrenToExpand) { 265 if (expanded) { 266 ensureChildren(item); 267 } 268 269 if (item.getItems().length < maxChildrenToExpand) { 270 item.setExpanded(expanded); 271 272 for (TreeItem childItem : item.getItems()) { 273 expandAll(childItem, expanded, maxChildrenToExpand); 274 } 218 275 } 219 276 } 220 277 278 /** 279 * 280 */ 281 private void ensureChildren(TreeItem parent) { 282 if (parent.getData() instanceof ITask) { 283 TreeItem[] items = parent.getItems(); 284 if ((items == null) || (items.length == 0) || (items[0].getData() == null)) { 285 for (int i = 0; i < items.length; i++) { 286 items[i].dispose(); 287 } 288 289 ITask task = (ITask) parent.getData(); 290 291 if (task instanceof IStructuringTemporalRelationship) { 292 for (ITask subTask : ((IStructuringTemporalRelationship) task).getChildren()) { 293 createTreeItemFor(subTask, parent); 294 } 295 } 296 else if (task instanceof IMarkingTemporalRelationship) { 297 createTreeItemFor 298 (((IMarkingTemporalRelationship) task).getMarkedTask(), parent); 299 } 300 } 301 } 302 } 303 304 /** 305 * 306 */ 307 private void createTreeItemFor(ITask task, TreeItem parent) { 308 TreeItem item = new TreeItem(parent, SWT.NULL); 309 item.setText(task.toString()); 310 item.setData(task); 311 312 // simulate a child 313 if ((task instanceof IStructuringTemporalRelationship) || 314 (task instanceof IMarkingTemporalRelationship)) 315 { 316 new TreeItem(item, SWT.NULL); 317 } 318 } 319 221 320 }
Note: See TracChangeset
for help on using the changeset viewer.