< prev index next >

application/uitests/org.openjdk.jmc.test.jemmy/src/test/java/org/openjdk/jmc/test/jemmy/misc/wrappers/MCButton.java

Print this page




  19  * the distribution.
  20  * 
  21  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
  22  * endorse or promote products derived from this software without specific prior written permission.
  23  * 
  24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  26  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  31  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 package org.openjdk.jmc.test.jemmy.misc.wrappers;
  34 
  35 import java.util.ArrayList;
  36 import java.util.List;
  37 
  38 import org.eclipse.jface.dialogs.IDialogConstants;

  39 import org.eclipse.swt.widgets.Button;
  40 import org.eclipse.swt.widgets.Display;
  41 import org.eclipse.swt.widgets.Shell;
  42 import org.jemmy.Point;
  43 import org.jemmy.control.Wrap;
  44 import org.jemmy.interfaces.Parent;
  45 import org.jemmy.lookup.Lookup;
  46 import org.jemmy.swt.ControlWrap;
  47 import org.jemmy.swt.lookup.ByName;
  48 import org.jemmy.swt.lookup.ByTextControlLookup;
  49 import org.junit.Assert;
  50 
  51 import org.openjdk.jmc.test.jemmy.misc.base.wrappers.MCJemmyBase;
  52 import org.openjdk.jmc.test.jemmy.misc.fetchers.Fetcher;
  53 
  54 /**
  55  * The Jemmy wrapper for Buttons
  56  */
  57 public class MCButton extends MCJemmyBase {
  58 
  59         private MCButton(Wrap<? extends Button> button) {
  60                 this.control = button;
  61         }
  62 
  63         /**







































  64          * Finds a button in the default Mission Control shell and returns it.
  65          *
  66          * @param label
  67          *            the {@link MCButton} Label of the button
  68          * @return a {@link MCButton} in the default shell matching the label
  69          */
  70         public static MCButton getByLabel(Labels label) {
  71                 return getByLabel(getShell(), label);
  72         }
  73 
  74         /**
  75          * Finds a button in the default Mission Control shell and returns it.
  76          *
  77          * @param label
  78          *            the {@link MCButton} Label of the button
  79          * @param waitForIdle
  80          *            {@code true} if supposed to wait for an idle UI before trying to find the Button
  81          * @return a {@link MCButton} in the default shell matching the label
  82          */
  83         public static MCButton getByLabel(Labels label, boolean waitForIdle) {
  84                 return getByLabel(getShell(), label, waitForIdle);
  85         }
  86 
  87         /**
  88          * Finds a button in the default Mission Control shell and returns it.
  89          *
  90          * @param label
  91          *            the label string of the button
  92          * @return a {@link MCButton} in the default shell matching the label
  93          */
  94         public static MCButton getByLabel(String label) {
  95                 return getByLabel(getShell(), label);













  96         }
  97 
  98         /**
  99          * Finds a button by button label and returns it
 100          *
 101          * @param shell
 102          *            the shell where to find the button
 103          * @param label
 104          *            the {@link MCButton} Label of the button
 105          * @param waitForIdle
 106          *            {@code true} if supposed to wait for an idle UI before trying to find the Button
 107          * @return a {@link MCButton} in the correct shell matching the label
 108          */
 109         public static MCButton getByLabel(Wrap<? extends Shell> shell, Labels label, boolean waitForIdle) {
 110                 return getByLabel(shell, Labels.getButtonLabel(label), waitForIdle);
 111         }
 112 
 113         /**
 114          * Finds a button by button label and returns it
 115          *




  19  * the distribution.
  20  * 
  21  * 3. Neither the name of the copyright holder nor the names of its contributors may be used to
  22  * endorse or promote products derived from this software without specific prior written permission.
  23  * 
  24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  26  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
  31  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  */
  33 package org.openjdk.jmc.test.jemmy.misc.wrappers;
  34 
  35 import java.util.ArrayList;
  36 import java.util.List;
  37 
  38 import org.eclipse.jface.dialogs.IDialogConstants;
  39 import org.eclipse.swt.graphics.Image;
  40 import org.eclipse.swt.widgets.Button;
  41 import org.eclipse.swt.widgets.Display;
  42 import org.eclipse.swt.widgets.Shell;
  43 import org.jemmy.Point;
  44 import org.jemmy.control.Wrap;
  45 import org.jemmy.interfaces.Parent;
  46 import org.jemmy.lookup.Lookup;
  47 import org.jemmy.swt.ControlWrap;
  48 import org.jemmy.swt.lookup.ByName;
  49 import org.jemmy.swt.lookup.ByTextControlLookup;
  50 import org.junit.Assert;
  51 
  52 import org.openjdk.jmc.test.jemmy.misc.base.wrappers.MCJemmyBase;
  53 import org.openjdk.jmc.test.jemmy.misc.fetchers.Fetcher;
  54 
  55 /**
  56  * The Jemmy wrapper for Buttons
  57  */
  58 public class MCButton extends MCJemmyBase {
  59 
  60         private MCButton(Wrap<? extends Button> button) {
  61                 this.control = button;
  62         }
  63 
  64         /**
  65          * Finds a button in the supplied shell by image and returns it.
  66          *
  67          * @param shell
  68          *            the shell where to search for the button
  69          * @param image
  70          *            the image to look up the button with
  71          * @return a {@link MCButton} (possibly null)
  72          */
  73         @SuppressWarnings("unchecked")
  74         public static MCButton getByImage(Wrap<? extends Shell> shell, Image image) {
  75                 List<Wrap<? extends Button>> allVisibleButtonWraps = getVisible(
  76                                 shell.as(Parent.class, Button.class).lookup(Button.class));
  77                 for (final Wrap<? extends Button> buttonWrap : allVisibleButtonWraps) {
  78                         Fetcher<Image> fetcher = new Fetcher<Image>() {
  79                                 @Override
  80                                 public void run() {
  81                                         setOutput(buttonWrap.getControl().getImage());
  82                                 }
  83                         };
  84                         Display.getDefault().syncExec(fetcher);
  85                         if (image.equals(fetcher.getOutput())) {
  86                                 return new MCButton(buttonWrap);
  87                         }
  88                 }
  89                 return null;
  90         }
  91 
  92         /**
  93          * Finds a button in the default Mission Control shell and returns it.
  94          *
  95          * @param image
  96          *            the image of the button
  97          * @return a {@link MCButton} in the default shell matching the image.
  98          */
  99         public static MCButton getByImage(Image image) {
 100                 return getByImage(getShell(), image);
 101         }
 102 
 103         /**
 104          * Finds a button in the default Mission Control shell and returns it.
 105          *
 106          * @param label
 107          *            the {@link MCButton} Label of the button
 108          * @return a {@link MCButton} in the default shell matching the label
 109          */
 110         public static MCButton getByLabel(Labels label) {
 111                 return getByLabel(getShell(), label);
 112         }
 113 
 114         /**
 115          * Finds a button in the default Mission Control shell and returns it.
 116          *
 117          * @param label
 118          *            the {@link MCButton} Label of the button
 119          * @param waitForIdle
 120          *            {@code true} if supposed to wait for an idle UI before trying to find the Button
 121          * @return a {@link MCButton} in the default shell matching the label
 122          */
 123         public static MCButton getByLabel(Labels label, boolean waitForIdle) {
 124                 return getByLabel(getShell(), label, waitForIdle);
 125         }
 126 
 127         /**
 128          * Finds a button in the default Mission Control shell and returns it.
 129          *
 130          * @param label
 131          *            the label string of the button
 132          * @return a {@link MCButton} in the default shell matching the label
 133          */
 134         public static MCButton getByLabel(String label) {
 135                 return getByLabel(getShell(), label);
 136         }
 137 
 138         /**
 139          * Finds a button in a shell with the given text and returns it.
 140          *
 141          * @param label
 142          *            the label string of the button
 143          * @param shellText
 144          *            the text to look up the shell that the button is contained in
 145          * @return a {@link MCButton} in the shell matching the label
 146          */
 147         public static MCButton getByLabel(String  shellText, String label) {
 148                 return getByLabel(getShellByText(shellText), label);
 149         }
 150 
 151         /**
 152          * Finds a button by button label and returns it
 153          *
 154          * @param shell
 155          *            the shell where to find the button
 156          * @param label
 157          *            the {@link MCButton} Label of the button
 158          * @param waitForIdle
 159          *            {@code true} if supposed to wait for an idle UI before trying to find the Button
 160          * @return a {@link MCButton} in the correct shell matching the label
 161          */
 162         public static MCButton getByLabel(Wrap<? extends Shell> shell, Labels label, boolean waitForIdle) {
 163                 return getByLabel(shell, Labels.getButtonLabel(label), waitForIdle);
 164         }
 165 
 166         /**
 167          * Finds a button by button label and returns it
 168          *


< prev index next >