| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NextWidgetFinder |
|
| 2.0;2 |
| 1 | 2 | /******************************************************************************* |
| 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.utils.internal; | |
| 12 | ||
| 13 | ||
| 14 | import org.eclipse.swt.widgets.Widget; | |
| 15 | import org.eclipse.swtbot.swt.finder.results.WidgetResult; | |
| 16 | ||
| 17 | /** | |
| 18 | * This object is used to find the next widget. | |
| 19 | * <p> | |
| 20 | * <b>NOTE: This finds all the siblings and finds the index of the next widget among the siblings. This does not use | |
| 21 | * SWTUtils to find siblings and index for the widget that this instance wraps for performance reasons.</b> | |
| 22 | * </p> | |
| 23 | * | |
| 24 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 25 | * @version $Id$ | |
| 26 | * @see PreviousWidgetFinder | |
| 27 | * @see WidgetIndexFinder | |
| 28 | */ | |
| 29 | public class NextWidgetFinder implements WidgetResult<Widget> { | |
| 30 | ||
| 31 | /** | |
| 32 | * The widget to use. | |
| 33 | */ | |
| 34 | private final Widget w; | |
| 35 | ||
| 36 | /** | |
| 37 | * Constructs the next widget finder. | |
| 38 | * | |
| 39 | * @param w the widget | |
| 40 | */ | |
| 41 | 2 | public NextWidgetFinder(Widget w) { |
| 42 | 2 | this.w = w; |
| 43 | 2 | } |
| 44 | ||
| 45 | /** | |
| 46 | * Runs the processing to find the next widget. | |
| 47 | * | |
| 48 | * @see org.eclipse.swtbot.swt.finder.results.WidgetResult#run() | |
| 49 | * @return The next widget or <code>null</code> if not found. | |
| 50 | */ | |
| 51 | public Widget run() { | |
| 52 | 2 | Widget[] siblings = new SiblingFinder(w).run(); |
| 53 | 2 | int widgetIndex = new WidgetIndexFinder(w).run(); |
| 54 | 2 | if (widgetIndex < siblings.length - 1) |
| 55 | 1 | return siblings[widgetIndex + 1]; |
| 56 | 1 | return null; |
| 57 | } | |
| 58 | } |