| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SWTBotShell |
|
| 1.1333333333333333;1.133 | ||||
| SWTBotShell$1 |
|
| 1.1333333333333333;1.133 | ||||
| SWTBotShell$1$1 |
|
| 1.1333333333333333;1.133 | ||||
| SWTBotShell$2 |
|
| 1.1333333333333333;1.133 | ||||
| SWTBotShell$3 |
|
| 1.1333333333333333;1.133 | ||||
| SWTBotShell$4 |
|
| 1.1333333333333333;1.133 | ||||
| SWTBotShell$5 |
|
| 1.1333333333333333;1.133 |
| 1 | 26 | /******************************************************************************* |
| 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.Shell; | |
| 15 | import org.eclipse.swtbot.swt.finder.SWTBot; | |
| 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.BoolResult; | |
| 19 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
| 20 | import org.eclipse.swtbot.swt.finder.utils.SWTUtils; | |
| 21 | import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; | |
| 22 | import org.hamcrest.SelfDescribing; | |
| 23 | ||
| 24 | /** | |
| 25 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
| 26 | * @version $Id$ | |
| 27 | */ | |
| 28 | @SWTBotWidget(clasz = Shell.class, preferredName = "shell") | |
| 29 | public class SWTBotShell extends AbstractSWTBotControl<Shell> { | |
| 30 | ||
| 31 | /** | |
| 32 | * Constructs an instance of this with the given shell. | |
| 33 | * | |
| 34 | * @param shell the widget. | |
| 35 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
| 36 | */ | |
| 37 | public SWTBotShell(Shell shell) throws WidgetNotFoundException { | |
| 38 | 424 | this(shell, null); |
| 39 | 424 | } |
| 40 | ||
| 41 | /** | |
| 42 | * Constructs an instance of this with the given shell. | |
| 43 | * | |
| 44 | * @param shell the widget. | |
| 45 | * @param description the description of the widget, this will be reported by {@link #toString()} | |
| 46 | * @throws WidgetNotFoundException if the widget is <code>null</code> or widget has been disposed. | |
| 47 | */ | |
| 48 | public SWTBotShell(Shell shell, SelfDescribing description) throws WidgetNotFoundException { | |
| 49 | 424 | super(shell, description); |
| 50 | 424 | } |
| 51 | ||
| 52 | // @Override | |
| 53 | // protected Widget findWidget(int index) throws WidgetNotFoundException { | |
| 54 | // // could have used a matcher, but that would just slow down things | |
| 55 | // Shell[] shells = finder.getShells(); | |
| 56 | // for (int i = 0; i < shells.length; i++) { | |
| 57 | // Shell shell = shells[i]; | |
| 58 | // if (new SWTBotShell(shell).getText().equals(text)) | |
| 59 | // return shell; | |
| 60 | // } | |
| 61 | // throw new WidgetNotFoundException("Cound not find shell matching text:" + text); | |
| 62 | // } | |
| 63 | ||
| 64 | /** | |
| 65 | * Activates the shell. | |
| 66 | * @return itself. | |
| 67 | * | |
| 68 | * @throws TimeoutException if the shell could not be activated | |
| 69 | */ | |
| 70 | public SWTBotShell activate() throws TimeoutException { | |
| 71 | 1131 | new SWTBot().waitUntil(new DefaultCondition() { |
| 72 | public String getFailureMessage() { | |
| 73 | 0 | return "Timed out waiting for " + SWTUtils.toString(widget) + " to get activated"; //$NON-NLS-1$ //$NON-NLS-2$ |
| 74 | } | |
| 75 | ||
| 76 | public boolean test() throws Exception { | |
| 77 | 377 | syncExec(new VoidResult() { |
| 78 | public void run() { | |
| 79 | 377 | widget.forceActive(); |
| 80 | 377 | widget.forceFocus(); |
| 81 | 377 | } |
| 82 | }); | |
| 83 | 377 | return isActive(); |
| 84 | } | |
| 85 | }); | |
| 86 | 377 | notify(SWT.Activate); |
| 87 | 377 | return this; |
| 88 | } | |
| 89 | ||
| 90 | /** | |
| 91 | * Closes the shell | |
| 92 | * | |
| 93 | * @throws TimeoutException if the shell does not close. | |
| 94 | */ | |
| 95 | public void close() throws TimeoutException { | |
| 96 | 26 | notify(SWT.Close); |
| 97 | 26 | asyncExec(new VoidResult() { |
| 98 | public void run() { | |
| 99 | // TODO investigate bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=259895 | |
| 100 | 26 | if (!widget.isDisposed()) |
| 101 | 26 | widget.close(); |
| 102 | 26 | } |
| 103 | }); | |
| 104 | 26 | new SWTBot().waitUntil(new DefaultCondition() { |
| 105 | public boolean test() throws Exception { | |
| 106 | 26 | return !isOpen(); |
| 107 | } | |
| 108 | ||
| 109 | public String getFailureMessage() { | |
| 110 | 0 | return "Timed out waiting for " + SWTUtils.toString(widget) + " to close."; //$NON-NLS-1$ //$NON-NLS-2$ |
| 111 | } | |
| 112 | }); | |
| 113 | 26 | } |
| 114 | ||
| 115 | /** | |
| 116 | * Checks if the shell is open. | |
| 117 | * | |
| 118 | * @return <code>true</code> if the shell is visible, <code>false</code> otherwise. | |
| 119 | */ | |
| 120 | public boolean isOpen() { | |
| 121 | 26 | return syncExec(new BoolResult() { |
| 122 | public Boolean run() { | |
| 123 | 26 | return !widget.isDisposed() && widget.isVisible(); |
| 124 | } | |
| 125 | }); | |
| 126 | } | |
| 127 | ||
| 128 | /** | |
| 129 | * Checks if the shell is active. | |
| 130 | * | |
| 131 | * @return <code>true</code> if the shell is active, <code>false</code> otherwise. | |
| 132 | */ | |
| 133 | public boolean isActive() { | |
| 134 | 377 | return syncExec(new BoolResult() { |
| 135 | public Boolean run() { | |
| 136 | 377 | return display.getActiveShell() == widget; |
| 137 | } | |
| 138 | }); | |
| 139 | } | |
| 140 | ||
| 141 | /** | |
| 142 | * Returns a SWTBot instance that matches the contents of this shell. | |
| 143 | * | |
| 144 | * @return SWTBot | |
| 145 | */ | |
| 146 | public SWTBot bot() { | |
| 147 | return new SWTBot(widget); | |
| 148 | } | |
| 149 | ||
| 150 | } |