| /******************************************************************************* |
| * Copyright (c) 2010 SAP AG, Walldorf. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * SAP AG - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.platform.discovery.testutils.utils.abbot.matchers;
|
|
|
| import org.eclipse.swt.custom.CLabel;
|
| import org.eclipse.swt.widgets.Link;
|
| import org.eclipse.swt.widgets.Widget;
|
| import org.eclipse.ui.forms.widgets.Hyperlink;
|
|
|
| import abbot.swt.finder.matchers.WidgetTextMatcher;
|
|
|
| /**
|
| * Text matcher which extends {@link WidgetTextMatcher} and adds support for some unsupported controls (e.g. CLabel)
|
| * @author Danail Branekov
|
| */
|
| @SuppressWarnings("rawtypes")
|
| public class EnhancedTextMatcher extends WidgetTextMatcher
|
| {
|
| private final String text;
|
|
|
| public EnhancedTextMatcher(String text, boolean mustBeShowing, Class clazz)
|
| {
|
| super(text, clazz, mustBeShowing);
|
| this.text = text;
|
| }
|
|
|
| public EnhancedTextMatcher(String text, boolean mustBeShowing)
|
| {
|
| super(text, mustBeShowing);
|
| this.text = text;
|
| }
|
|
|
| public EnhancedTextMatcher(String text, Class clazz)
|
| {
|
| super(text, clazz);
|
| this.text = text;
|
| }
|
|
|
| public EnhancedTextMatcher(String text)
|
| {
|
| super(text);
|
| this.text = text;
|
| }
|
|
|
| @Override
|
| public boolean matches(Widget w)
|
| {
|
| if(w instanceof CLabel)
|
| {
|
| return handleCLabel((CLabel)w);
|
| }
|
|
|
| if(w instanceof Link)
|
| {
|
| return handleLink((Link)w);
|
| }
|
|
|
| if(w instanceof Hyperlink)
|
| {
|
| return handleImageHyperlink((Hyperlink)w);
|
| }
|
|
|
| return super.matches(w);
|
| }
|
|
|
| private boolean handleCLabel(final CLabel clabel)
|
| {
|
| final boolean[] result = new boolean[]{false};
|
| clabel.getDisplay().syncExec(new Runnable(){
|
| @Override
|
| public void run()
|
| {
|
| result[0] = text.equals(clabel.getText());
|
| }});
|
|
|
| return result[0];
|
| }
|
|
|
| private boolean handleLink(final Link link)
|
| {
|
| final boolean[] result = new boolean[]{false};
|
| link.getDisplay().syncExec(new Runnable(){
|
| @Override
|
| public void run()
|
| {
|
| result[0] = text.equals(link.getText());
|
| }});
|
|
|
| return result[0];
|
| }
|
|
|
| private boolean handleImageHyperlink(final Hyperlink link)
|
| {
|
| final boolean[] result = new boolean[]{false};
|
| link.getDisplay().syncExec(new Runnable(){
|
| @Override
|
| public void run()
|
| {
|
| result[0] = text.equals(link.getText());
|
| }});
|
|
|
| return result[0];
|
| }
|
| }
|