Coverage Report - org.eclipse.swtbot.swt.finder.widgets.SWTBotButton
 
Classes in this File Line Coverage Branch Coverage Complexity
SWTBotButton
86%
19/22
N/A
1
 
 1  0
 /*******************************************************************************
 2  
  * Copyright (c) 2008 Ketan Padegaonkar 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  
  *     Ketan Padegaonkar - 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.Button;
 15  
 import org.eclipse.swtbot.swt.finder.ReferenceBy;
 16  
 import org.eclipse.swtbot.swt.finder.SWTBotWidget;
 17  
 import org.eclipse.swtbot.swt.finder.Style;
 18  
 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
 19  
 import org.eclipse.swtbot.swt.finder.utils.MessageFormat;
 20  
 import org.eclipse.swtbot.swt.finder.utils.SWTUtils;
 21  
 import org.eclipse.swtbot.swt.finder.utils.internal.Assert;
 22  
 import org.hamcrest.SelfDescribing;
 23  
 
 24  
 /**
 25  
  * This represents a {@link Button} widget of type {@link SWT#PUSH}.
 26  
  *
 27  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 28  
  * @version $Id$
 29  
  * @see SWTBotCheckBox
 30  
  * @see SWTBotRadio
 31  
  * @see SWTBotToggleButton
 32  
  */
 33  
 @SWTBotWidget(clasz = Button.class, style = @Style(name = "SWT.PUSH", value = SWT.PUSH), preferredName = "button", referenceBy = { ReferenceBy.LABEL, ReferenceBy.MNEMONIC, ReferenceBy.TOOLTIP })  //$NON-NLS-1$
 34  
 public class SWTBotButton extends AbstractSWTBotControl<Button> {
 35  
 
 36  
         /**
 37  
          * Constructs an instance of this object with the given button
 38  
          *
 39  
          * @param button the widget.
 40  
          * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 41  
          * @since 2.0
 42  
          */
 43  
         public SWTBotButton(Button button) {
 44  0
                 this(button, null);
 45  0
         }
 46  
 
 47  
         /**
 48  
          * Constructs an instance of this object with the given button
 49  
          *
 50  
          * @param button the widget.
 51  
          * @param description the description of the widget, this will be reported by {@link #toString()}
 52  
          * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed.
 53  
          * @since 2.0
 54  
          */
 55  
         public SWTBotButton(Button button, SelfDescribing description) {
 56  161
                 super(button, description);
 57  161
                 Assert.isTrue(SWTUtils.hasStyle(button, SWT.PUSH), "Expecting a push button."); //$NON-NLS-1$
 58  161
         }
 59  
 
 60  
         /**
 61  
          * Click on the button.
 62  
          */
 63  
         public SWTBotButton click() {
 64  140
                 log.debug(MessageFormat.format("Clicking on {0}", SWTUtils.getText(widget))); //$NON-NLS-1$
 65  140
                 waitForEnabled();
 66  140
                 notify(SWT.MouseEnter);
 67  140
                 notify(SWT.MouseMove);
 68  140
                 notify(SWT.Activate);
 69  140
                 notify(SWT.FocusIn);
 70  140
                 notify(SWT.MouseDown);
 71  140
                 notify(SWT.MouseUp);
 72  140
                 notify(SWT.Selection);
 73  140
                 notify(SWT.MouseHover);
 74  140
                 notify(SWT.MouseMove);
 75  140
                 notify(SWT.MouseExit);
 76  140
                 notify(SWT.Deactivate);
 77  140
                 notify(SWT.FocusOut);
 78  140
                 log.debug(MessageFormat.format("Clicked on {0}", SWTUtils.getText(widget))); //$NON-NLS-1$
 79  140
                 return this;
 80  
         }
 81  
 
 82  
 }