Search in sources :

Example 1 with ReferencedComposite

use of org.eclipse.reddeer.core.reference.ReferencedComposite in project jbosstools-openshift by jbosstools.

the class ShellWithButton method lookForShellWithButton.

private static org.eclipse.swt.widgets.Shell lookForShellWithButton(final String title, final String buttonLabel) {
    Matcher<String> titleMatcher = new WithTextMatcher(title);
    Matcher<String> buttonMatcher = new BaseMatcher<String>() {

        @Override
        public boolean matches(Object obj) {
            if (obj instanceof Control) {
                final Control control = (Control) obj;
                ReferencedComposite ref = new ReferencedComposite() {

                    @Override
                    public Control getControl() {
                        return control;
                    }
                };
                try {
                    new PushButton(ref, buttonLabel);
                    return true;
                } catch (CoreLayerException e) {
                // ok, this control doesn't contain the button
                }
            }
            return false;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("containing button '" + buttonLabel + "'");
        }
    };
    @SuppressWarnings("unchecked") Matcher<String> matcher = new AndMatcher(titleMatcher, buttonMatcher);
    return ShellLookup.getInstance().getShell(matcher);
}
Also used : AndMatcher(org.eclipse.reddeer.common.matcher.AndMatcher) Control(org.eclipse.swt.widgets.Control) Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) WithTextMatcher(org.eclipse.reddeer.core.matcher.WithTextMatcher) PushButton(org.eclipse.reddeer.swt.impl.button.PushButton) CoreLayerException(org.eclipse.reddeer.core.exception.CoreLayerException) ReferencedComposite(org.eclipse.reddeer.core.reference.ReferencedComposite)

Aggregations

AndMatcher (org.eclipse.reddeer.common.matcher.AndMatcher)1 CoreLayerException (org.eclipse.reddeer.core.exception.CoreLayerException)1 WithTextMatcher (org.eclipse.reddeer.core.matcher.WithTextMatcher)1 ReferencedComposite (org.eclipse.reddeer.core.reference.ReferencedComposite)1 PushButton (org.eclipse.reddeer.swt.impl.button.PushButton)1 Control (org.eclipse.swt.widgets.Control)1 BaseMatcher (org.hamcrest.BaseMatcher)1 Description (org.hamcrest.Description)1