import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
}
}
+ /**
+ * Close a view with an id
+ *
+ * @param viewId
+ * the view id, like "org.eclipse.linuxtools.tmf.ui.views.histogram"
+ * @param bot
+ * the workbench bot
+ */
+ public static void closeViewById(String viewId, SWTWorkbenchBot bot) {
+ final SWTBotView view = bot.viewById(viewId);
+ view.close();
+ bot.waitUntil(ConditionHelpers.ViewIsClosed(view));
+ }
+
/**
* Switch to the tracing perspective
*/
});
}
+ /**
+ * Initialize the environment for SWTBot
+ */
+ public static void initialize() {
+ failIfUIThread();
+
+ SWTWorkbenchBot bot = new SWTWorkbenchBot();
+ UIThreadRunnable.syncExec(() -> {
+ Shell shell = bot.activeShell().widget;
+
+ // Only adjust shell if it appears to be the top-most
+ if (shell.getParent() == null) {
+ makeShellFullyVisible(shell);
+ }
+ });
+ }
+
/**
* If the test is running in the UI thread then fail
*/
- public static void failIfUIThread() {
+ private static void failIfUIThread() {
if (Display.getCurrent() != null && Display.getCurrent().getThread() == Thread.currentThread()) {
fail("SWTBot test needs to run in a non-UI thread. Make sure that \"Run in UI thread\" is unchecked in your launch configuration or"
+ " that useUIThread is set to false in the pom.xml");
}
+ }
+ /**
+ * Try to make the shell fully visible in the display. If the shell cannot
+ * fit the display, it will be positioned so that top-left corner is at
+ * <code>(0, 0)</code> in display-relative coordinates.
+ *
+ * @param shell
+ * the shell to make fully visible
+ */
+ private static void makeShellFullyVisible(Shell shell) {
+ Rectangle displayBounds = shell.getDisplay().getBounds();
+ Point absCoord = shell.toDisplay(0, 0);
+ Point shellSize = shell.getSize();
+
+ Point newLocation = new Point(absCoord.x, absCoord.y);
+ newLocation.x = Math.max(0, Math.min(absCoord.x, displayBounds.width - shellSize.x));
+ newLocation.y = Math.max(0, Math.min(absCoord.y, displayBounds.height - shellSize.y));
+ if (!newLocation.equals(absCoord)) {
+ shell.setLocation(newLocation);
+ }
}
/**
return currentNode;
}
+
+ /**
+ * Get the active events editor. Note that this will wait until such editor
+ * is available.
+ *
+ * @param workbenchBot
+ * a given workbench bot
+ * @return the active events editor
+ */
+ public static SWTBotEditor activeEventsEditor(final SWTWorkbenchBot workbenchBot) {
+ final SWTBotEditor editor[] = new SWTBotEditor[1];
+ workbenchBot.waitUntil(new DefaultCondition() {
+ @Override
+ public boolean test() throws Exception {
+ List<SWTBotEditor> editors = workbenchBot.editors(WidgetMatcherFactory.withPartId(TmfEventsEditor.ID));
+ for (SWTBotEditor e : editors) {
+ if (e.isActive() && !e.getWidget().isDisposed()) {
+ editor[0] = e;
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Active events editor not found";
+ }
+ });
+ return editor[0];
+ }
}