summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorJohn Cortell2011-01-28 21:59:34 (EST)
committer Ketan Padegaonkar2011-01-28 21:59:34 (EST)
commit3146430cb2cdd38e9577e6bee1afd81b72248018 (patch)
treeee2f448bc99daee82ecedaa55393ee3e2c5be37e
parent3ee6280f716a2a59f1d56e4cb42ec0908ce6a0dc (diff)
downloadorg.eclipse.swtbot-3146430cb2cdd38e9577e6bee1afd81b72248018.zip
org.eclipse.swtbot-3146430cb2cdd38e9577e6bee1afd81b72248018.tar.gz
org.eclipse.swtbot-3146430cb2cdd38e9577e6bee1afd81b72248018.tar.bz2
RESOLVED - 332992: Missing support for Scale widget
https://bugs.eclipse.org/bugs/show_bug.cgi?id=332992
-rw-r--r--org.eclipse.swtbot.generator/widgets.xml1
-rw-r--r--org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScaleTest.java72
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/SWTBot.java218
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScale.java133
4 files changed, 424 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.generator/widgets.xml b/org.eclipse.swtbot.generator/widgets.xml
index dba0506..cac0276 100644
--- a/org.eclipse.swtbot.generator/widgets.xml
+++ b/org.eclipse.swtbot.generator/widgets.xml
@@ -24,6 +24,7 @@
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotSpinner" />
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotSlider" />
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotBrowser" />
+ <widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotScale" />
<!--
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotExpandBar" />
<widget class="org.eclipse.swtbot.swt.finder.widgets.SWTBotShell" />
diff --git a/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScaleTest.java b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScaleTest.java
new file mode 100644
index 0000000..56d8669
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder.test/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScaleTest.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SWTBot Committers 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:
+ * John Cortell - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.eclipse.swtbot.swt.finder.finders.AbstractSWTTestCase;
+import org.junit.Test;
+
+public class SWTBotScaleTest extends AbstractSWTTestCase {
+
+ @Test
+ public void findsScale() throws Exception {
+ assertNotNull(bot.scale().widget);
+ }
+
+ @Test
+ public void findsScaleInGroup() throws Exception {
+ assertNotNull(bot.scaleInGroup("Scale").widget);
+ }
+
+ @Test
+ public void shouldGetValue() throws Exception {
+ bot.spinnerInGroup("Selection").setSelection(42);
+ assertEquals(42, bot.scaleInGroup("Scale").getValue());
+ }
+
+ @Test
+ public void shouldSetValue() throws Exception {
+ bot.scaleInGroup("Scale").setValue(24);
+ assertEquals(24, bot.scaleInGroup("Scale").getValue());
+ }
+
+ @Test
+ public void shouldGetMinimumAndMaximum() throws Exception {
+ bot.spinnerInGroup("Minimum").setSelection(5);
+ bot.spinnerInGroup("Maximum").setSelection(45);
+
+ assertEquals(5, bot.scaleInGroup("Scale").getMinimum());
+ assertEquals(45, bot.scaleInGroup("Scale").getMaximum());
+ }
+
+ @Test
+ public void shouldGetIncrementAndPageIncrement() throws Exception {
+ bot.spinnerInGroup("Increment").setSelection(7);
+ bot.spinnerInGroup("Page Increment").setSelection(15);
+
+ assertEquals(7, bot.scaleInGroup("Scale").getIncrement());
+ assertEquals(15, bot.scaleInGroup("Scale").getPageIncrement());
+ }
+
+ public void setUp() throws Exception {
+ super.setUp();
+ bot.tabItem("Scale").activate();
+ bot.spinnerInGroup("Selection").setSelection(0);
+ bot.spinnerInGroup("Minimum").setSelection(0);
+ bot.spinnerInGroup("Maximum").setSelection(100);
+
+ bot.spinnerInGroup("Increment").setSelection(1);
+ bot.spinnerInGroup("Page Increment").setSelection(10);
+ }
+
+}
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/SWTBot.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/SWTBot.java
index 963187c..37af160 100644
--- a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/SWTBot.java
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/SWTBot.java
@@ -15,6 +15,7 @@ import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Scale;
import org.eclipse.swt.widgets.Slider;
import org.eclipse.swt.widgets.Spinner;
import org.eclipse.swt.widgets.TabItem;
@@ -41,6 +42,7 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLink;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotList;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotScale;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotSlider;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotSpinner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotStyledText;
@@ -4154,6 +4156,222 @@ public class SWTBot extends SWTBotFactory {
return new SWTBotBrowser((Browser) widget(matcher, index), matcher);
}
+ /**
+ * @param label the label on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>label</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleWithLabel(String label) {
+ return scaleWithLabel(label, 0);
+ }
+
+ /**
+ * @param label the label on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotScale} with the specified <code>label</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scaleWithLabel(String label, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withLabel(label));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param text the text on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>text</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scale(String text) {
+ return scale(text, 0);
+ }
+
+ /**
+ * @param text the text on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotScale} with the specified <code>text</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scale(String text, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withText(text));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>tooltip</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleWithTooltip(String tooltip) {
+ return scaleWithTooltip(tooltip, 0);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotScale} with the specified <code>tooltip</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scaleWithTooltip(String tooltip, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withTooltip(tooltip));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param key the key set on the widget.
+ * @param value the value for the key.
+ * @return a {@link SWTBotScale} with the specified <code>key/value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleWithId(String key, String value) {
+ return scaleWithId(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 SWTBotScale} with the specified <code>key/value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scaleWithId(String key, String value, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withId(key, value));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param value the value for the key {@link org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences#DEFAULT_KEY}.
+ * @return a {@link SWTBotScale} with the specified <code>value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleWithId(String value) {
+ return scaleWithId(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 SWTBotScale} with the specified <code>value</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scaleWithId(String value, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withId(value));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleInGroup(String inGroup) {
+ return scaleInGroup(inGroup, 0);
+ }
+
+ /**
+ * @param inGroup the inGroup on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotScale} with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scaleInGroup(String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), inGroup(inGroup));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @return a {@link SWTBotScale} with the specified <code>none</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scale() {
+ return scale(0);
+ }
+
+ /**
+ * @param index the index of the widget.
+ * @return a {@link SWTBotScale} with the specified <code>none</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scale(int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param label the label on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>label</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleWithLabelInGroup(String label, String inGroup) {
+ return scaleWithLabelInGroup(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 SWTBotScale} 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 SWTBotScale scaleWithLabelInGroup(String label, String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withLabel(label), inGroup(inGroup));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param text the text on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>text</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleInGroup(String text, String inGroup) {
+ return scaleInGroup(text, inGroup, 0);
+ }
+
+ /**
+ * @param text the text on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @param index the index of the widget.
+ * @return a {@link SWTBotScale} with the specified <code>text</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public SWTBotScale scaleInGroup(String text, String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withText(text), inGroup(inGroup));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
+ /**
+ * @param tooltip the tooltip on the widget.
+ * @param inGroup the inGroup on the widget.
+ * @return a {@link SWTBotScale} with the specified <code>tooltip</code> with the specified <code>inGroup</code>.
+ * @throws WidgetNotFoundException if the widget is not found or is disposed.
+ */
+ public SWTBotScale scaleWithTooltipInGroup(String tooltip, String inGroup) {
+ return scaleWithTooltipInGroup(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 SWTBotScale} 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 SWTBotScale scaleWithTooltipInGroup(String tooltip, String inGroup, int index) {
+ Matcher matcher = allOf(widgetOfType(Scale.class), withTooltip(tooltip), inGroup(inGroup));
+ return new SWTBotScale((Scale) widget(matcher, index), matcher);
+ }
+
private Matcher<? extends List> withLabel(String label) {
return WidgetMatcherFactory.withLabel(label, finder);
}
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScale.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScale.java
new file mode 100644
index 0000000..b6f3a27
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/widgets/SWTBotScale.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2011 SWTBot Committers 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:
+ * John Cortell - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.widgets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Scale;
+import org.eclipse.swtbot.swt.finder.ReferenceBy;
+import org.eclipse.swtbot.swt.finder.SWTBotWidget;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.results.IntResult;
+import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.utils.MessageFormat;
+import org.hamcrest.SelfDescribing;
+
+/**
+ * Represents a scale
+ *
+ * @author John Cortell
+ */
+@SWTBotWidget(clasz = Scale.class, preferredName = "scale", referenceBy = { ReferenceBy.LABEL, ReferenceBy.TEXT, ReferenceBy.TOOLTIP })
+public class SWTBotScale extends AbstractSWTBot<Scale> {
+
+ /**
+ * Constructs a new instance with the given widget.
+ *
+ * @param widget the widget.
+ * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
+ */
+ public SWTBotScale(Scale widget) throws WidgetNotFoundException {
+ super(widget);
+ }
+
+ /**
+ * Constructs an instance with the given widget
+ *
+ * @param widget 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.
+ */
+ public SWTBotScale(Scale widget, SelfDescribing description) throws WidgetNotFoundException {
+ super(widget, description);
+ }
+
+ /**
+ * Return the current value of the scale.
+ *
+ * @return the current selection in the scale.
+ */
+ public int getValue() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getSelection();
+ }
+ });
+ }
+
+ /**
+ * Set the selection to the specified value.
+ *
+ * @param value the value to set into the scale.
+ */
+ public void setValue(final int value) {
+ log.debug(MessageFormat.format("Setting selection on {0} to {1}", this, value)); //$NON-NLS-1$
+ waitForEnabled();
+ asyncExec(new VoidResult() {
+ public void run() {
+ widget.setSelection(value);
+ }
+ });
+ notify(SWT.Selection);
+ log.debug(MessageFormat.format("Set selection on {0} to {1}", this, value)); //$NON-NLS-1$
+ }
+
+ /**
+ * Return the maximum value the scale will accept.
+ *
+ * @return the maximum of the scale.
+ */
+ public int getMaximum() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getMaximum();
+ }
+ });
+ }
+
+ /**
+ * Return the minimum value the scale will accept.
+ *
+ * @return the minimum of the scale.
+ */
+ public int getMinimum() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getMinimum();
+ }
+ });
+ }
+
+ /**
+ * Return the increment of the scale.
+ *
+ * @return the increment of the scale.
+ */
+ public int getIncrement() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getIncrement();
+ }
+ });
+ }
+
+ /**
+ * Return the page increment of the scale.
+ *
+ * @return the increment of the scale.
+ */
+ public int getPageIncrement() {
+ return syncExec(new IntResult() {
+ public Integer run() {
+ return widget.getPageIncrement();
+ }
+ });
+ }
+}