Coverage Report - org.eclipse.swtbot.swt.finder.widgets.SWTBotSlider
 
Classes in this File Line Coverage Branch Coverage Complexity
SWTBotSlider
56%
9/16
N/A
1
SWTBotSlider$1
100%
3/3
N/A
1
SWTBotSlider$2
100%
4/4
N/A
1
SWTBotSlider$3
0%
0/3
N/A
1
SWTBotSlider$4
0%
0/3
N/A
1
SWTBotSlider$5
0%
0/3
N/A
1
SWTBotSlider$6
0%
0/3
N/A
1
SWTBotSlider$7
0%
0/3
N/A
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.Slider;
 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 slider.
 25  
  *
 26  
  * @author Yann N. Dauphin
 27  
  * @version $Id$
 28  
  */
 29  
 @SWTBotWidget(clasz = Slider.class, preferredName = "slider", referenceBy = { ReferenceBy.LABEL, ReferenceBy.TEXT, ReferenceBy.TOOLTIP })
 30  
 public class SWTBotSlider extends AbstractSWTBot<Slider> {
 31  
 
 32  
         /**
 33  
          * Constructs a new instance with the given widget.
 34  
          *
 35  
          * @param widget the widget.
 36  
          * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 37  
          */
 38  
         public SWTBotSlider(Slider 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 SWTBotSlider(Slider widget, SelfDescribing description) throws WidgetNotFoundException {
 50  4
                 super(widget, description);
 51  4
         }
 52  
 
 53  
         /**
 54  
          * Return the current value of the slider.
 55  
          *
 56  
          * @return the current selection in the slider.
 57  
          */
 58  
         public int getSelection() {
 59  1
                 return syncExec(new IntResult() {
 60  
                         public Integer run() {
 61  1
                                 return widget.getSelection();
 62  
                         }
 63  
                 });
 64  
         }
 65  
 
 66  
         /**
 67  
          * Set the selection to the specified value.
 68  
          *
 69  
          * @param value the value to set into the slider.
 70  
          */
 71  
         public void setSelection(final int value) {
 72  1
                 log.debug(MessageFormat.format("Setting selection on {0} to {1}", this, value)); //$NON-NLS-1$
 73  1
                 waitForEnabled();
 74  1
                 asyncExec(new VoidResult() {
 75  
                         public void run() {
 76  1
                                 widget.setSelection(value);
 77  1
                         }
 78  
                 });
 79  1
                 notify(SWT.Selection);
 80  1
                 log.debug(MessageFormat.format("Set selection on {0} to {1}", this, value)); //$NON-NLS-1$
 81  1
         }
 82  
 
 83  
         /**
 84  
          * Return the maximum value the slider will accept.
 85  
          *
 86  
          * @return the maximum of the slider.
 87  
          */
 88  
         public int getMaximum() {
 89  0
                 return syncExec(new IntResult() {
 90  
                         public Integer run() {
 91  0
                                 return widget.getMaximum();
 92  
                         }
 93  
                 });
 94  
         }
 95  
 
 96  
         /**
 97  
          * Return the minimum value the slider will accept.
 98  
          *
 99  
          * @return the minimum of the slider.
 100  
          */
 101  
         public int getMinimum() {
 102  0
                 return syncExec(new IntResult() {
 103  
                         public Integer run() {
 104  0
                                 return widget.getMinimum();
 105  
                         }
 106  
                 });
 107  
         }
 108  
 
 109  
         /**
 110  
          * Return the increment of the slider.
 111  
          *
 112  
          * @return the increment of the slider.
 113  
          */
 114  
         public int getIncrement() {
 115  0
                 return syncExec(new IntResult() {
 116  
                         public Integer run() {
 117  0
                                 return widget.getIncrement();
 118  
                         }
 119  
                 });
 120  
         }
 121  
 
 122  
         /**
 123  
          * Return the page increment of the slider.
 124  
          *
 125  
          * @return the increment of the slider.
 126  
          */
 127  
         public int getPageIncrement() {
 128  0
                 return syncExec(new IntResult() {
 129  
                         public Integer run() {
 130  0
                                 return widget.getPageIncrement();
 131  
                         }
 132  
                 });
 133  
         }
 134  
 
 135  
         /**
 136  
          * Return the size of the thumb of the slider.
 137  
          *
 138  
          * @return the size of the thumb of the slider.
 139  
          */
 140  
         public int getThumb() {
 141  0
                 return syncExec(new IntResult() {
 142  
                         public Integer run() {
 143  0
                                 return widget.getThumb();
 144  
                         }
 145  
                 });
 146  
         }
 147  
 
 148  
 }