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