Permalink
Browse files

RESOLVED - 344383: Add support for buttons of type SWT.ARROW

  • Loading branch information...
ketan committed Jun 21, 2011
1 parent f999c52 commit 7b246a8af4b1b2957da5875512da204f1e615e1c
@@ -1,5 +1,6 @@
<widgets>
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotButton" />
+ <widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotArrowButton" />
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox" />
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio" />
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotToggleButton" />
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2008,2010 Ketan Padegaonkar and others.
+ * 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:
+ * Ketan Padegaonkar - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import static org.eclipse.swtbot.swt.finder.SWTBotTestCase.assertTextContains;
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
+import static org.eclipse.swtbot.swt.finder.utils.SWTUtils.hasStyle;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swtbot.swt.finder.finders.AbstractSWTTestCase;
+import org.eclipse.swtbot.swt.finder.finders.ControlFinder;
+import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Ketan Padegaonkar &lt;KetanPadegaonkar [at] gmail [dot] com&gt;
+ * @version $Id$
+ */
+public class SWTBotArrowButtonTest extends AbstractSWTTestCase {
+
+ private long oldTimeout;
+
+ @Before
+ public void lowerTimeout() {
+ this.oldTimeout = SWTBotPreferences.TIMEOUT;
+ SWTBotPreferences.TIMEOUT = 2000;
+ }
+
+ @After
+ public void resetTimeout() {
+ SWTBotPreferences.TIMEOUT = oldTimeout;
+ }
+
+ @Test
+ public void findsArrowButtons() throws Exception {
+ assertEquals(Button.class, bot.arrowButton(0).widget.getClass());
+ assertTrue(hasStyle(bot.arrowButton(0).widget, SWT.ARROW));
+ }
+
+ @Test
+ public void clicksArrowButton() throws Exception {
+ try {
+ List<Text> findControls = new ControlFinder().findControls(widgetOfType(Text.class));
+ SWTBotText text = new SWTBotText(findControls.get(0));
+ text.setText("");
+ assertFalse(bot.checkBox("Listen").isChecked());
+ bot.checkBox("Listen").click();
+ assertTrue(bot.checkBox("Listen").isChecked());
+ bot.arrowButton(0).click();
+ assertTextContains("Selection [13]: SelectionEvent{Button {}", text);
+ } finally {
+ bot.checkBox("Listen").click();
+ bot.button("Clear").click();
+ }
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ bot.tabItem("Button").activate();
+ bot.radio("SWT.ARROW").click();
+ }
+
+}
@@ -60,6 +60,7 @@ public void setUp() throws Exception {
super.setUp();
bot = new SWTBot();
bot.tabItem("Button").activate();
+ bot.radio("SWT.PUSH").click();
}
}
@@ -31,6 +31,7 @@
import org.eclipse.swtbot.swt.finder.finders.Finder;
import org.eclipse.swtbot.swt.finder.finders.MenuFinder;
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotArrowButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotBrowser;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCCombo;
@@ -357,6 +358,178 @@ public SWTBotButton buttonWithTooltipInGroup(String tooltip, String inGroup, int
return new SWTBotButton((Button) widget(matcher, index), matcher);
}
+ /**
+ * @param label the label on the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>label</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonWithLabel(String label) {
+ return arrowButtonWithLabel(label, 0);
+ }
+
+ /**
+ * @param label the label on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>label</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonWithLabel(String label, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withLabel(label), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>tooltip</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonWithTooltip(String tooltip) {
+ return arrowButtonWithTooltip(tooltip, 0);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>tooltip</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonWithTooltip(String tooltip, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withTooltip(tooltip), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param key the key set on the widget.
+ * @param value the value for the key.
+ * @return a {@link SWTBotArrowButton} with the specified <code>key/value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonWithId(String key, String value) {
+ return arrowButtonWithId(key, value, 0);
+ }
+
+ /**
+ * @param key the key set on the widget.
+ * @param value the value for the key.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>key/value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonWithId(String key, String value, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withId(key, value), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param value the value for the key {@link org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences#DEFAULT_KEY}.
+ * @return a {@link SWTBotArrowButton} with the specified <code>value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonWithId(String value) {
+ return arrowButtonWithId(value, 0);
+ }
+
+ /**
+ * @param value the value for the key {@link org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences#DEFAULT_KEY}.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonWithId(String value, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withId(value), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonInGroup(String inGroup) {
+ return arrowButtonInGroup(inGroup, 0);
+ }
+
+ /**
+ * @param inGroup the inGroup on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonInGroup(String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), inGroup(inGroup), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @return a {@link SWTBotArrowButton} with the specified <code>none</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButton() {
+ return arrowButton(0);
+ }
+
+ /**
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>none</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButton(int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param label the label on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>label</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonWithLabelInGroup(String label, String inGroup) {
+ return arrowButtonWithLabelInGroup(label, inGroup, 0);
+ }
+
+ /**
+ * @param label the label on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>label</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonWithLabelInGroup(String label, String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withLabel(label), inGroup(inGroup), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>tooltip</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotArrowButton arrowButtonWithTooltipInGroup(String tooltip, String inGroup) {
+ return arrowButtonWithTooltipInGroup(tooltip, inGroup, 0);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotArrowButton} with the specified <code>tooltip</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotArrowButton arrowButtonWithTooltipInGroup(String tooltip, String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Button.class), withTooltip(tooltip), inGroup(inGroup), withStyle(SWT.ARROW, "SWT.ARROW"));
+ return new SWTBotArrowButton((Button) widget(matcher, index), matcher);
+ }
+
/**
* @param label the label on the widget.
* @return a {@link SWTBotCheckBox} with the specified <code>label</code>.
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Ketan Padegaonkar and others.
+ * 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:
+ * Ketan Padegaonkar - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swtbot.swt.finder.ReferenceBy;
+import org.eclipse.swtbot.swt.finder.SWTBotWidget;
+import org.eclipse.swtbot.swt.finder.Style;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.utils.MessageFormat;
+import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
+import org.eclipse.swtbot.swt.finder.utils.internal.Assert;
+import org.hamcrest.SelfDescribing;
+
+/**
+ * This represents a {@link Button} widget of type {@link SWT#ARROW}.
+ *
+ * @author Ketan Padegaonkar &lt;KetanPadegaonkar [at] gmail [dot] com&gt;
+ * @version $Id$
+ * @see SWTBotCheckBox
+ * @see SWTBotRadio
+ * @see SWTBotToggleButton
+ */
+@SWTBotWidget(clasz = Button.class, style = @Style(name = "SWT.ARROW", value = SWT.ARROW), preferredName = "arrowButton", referenceBy = { ReferenceBy.LABEL, ReferenceBy.TOOLTIP }) //$NON-NLS-1$
+public class SWTBotArrowButton extends AbstractSWTBotControl<Button> {
+
+ /**
+ * Constructs an instance of this object with the given button
+ *
+ * @param button the widget.
+ * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
+ * @since 2.0
+ */
+ public SWTBotArrowButton(Button button) {
+ this(button, null);
+ }
+
+ /**
+ * Constructs an instance of this object with the given button
+ *
+ * @param button the widget.
+ * @param description the description of the widget, this will be reported by {@link #toString()}
+ * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
+ * @since 2.0
+ */
+ public SWTBotArrowButton(Button button, SelfDescribing description) {
+ super(button, description);
+ Assert.isTrue(SWTUtils.hasStyle(button, SWT.ARROW), "Expecting an arrow button."); //$NON-NLS-1$
+ }
+
+ /**
+ * Click on the button.
+ */
+ public SWTBotArrowButton click() {
+ log.debug(MessageFormat.format("Clicking on {0}", SWTUtils.getText(widget))); //$NON-NLS-1$
+ waitForEnabled();
+ notify(SWT.MouseEnter);
+ notify(SWT.MouseMove);
+ notify(SWT.Activate);
+ notify(SWT.FocusIn);
+ notify(SWT.MouseDown);
+ notify(SWT.MouseUp);
+ notify(SWT.Selection);
+ notify(SWT.MouseHover);
+ notify(SWT.MouseMove);
+ notify(SWT.MouseExit);
+ notify(SWT.Deactivate);
+ notify(SWT.FocusOut);
+ log.debug(MessageFormat.format("Clicked on {0}", SWTUtils.getText(widget))); //$NON-NLS-1$
+ return this;
+ }
+
+}

0 comments on commit 7b246a8

Please sign in to comment.