< 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
*** 34,43 ****
--- 34,44 ----
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
+ import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jemmy.Point;
import org.jemmy.control.Wrap;
*** 59,68 ****
--- 60,108 ----
private MCButton(Wrap<? extends Button> button) {
this.control = button;
}
/**
+ * Finds a button in the supplied shell by image and returns it.
+ *
+ * @param shell
+ * the shell where to search for the button
+ * @param image
+ * the image to look up the button with
+ * @return a {@link MCButton} (possibly null)
+ */
+ @SuppressWarnings("unchecked")
+ public static MCButton getByImage(Wrap<? extends Shell> shell, Image image) {
+ List<Wrap<? extends Button>> allVisibleButtonWraps = getVisible(
+ shell.as(Parent.class, Button.class).lookup(Button.class));
+ for (final Wrap<? extends Button> buttonWrap : allVisibleButtonWraps) {
+ Fetcher<Image> fetcher = new Fetcher<Image>() {
+ @Override
+ public void run() {
+ setOutput(buttonWrap.getControl().getImage());
+ }
+ };
+ Display.getDefault().syncExec(fetcher);
+ if (image.equals(fetcher.getOutput())) {
+ return new MCButton(buttonWrap);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds a button in the default Mission Control shell and returns it.
+ *
+ * @param image
+ * the image of the button
+ * @return a {@link MCButton} in the default shell matching the image.
+ */
+ public static MCButton getByImage(Image image) {
+ return getByImage(getShell(), image);
+ }
+
+ /**
* Finds a button in the default Mission Control shell and returns it.
*
* @param label
* the {@link MCButton} Label of the button
* @return a {@link MCButton} in the default shell matching the label
*** 94,103 ****
--- 134,156 ----
public static MCButton getByLabel(String label) {
return getByLabel(getShell(), label);
}
/**
+ * Finds a button in a shell with the given text and returns it.
+ *
+ * @param label
+ * the label string of the button
+ * @param shellText
+ * the text to look up the shell that the button is contained in
+ * @return a {@link MCButton} in the shell matching the label
+ */
+ public static MCButton getByLabel(String shellText, String label) {
+ return getByLabel(getShellByText(shellText), label);
+ }
+
+ /**
* Finds a button by button label and returns it
*
* @param shell
* the shell where to find the button
* @param label
< prev index next >