Coverage Report - org.eclipse.swtbot.eclipse.finder.matchers.WithPartId
 
Classes in this File Line Coverage Branch Coverage Complexity
WithPartId
0%
0/11
0%
0/2
1.4
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2009 SWTBot Committers 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  
  *     Ralf Ebert www.ralfebert.de - (bug 271630) SWTBot Improved RCP / Workbench support
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.eclipse.finder.matchers;
 12  
 
 13  
 import static org.hamcrest.Matchers.equalTo;
 14  
 
 15  
 import org.eclipse.swtbot.swt.finder.matchers.AbstractMatcher;
 16  
 import org.eclipse.ui.IWorkbenchPartReference;
 17  
 import org.hamcrest.Description;
 18  
 import org.hamcrest.Factory;
 19  
 import org.hamcrest.Matcher;
 20  
 
 21  
 /**
 22  
  * @author Ralf Ebert www.ralfebert.de (bug 271630)
 23  
  * @version $Id$
 24  
  * @since 2.0
 25  
  */
 26  
 public class WithPartId<T extends IWorkbenchPartReference> extends AbstractMatcher<T> {
 27  
 
 28  
         private final Matcher<String>        idMatcher;
 29  
 
 30  0
         WithPartId(Matcher<String> idMatcher) {
 31  0
                 this.idMatcher = idMatcher;
 32  0
         }
 33  
 
 34  
         @Override
 35  
         public boolean doMatch(Object item) {
 36  0
                 if (item instanceof IWorkbenchPartReference) {
 37  0
                         IWorkbenchPartReference part = (IWorkbenchPartReference) item;
 38  0
                         return idMatcher.matches(part.getId());
 39  
                 }
 40  0
                 return false;
 41  
         }
 42  
 
 43  
         public void describeTo(Description description) {
 44  0
                 description.appendText("with id '").appendDescriptionOf(idMatcher).appendText("'");
 45  0
         }
 46  
 
 47  
         /**
 48  
          * Matches a workbench part (view/editor) with the specified id.
 49  
          * 
 50  
          * @param id the id of the part.
 51  
          * @return a matcher.
 52  
          * @since 2.0
 53  
          */
 54  
         @Factory
 55  
         public static <T extends IWorkbenchPartReference> Matcher<T> withPartId(String id) {
 56  0
                 return withPartId(equalTo(id));
 57  
         }
 58  
 
 59  
         /**
 60  
          * Matches a workbench part (view/editor) with the specified id.
 61  
          * 
 62  
          * @param idMatcher the part id matcher.
 63  
          * @return a matcher.
 64  
          * @since 2.0
 65  
          */
 66  
         @Factory
 67  
         public static <T extends IWorkbenchPartReference> Matcher<T> withPartId(Matcher<String> idMatcher) {
 68  0
                 return new WithPartId<T>(idMatcher);
 69  
         }
 70  
 }