merging in latest changes from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.test / src / test / java / eu / etaxonomy / taxeditor / test / SwtBotUtils.java
1 package eu.etaxonomy.taxeditor.test;
2
3 import java.util.List;
4
5 import org.eclipse.osgi.internal.loader.FilteredSourcePackage;
6 import org.eclipse.swt.widgets.Tree;
7 import org.eclipse.swt.widgets.Widget;
8 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
9 import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
10 import org.eclipse.swtbot.eclipse.finder.waits.Conditions;
11 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
12 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
13 import org.eclipse.swtbot.swt.finder.finders.ChildrenControlFinder;
14 import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
15 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
16
17 public class SwtBotUtils {
18
19 private SWTWorkbenchBot bot;
20
21 public SwtBotUtils(SWTWorkbenchBot bot) {
22 this.bot = bot;
23 }
24
25 /**
26 * @return
27 * @throws WidgetNotFoundException
28 */
29 public SWTBotTree tree(Widget widget) throws WidgetNotFoundException {
30 List<Tree> controls = new ChildrenControlFinder(widget).findControls(WidgetMatcherFactory.widgetOfType(Tree.class));
31 if (controls.isEmpty())
32 throw new WidgetNotFoundException("Could not find any tree");
33 SWTBotTree tree = new SWTBotTree((Tree) controls.get(0));
34 return tree;
35 }
36
37 /**
38 *
39 * @param index the index of the SelectionElement
40 * @param dialogName the title of the expected dialog
41 */
42 public void openFilteredSelection(int index, String dialogName){
43 SWTBotButton existing = bot.buttonWithTooltip("Browse existing", index);
44 existing.click();
45 bot.waitUntil(Conditions.shellIsActive(dialogName));
46 }
47
48 /**
49 * @return
50 * @throws WidgetNotFoundException
51 */
52 public SWTBotView view(String title) throws WidgetNotFoundException {
53 return getBot().viewByTitle(title);
54 }
55
56 public void cancel() {
57 clickButton("Cancel");
58 }
59
60 public void ok() {
61 clickButton("OK");
62 }
63
64 public void finish() {
65 clickButton("Finish");
66 }
67
68 public void clickButton(String label) {
69 getBot().button(label).click();
70 }
71
72 public String getActiveShellHeadline(){
73 return getBot().activeShell().getText();
74 }
75
76 public SWTWorkbenchBot getBot() {
77 return bot;
78 }
79
80 public void setBot(SWTWorkbenchBot bot) {
81 this.bot = bot;
82 }
83 }