| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| WithPartName |
|
| 1.4;1.4 |
| 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 | * Ketan Padegaonkar - http://swtbot.org/bugzilla/show_bug.cgi?id=126 | |
| 11 | * Ketan Patel (bug 260088) | |
| 12 | *******************************************************************************/ | |
| 13 | package org.eclipse.swtbot.eclipse.finder.matchers; | |
| 14 | ||
| 15 | import static org.hamcrest.Matchers.equalTo; | |
| 16 | ||
| 17 | import org.eclipse.swtbot.swt.finder.matchers.AbstractMatcher; | |
| 18 | import org.eclipse.ui.IWorkbenchPartReference; | |
| 19 | import org.hamcrest.Description; | |
| 20 | import org.hamcrest.Factory; | |
| 21 | import org.hamcrest.Matcher; | |
| 22 | ||
| 23 | ||
| 24 | /** | |
| 25 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 26 | * @author Ketan Patel | |
| 27 | * @version $Id$ | |
| 28 | * @since 2.0 | |
| 29 | */ | |
| 30 | public class WithPartName<T extends IWorkbenchPartReference> extends AbstractMatcher<T> { | |
| 31 | ||
| 32 | private final Matcher<String> nameMatcher; | |
| 33 | ||
| 34 | /** | |
| 35 | * @param nameMatcher the part name matcher. | |
| 36 | */ | |
| 37 | 35 | public WithPartName(Matcher<String> nameMatcher) { |
| 38 | 35 | this.nameMatcher = nameMatcher; |
| 39 | 35 | } |
| 40 | ||
| 41 | public boolean doMatch(Object item) { | |
| 42 | 307 | if (item instanceof IWorkbenchPartReference) { |
| 43 | 307 | IWorkbenchPartReference part = (IWorkbenchPartReference) item; |
| 44 | 307 | return nameMatcher.matches(part.getPartName()); |
| 45 | } | |
| 46 | 0 | return false; |
| 47 | } | |
| 48 | ||
| 49 | public void describeTo(Description description) { | |
| 50 | 4 | description.appendText("with name '").appendDescriptionOf(nameMatcher).appendText("'"); |
| 51 | 4 | } |
| 52 | ||
| 53 | /** | |
| 54 | * Matches a workbench part (view/editor) with the specfied name. | |
| 55 | * | |
| 56 | * @param text the label of the part. | |
| 57 | * @return a matcher. | |
| 58 | * @since 2.0 | |
| 59 | */ | |
| 60 | @Factory | |
| 61 | public static <T extends IWorkbenchPartReference> Matcher<T> withPartName(String text) { | |
| 62 | 35 | return withPartName(equalTo(text)); |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Matches a workbench part (view/editor) with the specified name. | |
| 67 | * | |
| 68 | * @param nameMatcher the part name matcher. | |
| 69 | * @return a matcher. | |
| 70 | * @since 2.0 | |
| 71 | */ | |
| 72 | @Factory | |
| 73 | public static <T extends IWorkbenchPartReference> Matcher<T> withPartName(Matcher<String> nameMatcher) { | |
| 74 | 35 | return new WithPartName<T>(nameMatcher); |
| 75 | } | |
| 76 | } |