1 | 22 | |
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.ToolItem; |
15 | |
import org.eclipse.swtbot.swt.finder.ReferenceBy; |
16 | |
import org.eclipse.swtbot.swt.finder.SWTBotWidget; |
17 | |
import org.eclipse.swtbot.swt.finder.Style; |
18 | |
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; |
19 | |
import org.eclipse.swtbot.swt.finder.results.BoolResult; |
20 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
21 | |
import org.eclipse.swtbot.swt.finder.utils.MessageFormat; |
22 | |
import org.eclipse.swtbot.swt.finder.utils.SWTUtils; |
23 | |
import org.eclipse.swtbot.swt.finder.utils.internal.Assert; |
24 | |
import org.hamcrest.SelfDescribing; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
@SWTBotWidget(clasz = ToolItem.class, preferredName = "toolbarRadioButton", style = @Style(name = "SWT.RADIO", value = SWT.RADIO), referenceBy = { |
33 | |
ReferenceBy.MNEMONIC, ReferenceBy.TOOLTIP }, returnType = SWTBotToolbarRadioButton.class) |
34 | |
public class SWTBotToolbarRadioButton extends SWTBotToolbarButton { |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public SWTBotToolbarRadioButton(ToolItem w) throws WidgetNotFoundException { |
43 | 0 | this(w, null); |
44 | 0 | } |
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public SWTBotToolbarRadioButton(ToolItem w, SelfDescribing description) throws WidgetNotFoundException { |
54 | 14 | super(w, description); |
55 | 14 | Assert.isTrue(SWTUtils.hasStyle(w, SWT.RADIO), "Expecting a radio button."); |
56 | 14 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public SWTBotToolbarRadioButton toggle() { |
64 | 6 | log.debug(MessageFormat.format("Clicking on {0}", this)); |
65 | 6 | waitForEnabled(); |
66 | 6 | internalToggle(); |
67 | 6 | sendNotifications(); |
68 | 6 | log.debug(MessageFormat.format("Clicked on {0}", this)); |
69 | 6 | return this; |
70 | |
} |
71 | |
|
72 | |
public SWTBotToolbarRadioButton click() { |
73 | 2 | return toggle(); |
74 | |
} |
75 | |
|
76 | |
private void internalToggle() { |
77 | 6 | syncExec(new VoidResult() { |
78 | |
public void run() { |
79 | 6 | widget.setSelection(!widget.getSelection()); |
80 | 6 | } |
81 | |
}); |
82 | 6 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public void select() { |
88 | 2 | if (!isChecked()) |
89 | 2 | toggle(); |
90 | 2 | } |
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public void deselect() { |
96 | 1 | if (isChecked()) |
97 | 1 | toggle(); |
98 | 1 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public boolean isChecked() { |
104 | 11 | return syncExec(new BoolResult() { |
105 | |
public Boolean run() { |
106 | 11 | return widget.getSelection(); |
107 | |
} |
108 | |
}); |
109 | |
} |
110 | |
} |