Java Code Examples for org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot#widget()

The following examples show how to use org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot#widget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns true if the specified project can be found in the 'Package Explorer' or 'Project View',
 * otherwise returns false. Throws a WidgetNotFoundException exception if the 'Package Explorer'
 * or 'Project Explorer' view cannot be found.
 *
 * @param bot The SWTWorkbenchBot.
 * @param projectName The name of the project to be found.
 * @return if the project exists
 */
public static boolean doesProjectExist(final SWTWorkbenchBot bot, String projectName) {
  SWTBotView explorer = getPackageExplorer(bot);
  if (explorer == null) {
    throw new WidgetNotFoundException(
        "Could not find the 'Package Explorer' or 'Project Explorer' view.");
  }

  // Select the root of the project tree in the explorer view
  Widget explorerWidget = explorer.getWidget();
  Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget);
  SWTBotTreeItem[] allItems = new SWTBotTree(explorerTree).getAllItems();
  for (int i = 0; i < allItems.length; i++) {
    if (allItems[i].getText().equals(projectName)) {
      return true;
    }
  }
  return false;
}
 
Example 2
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the specified project. Throws a WidgetNotFoundException if the 'Package Explorer' or
 * 'Project Explorer' view cannot be found or if the specified project cannot be found.
 *
 * @param bot The SWTWorkbenchBot.
 * @param projectName The name of the project to select.
 * @return the tree
 */
public static SWTBotTreeItem selectProject(final SWTWorkbenchBot bot, String projectName) {
  /*
   * Choose either the Package Explorer View or the Project Explorer view. Eclipse 3.3 and 3.4
   * start with the Java Perspective, which has the Package Explorer View open by default, whereas
   * Eclipse 3.5 starts with the Resource Perspective, which has the Project Explorer View open.
   */
  SWTBotView explorer = getPackageExplorer(bot);
  for (SWTBotView view : bot.views()) {
    if (view.getTitle().equals("Package Explorer")
        || view.getTitle().equals("Project Explorer")) {
      explorer = view;
      break;
    }
  }

  if (explorer == null) {
    throw new WidgetNotFoundException(
        "Could not find the 'Package Explorer' or 'Project Explorer' view.");
  }

  // Select the root of the project tree in the explorer view
  Widget explorerWidget = explorer.getWidget();
  Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget);
  return new SWTBotTree(explorerTree).getTreeItem(projectName).select();
}
 
Example 3
Source File: SwtBotProjectActions.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the specified project is found in the 'Package Explorer' or 'Project View',
 * otherwise returns false. Throws a WidgetNotFoundException exception if the 'Package Explorer'
 * or 'Project Explorer' view cannot be found.
 *
 * @param projectName the name of the project to be found
 * @return true if the project is found, and false if not found
 */
public static boolean projectFound(SWTWorkbenchBot bot, String projectName) {
  SWTBotView explorer = getExplorer(bot);

  // Select the root of the project tree in the explorer view
  Widget explorerWidget = explorer.getWidget();
  Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget);
  for (SWTBotTreeItem item : new SWTBotTree(explorerTree).getAllItems()) {
    if (item.getText().equals(projectName)) {
      return true;
    }
  }
  return false;
}
 
Example 4
Source File: SwtBotProjectActions.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/** Collapse all projects shown in the Project Explorer. */
public static void collapseProjects(SWTWorkbenchBot bot) {
  for (SWTBotView explorer :
      bot.views(WidgetMatcherFactory.withPartId(IPageLayout.ID_PROJECT_EXPLORER))) {
    Widget explorerWidget = explorer.getWidget();
    Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget);
    for (SWTBotTreeItem item : new SWTBotTree(explorerTree).getAllItems()) {
      item.collapse();
    }
  }
}
 
Example 5
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the project root tree in Package Explorer.
 */
public static SWTBotTree getProjectRootTree(SWTWorkbenchBot bot) {
  SWTBotView explorer = getPackageExplorer(bot);

  if (explorer == null) {
    throw new WidgetNotFoundException("Cannot find Package Explorer or Project Explorer");
  }

  Tree tree = bot.widget(widgetOfType(Tree.class), explorer.getWidget());
  return new SWTBotTree(tree);
}
 
Example 6
Source File: SwtBotProjectActions.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the project root tree in Package Explorer.
 */
public static SWTBotTree getProjectRootTree(SWTWorkbenchBot bot) {
  SWTBotView explorer = getExplorer(bot);
  Tree tree = bot.widget(widgetOfType(Tree.class), explorer.getWidget());
  return new SWTBotTree(tree);
}
 
Example 7
Source File: SwtBotProjectActions.java    From google-cloud-eclipse with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the specified project.
 *
 * @param projectName the name of the project to select
 * @param explorer the explorer view, assumed to be either the Project Explorer or the Package
 *     Explorer
 * @return the selected tree item
 * @throws WidgetNotFoundException if the 'Package Explorer' or 'Project Explorer' view cannot be
 *     found or if the specified project cannot be found.
 */
public static SWTBotTreeItem selectProject(
    SWTWorkbenchBot bot, SWTBotView explorer, String projectName) {
  // Select the root of the project tree in the explorer view
  Widget explorerWidget = explorer.getWidget();
  Tree explorerTree = bot.widget(widgetOfType(Tree.class), explorerWidget);
  return SwtBotTreeUtilities.select(bot, new SWTBotTree(explorerTree), projectName);
}
 
Example 8
Source File: SWTBotCustomChartUtils.java    From tracecompass with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Close the chart received in parameter. It clicks on the close button of
 * the chart.
 *
 * @param bot
 *            The SWT workbench bot to use
 * @param customChart
 *            The custom chart to close
 */
public static void closeChart(SWTWorkbenchBot bot, Chart customChart) {
    Button closeButton = bot.widget(closeButtonForChart(customChart), 0);
    SWTBotButton button = new SWTBotButton(closeButton);
    button.click();
}