| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SWTBotSpinner |
|
| 1.0;1 | ||||
| SWTBotSpinner$1 |
|
| 1.0;1 | ||||
| SWTBotSpinner$2 |
|
| 1.0;1 | ||||
| SWTBotSpinner$3 |
|
| 1.0;1 | ||||
| SWTBotSpinner$4 |
|
| 1.0;1 | ||||
| SWTBotSpinner$5 |
|
| 1.0;1 | ||||
| SWTBotSpinner$6 |
|
| 1.0;1 | ||||
| SWTBotSpinner$7 |
|
| 1.0;1 |
| 1 | 0 | /******************************************************************************* |
| 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 | * Yann N. Dauphin - initial API and implementation | |
| 10 | *******************************************************************************/ | |
| 11 | package org.eclipse.swtbot.swt.finder.widgets; | |
| 12 | ||
| 13 | import org.eclipse.swt.SWT; | |
| 14 | import org.eclipse.swt.widgets.Spinner; | |
| 15 | import org.eclipse.swtbot.swt.finder.ReferenceBy; | |
| 16 | import org.eclipse.swtbot.swt.finder.SWTBotWidget; | |
| 17 | import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; | |
| 18 | import org.eclipse.swtbot.swt.finder.results.IntResult; | |
| 19 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
| 20 | import org.eclipse.swtbot.swt.finder.utils.MessageFormat; | |
| 21 | import org.hamcrest.SelfDescribing; | |
| 22 | ||
| 23 | /** | |
| 24 | * Represents a spinner. | |
| 25 | * | |
| 26 | * @author Yann N. Dauphin | |
| 27 | * @version $Id$ | |
| 28 | */ | |
| 29 | @SWTBotWidget(clasz = Spinner.class, preferredName = "spinner", referenceBy = { ReferenceBy.LABEL, ReferenceBy.TEXT, ReferenceBy.TOOLTIP }) | |
| 30 | public class SWTBotSpinner extends AbstractSWTBot<Spinner> { | |
| 31 | ||
| 32 | /** | |
| 33 | * Constructs a new instance with the given widget. | |
| 34 | * | |
| 35 | * @param widget the spinner. | |
| 36 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
| 37 | */ | |
| 38 | public SWTBotSpinner(Spinner widget) throws WidgetNotFoundException { | |
| 39 | 0 | super(widget); |
| 40 | 0 | } |
| 41 | ||
| 42 | /** | |
| 43 | * Constructs an instance with the given widget | |
| 44 | * | |
| 45 | * @param widget the widget. | |
| 46 | * @param description the description of the widget, this will be reported by {@link #toString()} | |
| 47 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
| 48 | */ | |
| 49 | public SWTBotSpinner(Spinner widget, SelfDescribing description) | |
| 50 | throws WidgetNotFoundException { | |
| 51 | 39 | super(widget, description); |
| 52 | 39 | } |
| 53 | ||
| 54 | /** | |
| 55 | * Return the current value of the spinner. | |
| 56 | * | |
| 57 | * @return the current selection in the spinner. | |
| 58 | */ | |
| 59 | public int getSelection() { | |
| 60 | 1 | return syncExec(new IntResult() { |
| 61 | public Integer run() { | |
| 62 | 1 | return widget.getSelection(); |
| 63 | } | |
| 64 | }); | |
| 65 | } | |
| 66 | ||
| 67 | /** | |
| 68 | * Set the selection to the specified value. | |
| 69 | * | |
| 70 | * @param value the value to set into the spinner. | |
| 71 | */ | |
| 72 | public void setSelection(final int value) { | |
| 73 | 36 | log.debug(MessageFormat.format("Setting selection on {0} to {1}", this, value)); //$NON-NLS-1$ |
| 74 | 36 | waitForEnabled(); |
| 75 | 36 | asyncExec(new VoidResult() { |
| 76 | public void run() { | |
| 77 | 36 | widget.setSelection(value); |
| 78 | 36 | } |
| 79 | }); | |
| 80 | 36 | notify(SWT.Selection); |
| 81 | 36 | log.debug(MessageFormat.format("Set selection on {0} to {1}", this, value)); //$NON-NLS-1$ |
| 82 | 36 | } |
| 83 | ||
| 84 | /** | |
| 85 | * Return the maximum value the spinner will accept. | |
| 86 | * | |
| 87 | * @return the maximum of the spinner. | |
| 88 | */ | |
| 89 | public int getMaximum() { | |
| 90 | 0 | return syncExec(new IntResult() { |
| 91 | public Integer run() { | |
| 92 | 0 | return widget.getMaximum(); |
| 93 | } | |
| 94 | }); | |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Return the minimum value the spinner will accept. | |
| 99 | * | |
| 100 | * @return the minimum of the spinner. | |
| 101 | */ | |
| 102 | public int getMinimum() { | |
| 103 | 0 | return syncExec(new IntResult() { |
| 104 | public Integer run() { | |
| 105 | 0 | return widget.getMinimum(); |
| 106 | } | |
| 107 | }); | |
| 108 | } | |
| 109 | ||
| 110 | /** | |
| 111 | * Return the increment of the spinner. | |
| 112 | * | |
| 113 | * @return the increment of the spinner. | |
| 114 | */ | |
| 115 | public int getIncrement() { | |
| 116 | 0 | return syncExec(new IntResult() { |
| 117 | public Integer run() { | |
| 118 | 0 | return widget.getIncrement(); |
| 119 | } | |
| 120 | }); | |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * Return the page increment of the spinner. | |
| 125 | * | |
| 126 | * @return the increment of the spinner. | |
| 127 | */ | |
| 128 | public int getPageIncrement() { | |
| 129 | 0 | return syncExec(new IntResult() { |
| 130 | public Integer run() { | |
| 131 | 0 | return widget.getPageIncrement(); |
| 132 | } | |
| 133 | }); | |
| 134 | } | |
| 135 | ||
| 136 | /** | |
| 137 | * Return the number of decimal places of the spinner. | |
| 138 | * | |
| 139 | * @return the number of decimal places of the spinner. | |
| 140 | */ | |
| 141 | public int getDigits() { | |
| 142 | 0 | return syncExec(new IntResult() { |
| 143 | public Integer run() { | |
| 144 | 0 | return widget.getDigits(); |
| 145 | } | |
| 146 | }); | |
| 147 | } | |
| 148 | ||
| 149 | } |