1 | 486 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.eclipse.swtbot.swt.finder.widgets; |
12 | |
|
13 | |
import org.eclipse.swt.SWT; |
14 | |
import org.eclipse.swt.widgets.Event; |
15 | |
import org.eclipse.swt.widgets.TabFolder; |
16 | |
import org.eclipse.swt.widgets.TabItem; |
17 | |
import org.eclipse.swtbot.swt.finder.ReferenceBy; |
18 | |
import org.eclipse.swtbot.swt.finder.SWTBot; |
19 | |
import org.eclipse.swtbot.swt.finder.SWTBotWidget; |
20 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
21 | |
import org.eclipse.swtbot.swt.finder.results.BoolResult; |
22 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
23 | |
import org.eclipse.swtbot.swt.finder.results.WidgetResult; |
24 | |
import org.eclipse.swtbot.swt.finder.utils.MessageFormat; |
25 | |
import org.eclipse.swtbot.swt.finder.utils.SWTUtils; |
26 | |
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; |
27 | |
import org.hamcrest.SelfDescribing; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
@SWTBotWidget(clasz = TabItem.class, preferredName = "tabItem", referenceBy = { ReferenceBy.MNEMONIC }) |
35 | |
public class SWTBotTabItem extends AbstractSWTBot<TabItem> { |
36 | |
|
37 | 486 | private TabFolder parent; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public SWTBotTabItem(TabItem w) throws WidgetNotFoundException { |
46 | 1 | this(w, null); |
47 | 1 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public SWTBotTabItem(TabItem w, SelfDescribing description) throws WidgetNotFoundException { |
57 | 245 | super(w, description); |
58 | 245 | this.parent = syncExec(new WidgetResult<TabFolder>() { |
59 | |
public TabFolder run() { |
60 | 245 | return widget.getParent(); |
61 | |
} |
62 | |
}); |
63 | 245 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public SWTBotTabItem activate() throws TimeoutException { |
72 | 243 | log.trace(MessageFormat.format("Activating {0}", this)); |
73 | 243 | waitForEnabled(); |
74 | |
|
75 | 243 | asyncExec(new VoidResult() { |
76 | |
public void run() { |
77 | 243 | widget.getParent().setSelection(widget); |
78 | 243 | log.debug(MessageFormat.format("Activated {0}", this)); |
79 | 243 | } |
80 | |
}); |
81 | |
|
82 | 243 | notify(SWT.Selection, createEvent(), parent); |
83 | |
|
84 | 243 | new SWTBot().waitUntil(new DefaultCondition() { |
85 | |
public boolean test() throws Exception { |
86 | 243 | return isActive(); |
87 | |
} |
88 | |
|
89 | |
public String getFailureMessage() { |
90 | 0 | return "Timed out waiting for " + SWTUtils.toString(widget) + " to activate"; |
91 | |
} |
92 | |
}); |
93 | 243 | return this; |
94 | |
} |
95 | |
|
96 | |
protected Event createEvent() { |
97 | 243 | Event event = super.createEvent(); |
98 | 243 | event.widget = parent; |
99 | 243 | event.item = widget; |
100 | 243 | return event; |
101 | |
} |
102 | |
|
103 | |
public boolean isActive() { |
104 | 243 | return syncExec(new BoolResult() { |
105 | |
public Boolean run() { |
106 | 243 | return parent.getSelection()[0] == widget; |
107 | |
} |
108 | |
}); |
109 | |
} |
110 | |
|
111 | |
public boolean isEnabled() { |
112 | 243 | return syncExec(new BoolResult() { |
113 | |
public Boolean run() { |
114 | 243 | return parent.isEnabled(); |
115 | |
} |
116 | |
}); |
117 | |
} |
118 | |
|
119 | |
} |