|
29 | 29 | import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl; |
30 | 30 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel; |
31 | 31 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; |
| 32 | +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf; |
| 33 | +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType; |
| 34 | +import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText; |
32 | 35 |
|
33 | 36 | /** |
34 | 37 | * Launchbar CDT helper class to select items from launch targets |
@@ -103,73 +106,80 @@ public LaunchBarTargetSelector select(String text) |
103 | 106 |
|
104 | 107 | public LaunchBarTargetSelector selectTarget(String text) |
105 | 108 | { |
106 | | - click(); |
107 | | - SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP); |
108 | | - ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)); |
109 | | - int numberOfItemsInScrolledComp = syncExec( |
110 | | - () -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length); |
111 | | - Label itemToSelect; |
112 | | - |
113 | | - // Set the text in the not visible text field |
114 | | - // when the target list is too big, swtbot cannot select a target label, so we filter the list |
115 | | - if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP) |
116 | | - { |
117 | | - swtBotShell.bot().text().setText(text); |
118 | | - itemToSelect = swtBotShell.bot().label(0).widget; |
119 | | - } |
120 | | - else |
121 | | - { |
122 | | - itemToSelect = swtBotShell.bot().widget(withText(text)); |
123 | | - } |
124 | | - |
125 | | - Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation); |
126 | | - clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect); |
127 | | - return this; |
| 109 | + click(); |
| 110 | + SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP); |
| 111 | + ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)); |
| 112 | + int numberOfItemsInScrolledComp = syncExec( |
| 113 | + () -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length); |
| 114 | + Label itemToSelect; |
| 115 | + |
| 116 | + if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP) |
| 117 | + { |
| 118 | + swtBotShell.bot().text().setText(text); |
| 119 | + itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text))); |
| 120 | + } |
| 121 | + else |
| 122 | + { |
| 123 | + itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text))); |
| 124 | + } |
| 125 | + |
| 126 | + Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation); |
| 127 | + clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect); |
| 128 | + return this; |
128 | 129 | } |
129 | 130 |
|
130 | | - public boolean isTargetPresent(String text) |
| 131 | + public void scrollToBottom(ScrolledComposite scrolledComposite) |
131 | 132 | { |
132 | | - click(); |
| 133 | + syncExec(() -> { |
| 134 | + scrolledComposite.setOrigin(0, scrolledComposite.getClientArea().height); |
| 135 | + }); |
| 136 | + } |
133 | 137 |
|
134 | | - try |
135 | | - { |
136 | | - SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP); |
137 | | - ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)); |
138 | | - |
139 | | - int numberOfItemsInScrolledComp = syncExec(() -> |
140 | | - ((Composite) scrolledComposite.getChildren()[0]).getChildren().length |
141 | | - ); |
142 | | - |
143 | | - if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP) |
144 | | - { |
145 | | - swtBotShell.bot().text().setText(text); |
146 | | - |
147 | | - List<? extends Widget> labels = swtBotShell.bot().widgets(widgetOfType(Label.class)); |
148 | | - for (Widget widget : labels) |
149 | | - { |
150 | | - String labelText = syncExec(() -> ((Label) widget).getText()); |
151 | | - if (labelText.equals(text)) |
152 | | - { |
153 | | - return true; |
154 | | - } |
155 | | - } |
156 | | - return false; |
157 | | - } |
158 | | - else |
159 | | - { |
160 | | - Widget itemToCheck = swtBotShell.bot().widget(withText(text)); |
161 | | - String labelText = syncExec(() -> ((Label) itemToCheck).getText()); |
162 | | - return labelText.equals(text); |
163 | | - } |
164 | | - } |
165 | | - catch (WidgetNotFoundException e) |
166 | | - { |
167 | | - return false; |
168 | | - } |
169 | | - catch (Exception e) |
170 | | - { |
171 | | - e.printStackTrace(); |
172 | | - return false; |
173 | | - } |
| 138 | + public boolean isTargetPresent(String text) |
| 139 | + { |
| 140 | + click(); |
| 141 | + |
| 142 | + try |
| 143 | + { |
| 144 | + SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP); |
| 145 | + ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)); |
| 146 | + |
| 147 | + int numberOfItemsInScrolledComp = syncExec(() -> |
| 148 | + ((Composite) scrolledComposite.getChildren()[0]).getChildren().length |
| 149 | + ); |
| 150 | + |
| 151 | + // Scroll to the bottom if there are many items |
| 152 | + if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP) |
| 153 | + { |
| 154 | + scrollToBottom(swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class))); |
| 155 | + swtBotShell.bot().text().setText(text); |
| 156 | + |
| 157 | + List<? extends Widget> labels = swtBotShell.bot().widgets(widgetOfType(Label.class)); |
| 158 | + for (Widget widget : labels) |
| 159 | + { |
| 160 | + String labelText = syncExec(() -> ((Label) widget).getText()); |
| 161 | + if (labelText.equals(text)) |
| 162 | + { |
| 163 | + return true; |
| 164 | + } |
| 165 | + } |
| 166 | + return false; |
| 167 | + } |
| 168 | + else |
| 169 | + { |
| 170 | + Widget itemToCheck = swtBotShell.bot().widget(withText(text)); |
| 171 | + String labelText = syncExec(() -> ((Label) itemToCheck).getText()); |
| 172 | + return labelText.equals(text); |
| 173 | + } |
| 174 | + } |
| 175 | + catch (WidgetNotFoundException e) |
| 176 | + { |
| 177 | + return false; |
| 178 | + } |
| 179 | + catch (Exception e) |
| 180 | + { |
| 181 | + e.printStackTrace(); |
| 182 | + return false; |
| 183 | + } |
174 | 184 | } |
175 | 185 | } |
0 commit comments