| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Finder |
|
| 1.0;1 |
| 1 | /******************************************************************************* | |
| 2 | * Copyright (c) 2008 Ketan Padegaonkar and others. | |
| 3 | * All rights reserved. This program and the accompanying materials | |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 5 | * which accompanies this distribution, and is available at | |
| 6 | * http://www.eclipse.org/legal/epl-v10.html | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * Ketan Padegaonkar - initial API and implementation | |
| 10 | *******************************************************************************/ | |
| 11 | package org.eclipse.swtbot.swt.finder.finders; | |
| 12 | ||
| 13 | import java.util.List; | |
| 14 | ||
| 15 | import org.eclipse.swt.widgets.Display; | |
| 16 | import org.eclipse.swt.widgets.Menu; | |
| 17 | import org.eclipse.swt.widgets.MenuItem; | |
| 18 | import org.eclipse.swt.widgets.Shell; | |
| 19 | import org.eclipse.swt.widgets.Widget; | |
| 20 | import org.eclipse.swtbot.swt.finder.utils.TreePath; | |
| 21 | import org.hamcrest.Matcher; | |
| 22 | ||
| 23 | /** | |
| 24 | * A wrapper around {@link ControlFinder} and {@link MenuFinder} that delegates to either of them. | |
| 25 | * | |
| 26 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 27 | * @version $Id$ | |
| 28 | */ | |
| 29 | public class Finder { | |
| 30 | ||
| 31 | /** | |
| 32 | * The control finder to use. | |
| 33 | */ | |
| 34 | private final ControlFinder controlFinder; | |
| 35 | /** | |
| 36 | * The menu finder to use. | |
| 37 | */ | |
| 38 | private final MenuFinder menuFinder; | |
| 39 | /** | |
| 40 | * The display to use. | |
| 41 | */ | |
| 42 | private final Display display; | |
| 43 | ||
| 44 | /** | |
| 45 | * Constructs the finder with the given control and menu finder. | |
| 46 | * | |
| 47 | * @param controlFinder the finder that finds controls. | |
| 48 | * @param menuFinder the finder that finds menus. | |
| 49 | */ | |
| 50 | 3357 | public Finder(ControlFinder controlFinder, MenuFinder menuFinder) { |
| 51 | 3357 | this.controlFinder = controlFinder; |
| 52 | 3357 | this.menuFinder = menuFinder; |
| 53 | 3357 | display = controlFinder.display; |
| 54 | 3357 | } |
| 55 | ||
| 56 | /** | |
| 57 | * Establishes the finder from an existing finder (control finder only) and the given new menu finder. | |
| 58 | * | |
| 59 | * @param finder the finder | |
| 60 | * @param menuFinder the finder that finds menus. | |
| 61 | */ | |
| 62 | public Finder(Finder finder, MenuFinder menuFinder) { | |
| 63 | 0 | this(finder.controlFinder, menuFinder); |
| 64 | 0 | } |
| 65 | ||
| 66 | /** | |
| 67 | * Gets the currently active shell. | |
| 68 | * | |
| 69 | * @return the active shell. | |
| 70 | * @see ControlFinder#activeShell() | |
| 71 | */ | |
| 72 | public Shell activeShell() { | |
| 73 | 13 | return controlFinder.activeShell(); |
| 74 | } | |
| 75 | ||
| 76 | /** | |
| 77 | * Finds the controls in the active shell matching the given matcher. | |
| 78 | * <p> | |
| 79 | * This method is thread safe. | |
| 80 | * </p> | |
| 81 | * | |
| 82 | * @param matcher the matcher used to find controls in the active shell. | |
| 83 | * @return all controls in the active shell that the matcher matches. | |
| 84 | * @see ControlFinder#findControls(Matcher) | |
| 85 | */ | |
| 86 | public <T extends Widget> List<T> findControls(Matcher<T> matcher) { | |
| 87 | 2119 | return controlFinder.findControls(matcher); |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Finds the controls matching one of the widgets using the given matcher. If recursive is set, it will attempt to | |
| 92 | * recursively find the controls in each {@code children} widget if they exist. | |
| 93 | * | |
| 94 | * @param children the list of widgets. | |
| 95 | * @param matcher the matcher used to match the widgets. | |
| 96 | * @param recursive if the match should be recursive. | |
| 97 | * @return all visible widgets in the children that the matcher matches. If recursive is <code>true</code> then find | |
| 98 | * the widgets within each of the widget. | |
| 99 | * @see ControlFinder#findControls(List, Matcher, boolean) | |
| 100 | */ | |
| 101 | public <T extends Widget> List<T> findControls(List<Widget> children, Matcher<T> matcher, boolean recursive) { | |
| 102 | 0 | return controlFinder.findControls(children, matcher, recursive); |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Finds the controls starting with the given parent widget and uses the given matcher. If recursive is set, it will | |
| 107 | * attempt to find the controls in each child widget if they exist. | |
| 108 | * <p> | |
| 109 | * This method is thread safe. | |
| 110 | * </p> | |
| 111 | * | |
| 112 | * @param widget the parent widget in which controls should be found. | |
| 113 | * @param matcher the matcher used to match the widgets. | |
| 114 | * @param recursive if the match should be recursive. | |
| 115 | * @return all visible widgets in the parentWidget that the matcher matches. If recursive is <code>true</code> then | |
| 116 | * find the widget within each of the parentWidget. | |
| 117 | * @see ControlFinder#findControls(Widget, Matcher, boolean) | |
| 118 | */ | |
| 119 | public <T extends Widget> List<T> findControls(Widget widget, Matcher<T> matcher, boolean recursive) { | |
| 120 | 24 | return controlFinder.findControls(widget, matcher, recursive); |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Finds the shell matching the given text (shell.getText()). | |
| 125 | * | |
| 126 | * @param text The text on the Shell | |
| 127 | * @return A Shell containing the specified text | |
| 128 | * @see ControlFinder#findShells(String) | |
| 129 | */ | |
| 130 | public List<Shell> findShells(String text) { | |
| 131 | 0 | return controlFinder.findShells(text); |
| 132 | } | |
| 133 | ||
| 134 | /** | |
| 135 | * Gets the shells registered with the display. | |
| 136 | * | |
| 137 | * @return the shells | |
| 138 | * @see ControlFinder#getShells() | |
| 139 | */ | |
| 140 | public Shell[] getShells() { | |
| 141 | 61 | return controlFinder.getShells(); |
| 142 | } | |
| 143 | ||
| 144 | /** | |
| 145 | * Finds a menu matching the given item in all available shells. This searches for menus recursively. | |
| 146 | * | |
| 147 | * @param matcher the matcher that can match menus and menu items. | |
| 148 | * @return all menus in all shells that match the matcher. | |
| 149 | * @see MenuFinder#findMenus(Matcher) | |
| 150 | */ | |
| 151 | public List<MenuItem> findMenus(Matcher<MenuItem> matcher) { | |
| 152 | 0 | return menuFinder.findMenus(matcher); |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * Fins all the menus in the given menu bar matching the given matcher. If recursive is set, it will attempt to find | |
| 157 | * the controls recursively in each of the menus it that is found. | |
| 158 | * | |
| 159 | * @param bar the menu bar | |
| 160 | * @param matcher the matcher that can match menus and menu items. | |
| 161 | * @param recursive if set to true, will find sub-menus as well. | |
| 162 | * @return all menus in the specified menubar that match the matcher. | |
| 163 | * @see MenuFinder#findMenus(Menu, Matcher, boolean) | |
| 164 | */ | |
| 165 | public List<MenuItem> findMenus(Menu bar, Matcher<MenuItem> matcher, boolean recursive) { | |
| 166 | 0 | return menuFinder.findMenus(bar, matcher, recursive); |
| 167 | } | |
| 168 | ||
| 169 | /** | |
| 170 | * Finds the menus in the given shell using the given matcher. If recursive is set, it will attempt to find the | |
| 171 | * controls recursively in each of the menus it that is found. | |
| 172 | * | |
| 173 | * @param shell the shell to probe for menus. | |
| 174 | * @param matcher the matcher that can match menus and menu items. | |
| 175 | * @param recursive if set to true, will find sub-menus as well. | |
| 176 | * @return all menus in the specified shell that match the matcher. | |
| 177 | * @see MenuFinder#findMenus(Shell, Matcher, boolean) | |
| 178 | */ | |
| 179 | public List<MenuItem> findMenus(Shell shell, Matcher<MenuItem> matcher, boolean recursive) { | |
| 180 | 0 | return menuFinder.findMenus(shell, matcher, recursive); |
| 181 | } | |
| 182 | ||
| 183 | /** | |
| 184 | * Finds all the menus using the given matcher in the set of shells provided. If recursive is set, it will attempt | |
| 185 | * to find the controls recursively in each of the menus it that is found. | |
| 186 | * | |
| 187 | * @param shells the shells to probe for menus. | |
| 188 | * @param matcher the matcher that can match menus and menu items. | |
| 189 | * @param recursive if set to true, will find sub-menus as well. | |
| 190 | * @return all menus in the specified shells that match the matcher. | |
| 191 | * @see MenuFinder#findMenus(Shell[], Matcher, boolean) | |
| 192 | */ | |
| 193 | public List<MenuItem> findMenus(Shell[] shells, Matcher<MenuItem> matcher, boolean recursive) { | |
| 194 | 0 | return menuFinder.findMenus(shells, matcher, recursive); |
| 195 | } | |
| 196 | ||
| 197 | /** | |
| 198 | * Checks if this should return items that are not visible when performing the search for controls. | |
| 199 | * | |
| 200 | * @return <code>true</code> if the finder should return items that are not visible. Otherwise <code>false</code> is | |
| 201 | * returned to show no items will be returned if they are not visible. | |
| 202 | * @since 1.0 | |
| 203 | */ | |
| 204 | public boolean shouldFindInvisibleControls() { | |
| 205 | 0 | return controlFinder.shouldFindInVisibleControls; |
| 206 | } | |
| 207 | ||
| 208 | /** | |
| 209 | * This sets the flag to know if items should be returned if they are not visible. | |
| 210 | * | |
| 211 | * @param shouldFindInVisibleControls <code>true</code> to cause controls that are not visible to be found. Use | |
| 212 | * false so that controls that are visible will be returned. | |
| 213 | * @since 1.0 | |
| 214 | */ | |
| 215 | public void setShouldFindInvisibleControls(boolean shouldFindInVisibleControls) { | |
| 216 | 0 | controlFinder.shouldFindInVisibleControls = shouldFindInVisibleControls; |
| 217 | 0 | } |
| 218 | ||
| 219 | /** | |
| 220 | * Gets the display that has been set. | |
| 221 | * | |
| 222 | * @return the display | |
| 223 | */ | |
| 224 | public Display getDisplay() { | |
| 225 | 0 | return display; |
| 226 | } | |
| 227 | ||
| 228 | ||
| 229 | /** | |
| 230 | * Gets the path to the widget. The path is the list of all parent containers of the widget. | |
| 231 | * | |
| 232 | * @param w the widget. | |
| 233 | * @return the path to the widget w. | |
| 234 | * @since 2.0 | |
| 235 | * @see ControlFinder#getPath(Widget) | |
| 236 | */ | |
| 237 | public TreePath getPath(Widget w) { | |
| 238 | 0 | return controlFinder.getPath(w); |
| 239 | } | |
| 240 | ||
| 241 | } |