| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PreviousWidgetFinder |
|
| 1.5;1.5 |
| 1 | 674 | /******************************************************************************* |
| 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 finds the previous widget. | |
| 19 | * <p> | |
| 20 | * <b>NOTE: This finds all the siblings and finds the index of the previous 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 NextWidgetFinder | |
| 27 | * @see WidgetIndexFinder | |
| 28 | */ | |
| 29 | public final class PreviousWidgetFinder implements WidgetResult<Widget> { | |
| 30 | /** | |
| 31 | * The widget to use. | |
| 32 | */ | |
| 33 | private final Widget w; | |
| 34 | ||
| 35 | /** | |
| 36 | * Constructs the previous widget finder. | |
| 37 | * | |
| 38 | * @param w the widget | |
| 39 | */ | |
| 40 | 674 | public PreviousWidgetFinder(Widget w) { |
| 41 | 674 | this.w = w; |
| 42 | 674 | } |
| 43 | ||
| 44 | /** | |
| 45 | * Runs the processing to find the previous widget. | |
| 46 | * | |
| 47 | * @see org.eclipse.swtbot.swt.finder.results.WidgetResult#run() | |
| 48 | * @return The widget found or <code>null</code> if not found. | |
| 49 | */ | |
| 50 | public Widget run() { | |
| 51 | 674 | Widget[] siblings = new SiblingFinder(w).run(); |
| 52 | 674 | int myIndex = new WidgetIndexFinder(w).run(); |
| 53 | 674 | return myIndex > 0 ? siblings[myIndex - 1] : null; |
| 54 | } | |
| 55 | } |