| 1 | 14 | |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
package org.eclipse.swtbot.swt.finder.widgets; |
| 14 | |
|
| 15 | |
import java.util.ArrayList; |
| 16 | |
import java.util.Arrays; |
| 17 | |
import java.util.List; |
| 18 | |
|
| 19 | |
import org.eclipse.swt.SWT; |
| 20 | |
import org.eclipse.swt.graphics.Point; |
| 21 | |
import org.eclipse.swt.graphics.Rectangle; |
| 22 | |
import org.eclipse.swt.widgets.Event; |
| 23 | |
import org.eclipse.swt.widgets.Tree; |
| 24 | |
import org.eclipse.swt.widgets.TreeItem; |
| 25 | |
import org.eclipse.swtbot.swt.finder.SWTBot; |
| 26 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
| 27 | |
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
| 28 | |
import org.eclipse.swtbot.swt.finder.results.ArrayResult; |
| 29 | |
import org.eclipse.swtbot.swt.finder.results.BoolResult; |
| 30 | |
import org.eclipse.swtbot.swt.finder.results.IntResult; |
| 31 | |
import org.eclipse.swtbot.swt.finder.results.ListResult; |
| 32 | |
import org.eclipse.swtbot.swt.finder.results.Result; |
| 33 | |
import org.eclipse.swtbot.swt.finder.results.StringResult; |
| 34 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
| 35 | |
import org.eclipse.swtbot.swt.finder.results.WidgetResult; |
| 36 | |
import org.eclipse.swtbot.swt.finder.utils.MessageFormat; |
| 37 | |
import org.eclipse.swtbot.swt.finder.utils.SWTUtils; |
| 38 | |
import org.eclipse.swtbot.swt.finder.utils.TableRow; |
| 39 | |
import org.eclipse.swtbot.swt.finder.utils.TextDescription; |
| 40 | |
import org.eclipse.swtbot.swt.finder.utils.internal.Assert; |
| 41 | |
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; |
| 42 | |
import org.hamcrest.SelfDescribing; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public class SWTBotTreeItem extends AbstractSWTBot<TreeItem> { |
| 51 | |
|
| 52 | |
|
| 53 | 13 | private Tree tree; |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
public SWTBotTreeItem(final TreeItem treeItem) throws WidgetNotFoundException { |
| 60 | 50 | this(treeItem, null); |
| 61 | 50 | } |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
public SWTBotTreeItem(final TreeItem treeItem, SelfDescribing description) throws WidgetNotFoundException { |
| 69 | 63 | super(treeItem, description); |
| 70 | 63 | this.tree = syncExec(new WidgetResult<Tree>() { |
| 71 | |
public Tree run() { |
| 72 | 63 | return treeItem.getParent(); |
| 73 | |
} |
| 74 | |
}); |
| 75 | 63 | } |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
public String cell(final int column) { |
| 85 | 9 | if (column == 0) { |
| 86 | 2 | return getText(); |
| 87 | |
} |
| 88 | 7 | int columnCount = new SWTBotTree(tree).columnCount(); |
| 89 | 7 | Assert.isLegal(column < columnCount, java.text.MessageFormat.format("The column index ({0}) is more than the number of column({1}) in the tree.", column, columnCount)); |
| 90 | 5 | return syncExec(new StringResult() { |
| 91 | |
public String run() { |
| 92 | 5 | return widget.getText(column); |
| 93 | |
} |
| 94 | |
}); |
| 95 | |
} |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
public TableRow row() { |
| 103 | 1 | return syncExec(new Result<TableRow>() { |
| 104 | |
public TableRow run() { |
| 105 | 1 | int columnCount = tree.getColumnCount(); |
| 106 | 1 | TableRow tableRow = new TableRow(); |
| 107 | 1 | if (columnCount == 0) |
| 108 | 0 | tableRow.add(widget.getText()); |
| 109 | |
else |
| 110 | 5 | for (int j = 0; j < columnCount; j++) |
| 111 | 4 | tableRow.add(widget.getText(j)); |
| 112 | 1 | return tableRow; |
| 113 | |
} |
| 114 | |
}); |
| 115 | |
} |
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
public int rowCount() { |
| 123 | 11 | return syncExec(new IntResult() { |
| 124 | |
public Integer run() { |
| 125 | 11 | return widget.getItemCount(); |
| 126 | |
} |
| 127 | |
}); |
| 128 | |
} |
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
public SWTBotTreeItem getNode(final int row) { |
| 138 | 7 | int rowCount = rowCount(); |
| 139 | 7 | Assert.isLegal(row < rowCount, java.text.MessageFormat.format("The row number ({0}) is more than the number of rows({1}) in the tree.", row, rowCount)); |
| 140 | 6 | return syncExec(new Result<SWTBotTreeItem>() { |
| 141 | |
public SWTBotTreeItem run() { |
| 142 | 6 | return new SWTBotTreeItem(widget.getItem(row)); |
| 143 | |
} |
| 144 | |
}); |
| 145 | |
} |
| 146 | |
|
| 147 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
public String cell(final int row, final int column) { |
| 157 | 3 | return getNode(row).cell(column); |
| 158 | |
} |
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
public SWTBotTreeItem expand() { |
| 166 | 26 | assertEnabled(); |
| 167 | |
|
| 168 | 26 | if (isExpanded()){ |
| 169 | 0 | log.warn(MessageFormat.format("Tree item {0} is already expanded. Won''t expand it again.", this)); |
| 170 | 0 | return this; |
| 171 | |
} |
| 172 | |
|
| 173 | 26 | preExpandNotify(); |
| 174 | 26 | asyncExec(new VoidResult() { |
| 175 | |
public void run() { |
| 176 | 26 | widget.setExpanded(true); |
| 177 | 26 | } |
| 178 | |
}); |
| 179 | 26 | postExpandNotify(); |
| 180 | 26 | return this; |
| 181 | |
} |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public SWTBotTreeItem collapse() { |
| 189 | 0 | assertEnabled(); |
| 190 | |
|
| 191 | 0 | if (!isExpanded()){ |
| 192 | 0 | log.warn(MessageFormat.format("Tree item {0} is already collapsed. Won''t collapse it again.", this)); |
| 193 | 0 | return this; |
| 194 | |
} |
| 195 | |
|
| 196 | 0 | preCollapseNotify(); |
| 197 | 0 | asyncExec(new VoidResult() { |
| 198 | |
public void run() { |
| 199 | 0 | widget.setExpanded(false); |
| 200 | 0 | } |
| 201 | |
}); |
| 202 | 0 | postCollapseNotify(); |
| 203 | 0 | return this; |
| 204 | |
} |
| 205 | |
|
| 206 | |
private void preExpandNotify() { |
| 207 | 26 | notifyTree(SWT.Expand, createEvent()); |
| 208 | 26 | } |
| 209 | |
|
| 210 | |
private void postExpandNotify() { |
| 211 | 26 | notifyTree(SWT.MouseMove); |
| 212 | 26 | notifyTree(SWT.Activate); |
| 213 | 26 | notifyTree(SWT.FocusIn); |
| 214 | 26 | notifyTree(SWT.MouseDown); |
| 215 | 26 | notifyTree(SWT.MeasureItem); |
| 216 | 26 | notifyTree(SWT.Deactivate); |
| 217 | 26 | notifyTree(SWT.FocusOut); |
| 218 | 26 | } |
| 219 | |
|
| 220 | |
private void preCollapseNotify() { |
| 221 | 0 | notifyTree(SWT.Collapse, createEvent()); |
| 222 | 0 | } |
| 223 | |
|
| 224 | |
private void postCollapseNotify() { |
| 225 | 0 | notifyTree(SWT.MouseMove); |
| 226 | 0 | notifyTree(SWT.Activate); |
| 227 | 0 | notifyTree(SWT.FocusIn); |
| 228 | 0 | notifyTree(SWT.MouseDown); |
| 229 | 0 | notifyTree(SWT.MeasureItem); |
| 230 | 0 | notifyTree(SWT.Deactivate); |
| 231 | 0 | notifyTree(SWT.FocusOut); |
| 232 | 0 | } |
| 233 | |
|
| 234 | |
private void notifyTree(int eventType) { |
| 235 | 237 | notify(eventType, createEvent(), tree); |
| 236 | 237 | } |
| 237 | |
|
| 238 | |
private void notifyTree(int eventType, Event event) { |
| 239 | 36 | notify(eventType, event, tree); |
| 240 | 36 | } |
| 241 | |
|
| 242 | |
protected Event createEvent() { |
| 243 | 271 | Event event = super.createEvent(); |
| 244 | 271 | event.widget = tree; |
| 245 | 271 | event.item = widget; |
| 246 | 271 | return event; |
| 247 | |
} |
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
public List<String> getNodes() { |
| 255 | 1 | return syncExec(new ListResult<String>() { |
| 256 | |
public List<String> run() { |
| 257 | 1 | TreeItem[] items = widget.getItems(); |
| 258 | 1 | List<String> result = new ArrayList<String>(items.length); |
| 259 | 3 | for (TreeItem item : items) |
| 260 | 2 | result.add(item.getText()); |
| 261 | 1 | return result; |
| 262 | |
} |
| 263 | |
}); |
| 264 | |
|
| 265 | |
} |
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
public SWTBotTreeItem expandNode(final String... nodes) { |
| 275 | 6 | Assert.isNotEmpty((Object[]) nodes); |
| 276 | 6 | assertEnabled(); |
| 277 | |
|
| 278 | 6 | SWTBotTreeItem item = this; |
| 279 | 14 | for (String node : nodes) |
| 280 | 8 | item = item.getNode(node).expand(); |
| 281 | |
|
| 282 | 6 | return item; |
| 283 | |
} |
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
public SWTBotTreeItem collapseNode(final String nodeText) { |
| 292 | 0 | assertEnabled(); |
| 293 | 0 | return getNode(nodeText).collapse(); |
| 294 | |
} |
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
public SWTBotTreeItem getNode(final String nodeText, final int index) { |
| 305 | 13 | List<SWTBotTreeItem> nodes = getNodes(nodeText); |
| 306 | 13 | Assert.isTrue(index < nodes.size(), MessageFormat.format("The index ({0}) was more than the number of nodes ({1}) in the tree.", index, nodes.size())); |
| 307 | 12 | return nodes.get(index); |
| 308 | |
} |
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
|
| 317 | |
public List<SWTBotTreeItem> getNodes(final String nodeText) { |
| 318 | 13 | List<SWTBotTreeItem> foundItems = syncExec(new ListResult<SWTBotTreeItem>() { |
| 319 | |
public List<SWTBotTreeItem> run() { |
| 320 | 13 | TreeItem[] items = widget.getItems(); |
| 321 | 13 | List<SWTBotTreeItem> results = new ArrayList<SWTBotTreeItem>(); |
| 322 | 34 | for (TreeItem treeItem : items) { |
| 323 | 21 | if (treeItem.getText().equals(nodeText)) |
| 324 | 13 | results.add(new SWTBotTreeItem(treeItem, new TextDescription("Tree node with text: " + nodeText))); |
| 325 | |
} |
| 326 | 13 | return results; |
| 327 | |
} |
| 328 | |
}); |
| 329 | 13 | if (foundItems.isEmpty()) |
| 330 | 0 | throw new WidgetNotFoundException("Could not find node with text: " + nodeText); |
| 331 | 13 | return foundItems; |
| 332 | |
} |
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
public SWTBotTreeItem getNode(final String nodeText) { |
| 342 | 11 | return getNode(nodeText, 0); |
| 343 | |
} |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
public SWTBotTreeItem select() { |
| 352 | 1 | assertEnabled(); |
| 353 | 1 | syncExec(new VoidResult() { |
| 354 | |
public void run() { |
| 355 | 1 | tree.setFocus(); |
| 356 | 1 | tree.setSelection(widget); |
| 357 | 1 | } |
| 358 | |
}); |
| 359 | 1 | notifySelect(); |
| 360 | 1 | return this; |
| 361 | |
} |
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
@Override |
| 371 | |
protected void clickXY(int x, int y) { |
| 372 | 2 | log.debug(MessageFormat.format("Clicking on {0}", this)); |
| 373 | 2 | notifyTree(SWT.MouseEnter); |
| 374 | 2 | notifyTree(SWT.MouseMove); |
| 375 | 2 | notifyTree(SWT.Activate); |
| 376 | 2 | notifyTree(SWT.FocusIn); |
| 377 | 2 | notifyTree(SWT.MouseDown, createMouseEvent(x, y, 1, SWT.NONE, 1)); |
| 378 | 2 | notifyTree(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1)); |
| 379 | 2 | notifyTree(SWT.Selection, createSelectionEvent(SWT.BUTTON1)); |
| 380 | 2 | notifyTree(SWT.MouseHover); |
| 381 | 2 | notifyTree(SWT.MouseMove); |
| 382 | 2 | notifyTree(SWT.MouseExit); |
| 383 | 2 | notifyTree(SWT.Deactivate); |
| 384 | 2 | notifyTree(SWT.FocusOut); |
| 385 | 2 | log.debug(MessageFormat.format("Clicked on {0}", this)); |
| 386 | 2 | } |
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
public SWTBotTreeItem click() { |
| 395 | 1 | assertEnabled(); |
| 396 | 1 | Rectangle cellBounds = syncExec(new Result<Rectangle>() { |
| 397 | |
public Rectangle run() { |
| 398 | 1 | return widget.getBounds(); |
| 399 | |
} |
| 400 | |
}); |
| 401 | 1 | Point center = getCenter(cellBounds); |
| 402 | 1 | clickXY(center.x, center.y); |
| 403 | 1 | return this; |
| 404 | |
} |
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
|
| 411 | |
|
| 412 | |
public SWTBotTreeItem click(final int column) { |
| 413 | 1 | assertEnabled(); |
| 414 | 1 | Rectangle cellBounds = syncExec(new Result<Rectangle>() { |
| 415 | |
public Rectangle run() { |
| 416 | 1 | return widget.getBounds(column); |
| 417 | |
} |
| 418 | |
}); |
| 419 | 1 | Point center = getCenter(cellBounds); |
| 420 | 1 | clickXY(center.x, center.y); |
| 421 | 1 | return this; |
| 422 | |
} |
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
private Point getCenter(Rectangle bounds) { |
| 430 | 2 | return new Point (bounds.x + (bounds.width / 2), bounds.y + (bounds.height / 2)); |
| 431 | |
} |
| 432 | |
|
| 433 | |
|
| 434 | |
|
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
public SWTBotTreeItem doubleClick() { |
| 440 | 2 | assertEnabled(); |
| 441 | 2 | asyncExec(new VoidResult() { |
| 442 | |
public void run() { |
| 443 | 2 | tree.setSelection(widget); |
| 444 | 2 | } |
| 445 | |
}); |
| 446 | 2 | notifyTree(SWT.Selection, createSelectionEvent(SWT.BUTTON1)); |
| 447 | 2 | notifyTree(SWT.MouseDown); |
| 448 | 2 | notifyTree(SWT.MouseUp); |
| 449 | 2 | notifyTree(SWT.MouseDown); |
| 450 | 2 | notifyTree(SWT.MouseDoubleClick); |
| 451 | 2 | notifyTree(SWT.DefaultSelection); |
| 452 | 2 | notifyTree(SWT.MouseUp); |
| 453 | 2 | return this; |
| 454 | |
} |
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
public SWTBotTreeItem select(final String... items) { |
| 464 | 1 | assertEnabled(); |
| 465 | 1 | final List<String> nodes = Arrays.asList(items); |
| 466 | 1 | Assert.isTrue(getNodes().containsAll(nodes)); |
| 467 | |
|
| 468 | 1 | syncExec(new VoidResult() { |
| 469 | |
public void run() { |
| 470 | 1 | ArrayList<TreeItem> selection = new ArrayList<TreeItem>(); |
| 471 | |
|
| 472 | 3 | for (String item : items) { |
| 473 | 2 | SWTBotTreeItem si = getTreeItem(item); |
| 474 | 2 | selection.add(si.widget); |
| 475 | |
} |
| 476 | 1 | tree.setFocus(); |
| 477 | 1 | tree.setSelection(selection.toArray(new TreeItem[] {})); |
| 478 | 1 | } |
| 479 | |
}); |
| 480 | |
|
| 481 | 1 | notifySelect(); |
| 482 | 1 | return this; |
| 483 | |
} |
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
|
| 492 | |
public SWTBotTreeItem select(final String item) { |
| 493 | 0 | return select(new String[] { item }); |
| 494 | |
} |
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
private void notifySelect() { |
| 502 | 2 | notifyTree(SWT.MouseEnter); |
| 503 | 2 | notifyTree(SWT.MouseMove); |
| 504 | 2 | notifyTree(SWT.Activate); |
| 505 | 2 | notifyTree(SWT.FocusIn); |
| 506 | 2 | notifyTree(SWT.MouseDown); |
| 507 | 2 | notifyTree(SWT.Selection); |
| 508 | 2 | notifyTree(SWT.MouseUp); |
| 509 | 2 | notifyTree(SWT.MouseHover); |
| 510 | 2 | notifyTree(SWT.MouseMove); |
| 511 | 2 | notifyTree(SWT.MouseExit); |
| 512 | 2 | notifyTree(SWT.Deactivate); |
| 513 | 2 | notifyTree(SWT.FocusOut); |
| 514 | 2 | } |
| 515 | |
|
| 516 | |
@Override |
| 517 | |
public String getText() { |
| 518 | 11 | return SWTUtils.getText(widget); |
| 519 | |
} |
| 520 | |
|
| 521 | |
@Override |
| 522 | |
public SWTBotMenu contextMenu(String text) { |
| 523 | 1 | new SWTBotTree(tree).waitForEnabled(); |
| 524 | 1 | select(); |
| 525 | 1 | notifyTree(SWT.MouseDown, createMouseEvent(0, 0, 3, 0, 1)); |
| 526 | 1 | notifyTree(SWT.MouseUp, createMouseEvent(0, 0, 3, 0, 1)); |
| 527 | 1 | notifyTree(SWT.MenuDetect); |
| 528 | 1 | return super.contextMenu(tree, text); |
| 529 | |
} |
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
public void toggleCheck() { |
| 537 | 2 | setChecked(!isChecked()); |
| 538 | 2 | } |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
public void check() { |
| 546 | 2 | setChecked(true); |
| 547 | 1 | } |
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
|
| 554 | |
public void uncheck() { |
| 555 | 1 | setChecked(false); |
| 556 | 1 | } |
| 557 | |
|
| 558 | |
|
| 559 | |
|
| 560 | |
|
| 561 | |
|
| 562 | |
|
| 563 | |
|
| 564 | |
public boolean isChecked() { |
| 565 | 7 | assertIsCheck(); |
| 566 | 7 | return syncExec(new BoolResult() { |
| 567 | |
public Boolean run() { |
| 568 | 7 | return widget.getChecked(); |
| 569 | |
} |
| 570 | |
}); |
| 571 | |
} |
| 572 | |
|
| 573 | |
|
| 574 | |
|
| 575 | |
|
| 576 | |
|
| 577 | |
|
| 578 | 4 | private Event createCheckEvent() { |
| 579 | 4 | Event event = createEvent(); |
| 580 | 4 | event.time = (int) System.currentTimeMillis(); |
| 581 | 4 | event.item = widget; |
| 582 | 4 | event.widget = tree; |
| 583 | 4 | event.detail = SWT.CHECK; |
| 584 | 4 | return event; |
| 585 | |
} |
| 586 | |
|
| 587 | |
private void setChecked(final boolean checked) { |
| 588 | 5 | assertEnabled(); |
| 589 | 5 | assertIsCheck(); |
| 590 | 4 | syncExec(new VoidResult() { |
| 591 | |
public void run() { |
| 592 | 4 | log.debug(MessageFormat.format("Setting state to {0} on: {1}", (checked ? "checked" : "unchecked"), widget.getText())); |
| 593 | 4 | widget.setChecked(checked); |
| 594 | 4 | } |
| 595 | |
}); |
| 596 | 4 | notifyCheck(); |
| 597 | 4 | } |
| 598 | |
|
| 599 | |
private void assertIsCheck() { |
| 600 | 12 | Assert.isLegal(hasStyle(tree, SWT.CHECK), "The tree does not have the style SWT.CHECK"); |
| 601 | 11 | } |
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
|
| 606 | |
|
| 607 | |
|
| 608 | |
private void notifyCheck() { |
| 609 | 4 | syncExec(new VoidResult() { |
| 610 | |
public void run() { |
| 611 | 4 | tree.notifyListeners(SWT.Selection, createCheckEvent()); |
| 612 | 4 | } |
| 613 | |
}); |
| 614 | 4 | } |
| 615 | |
|
| 616 | |
protected void assertEnabled() { |
| 617 | 69 | new SWTBotTree(tree).assertEnabled(); |
| 618 | 69 | } |
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
public boolean isSelected() { |
| 625 | 2 | return UIThreadRunnable.syncExec(new BoolResult() { |
| 626 | |
public Boolean run() { |
| 627 | 2 | return Arrays.asList(tree.getSelection()).contains(widget); |
| 628 | |
} |
| 629 | |
}); |
| 630 | |
} |
| 631 | |
|
| 632 | |
|
| 633 | |
|
| 634 | |
|
| 635 | |
|
| 636 | |
|
| 637 | |
|
| 638 | |
|
| 639 | |
public boolean isExpanded() { |
| 640 | 26 | assertEnabled(); |
| 641 | 26 | return UIThreadRunnable.syncExec(new BoolResult() { |
| 642 | |
public Boolean run() { |
| 643 | 26 | return widget.getExpanded(); |
| 644 | |
} |
| 645 | |
}); |
| 646 | |
} |
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | |
public SWTBotTreeItem[] getItems() { |
| 655 | 1 | return syncExec(new ArrayResult<SWTBotTreeItem>() { |
| 656 | |
public SWTBotTreeItem[] run() { |
| 657 | 1 | TreeItem[] items = widget.getItems(); |
| 658 | 1 | SWTBotTreeItem[] children = new SWTBotTreeItem[items.length]; |
| 659 | 3 | for (int i = 0; i < items.length; i++) { |
| 660 | 2 | children[i] = new SWTBotTreeItem(items[i]); |
| 661 | |
} |
| 662 | 1 | return children; |
| 663 | |
} |
| 664 | |
}); |
| 665 | |
} |
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | 2 | private SWTBotTreeItem getTreeItem(final String nodeText) throws WidgetNotFoundException { |
| 675 | |
try { |
| 676 | 2 | new SWTBot().waitUntil(new DefaultCondition() { |
| 677 | |
public String getFailureMessage() { |
| 678 | 0 | return "Could not find node with text " + nodeText; |
| 679 | |
} |
| 680 | |
|
| 681 | |
public boolean test() throws Exception { |
| 682 | 2 | return getItem(nodeText) != null; |
| 683 | |
} |
| 684 | |
}); |
| 685 | 0 | } catch (TimeoutException e) { |
| 686 | 0 | throw new WidgetNotFoundException("Timed out waiting for tree item " + nodeText, e); |
| 687 | |
} |
| 688 | 2 | return new SWTBotTreeItem(getItem(nodeText)); |
| 689 | |
} |
| 690 | |
|
| 691 | |
|
| 692 | |
|
| 693 | |
|
| 694 | |
|
| 695 | |
|
| 696 | |
|
| 697 | 2 | private TreeItem getItem(final String nodeText) { |
| 698 | 4 | return syncExec(new WidgetResult<TreeItem>() { |
| 699 | |
public TreeItem run() { |
| 700 | 4 | TreeItem[] items = widget.getItems(); |
| 701 | 6 | for (TreeItem item : items) { |
| 702 | 6 | if (item.getText().equals(nodeText)) |
| 703 | 4 | return item; |
| 704 | |
} |
| 705 | 0 | return null; |
| 706 | |
} |
| 707 | |
}); |
| 708 | |
} |
| 709 | |
|
| 710 | |
public boolean isEnabled() { |
| 711 | 0 | return syncExec(new BoolResult() { |
| 712 | |
public Boolean run() { |
| 713 | 0 | return tree.isEnabled(); |
| 714 | |
} |
| 715 | |
}); |
| 716 | |
} |
| 717 | |
|
| 718 | |
} |