Java Code Examples for org.eclipse.swtbot.swt.finder.widgets.SWTBotTree#getAllItems()

The following examples show how to use org.eclipse.swtbot.swt.finder.widgets.SWTBotTree#getAllItems() . 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: SwtBotTreeUtilities.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Wait until the given tree has items, then return the first item.
 *
 * @throws TimeoutException if no items appear within the default timeout
 */
public static SWTBotTreeItem waitUntilTreeHasItems(SWTWorkbenchBot bot, SWTBotTree tree) {
  bot.waitUntil(
      new DefaultCondition() {
        @Override
        public String getFailureMessage() {
          return "Tree items never appeared";
        }

        @Override
        public boolean test() throws Exception {
          return tree.hasItems();
        }
      });
  return tree.getAllItems()[0];
}
 
Example 2
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Open view.
 *
 * @param bot
 *          to work with, must not be {@code null}
 * @param category
 *          the category, must not be {@code null}
 * @param view
 *          the name of the view, must not be {@code null}
 */
public static void openView(final SWTWorkbenchBot bot, final String category, final String view) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(category, "category");
  Assert.isNotNull(view, ARGUMENT_VIEW);
  bot.menu("Window").menu("Show View").menu("Other...").click();
  bot.shell("Show View").activate();
  final SWTBotTree tree = bot.tree();

  for (SWTBotTreeItem item : tree.getAllItems()) {
    if (category.equals(item.getText())) {
      CoreSwtbotTools.waitForItem(bot, item);
      final SWTBotTreeItem[] node = item.getItems();

      for (SWTBotTreeItem swtBotTreeItem : node) {
        if (view.equals(swtBotTreeItem.getText())) {
          swtBotTreeItem.select();
        }
      }
    }
  }
  assertTrue("View or Category found", bot.button().isEnabled());
  bot.button("OK").click();
}
 
Example 3
Source File: FetchRemoteTracesTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static void importProfiles() {
    openRemoteProfilePreferences();
    TmfFileDialogFactory.setOverrideFiles(PROFILES_LOCATION);
    fBot.button("Import").click();

    // Change the root path of every profile
    SWTBotTree tree = fBot.tree(1);
    for (SWTBotTreeItem profile : tree.getAllItems()) {
        for (SWTBotTreeItem node : profile.getItems()) {
            for (SWTBotTreeItem traceGroup : node.getItems()) {
                traceGroup.select();
                fBot.textWithLabel("Root path:").setText(TRACE_LOCATION);
            }
        }
    }
    SWTBotUtils.pressOKishButtonInPreferences(fBot);
}
 
Example 4
Source File: ConditionHelpers.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Is a tree node available
 *
 * @param name
 *            the name of the node
 * @param tree
 *            the parent tree
 * @return ICondition for verification
 */
public static ICondition isTreeNodeAvailable(final String name, final SWTBotTree tree) {
    return new SWTBotTestCondition() {
        @Override
        public boolean test() throws Exception {
            try {
                final SWTBotTreeItem[] treeItems = tree.getAllItems();
                for (SWTBotTreeItem ti : treeItems) {
                    final String text = ti.getText();
                    if (text.equals(name)) {
                        return true;
                    }
                }
            } catch (Exception e) {
            }
            return false;
        }

        @Override
        public String getFailureMessage() {
            return NLS.bind("No child of tree {0} found with text {1}. Child items: {2}",
                    new String[] { tree.toString(), name, Arrays.toString(tree.getAllItems()) });
        }
    };
}
 
Example 5
Source File: AddProjectNatureTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test viewer filter.
 */
@Test
public void testViewerFilter() {

    /* Check that shadow project is visible */
    toggleFilters(false);
    SWTBotTreeItem shadowProject = SWTBotUtils.selectProject(fBot, SOME_PROJECT_SHADOW_NAME);
    assertEquals(SOME_PROJECT_SHADOW_NAME, shadowProject.getText());
    SWTBotTreeItem tracesItem = SWTBotUtils.getTraceProjectItem(fBot, shadowProject, TRACES_FOLDER_NAME);
    SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, tracesItem, TRACE_NAME);
    assertEquals(TRACE_NAME, traceItem.getText());
    SWTBotUtils.getTraceProjectItem(fBot, shadowProject, EXPERIMENTS_FOLDER_NAME);

    /* Check that shadow project is not visible */
    toggleFilters(true);

    SWTBotView viewBot = fBot.viewByTitle(PROJECT_EXPLORER_TITLE);
    viewBot.setFocus();
    SWTBot projectExplorerBot = viewBot.bot();

    final SWTBotTree tree = projectExplorerBot.tree();
    SWTBotTreeItem[] items = tree.getAllItems();
    for (SWTBotTreeItem swtBotTreeItem : items) {
        assertNotEquals(SOME_PROJECT_SHADOW_NAME, swtBotTreeItem.getText());
    }
}
 
Example 6
Source File: SwtBotTreeActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Given a tree that contains an entry with <code>itemName</code> and a direct child with a name
 * matching <code>subchildName</code>, return its tree item.
 *
 * This method is useful when there is the possibility of a tree having two similarly-named
 * top-level nodes.
 *
 * @param mainTree the tree
 * @param itemName the name of a top-level node in the tree
 * @param subchildName the name of a direct child of the top-level node (used to uniquely select
 *        the appropriate tree item for the given top-level node name)
 * @return the tree item corresponding to the top-level node with <code>itemName</code>that has a
 *         direct child with <code>subchildName</code>. If there are multiple tree items that
 *         satisfy this criteria, then the first one (in the UI) will be returned
 *
 * @throws IllegalStateException if no such node can be found
 */
public static SWTBotTreeItem getUniqueTreeItem(final SWTBot bot, final SWTBotTree mainTree,
    String itemName, String subchildName) {
  for (SWTBotTreeItem item : mainTree.getAllItems()) {
    if (itemName.equals(item.getText())) {
      try {
        item.expand();
        SwtBotTreeActions.waitUntilTreeHasText(bot, item);
        if (item.getNode(subchildName) != null) {
          return item;
        }
      } catch (WidgetNotFoundException e) {
        // Ignore
      }
    }
  }

  throw new IllegalStateException("The '" + itemName + "' node with a child of '" + subchildName
      + "' must exist in the tree.");
}
 
Example 7
Source File: SwtBotProjectActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns true if there are errors in the Problem view. Returns false otherwise.
 */
public static boolean hasErrorsInProblemsView(SWTWorkbenchBot bot) {
  // Open Problems View by Window -> show view -> Problems
  bot.menu("Window").menu("Show View").menu("Problems").click();

  SWTBotView view = bot.viewByTitle("Problems");
  view.show();
  SWTBotTree tree = view.bot().tree();

  for (SWTBotTreeItem item : tree.getAllItems()) {
    String text = item.getText();
    if (text != null && text.startsWith("Errors")) {
      return true;
    }
  }

  return false;
}
 
Example 8
Source File: SwtBotWizardUtil.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Select a TreeItem with the given name in a tree.
 *
 * @param tree
 *          the tree in which the item is searched
 * @param name
 *          the name of the required item
 * @return true, if the item was selected
 */
public static boolean selectItem(final SWTBotTree tree, final String name) {
  SWTBotTreeItem[] items = tree.getAllItems();
  for (SWTBotTreeItem item : items) {
    if (selectTreeItem(item, name)) {
      return true;
    }
  }
  return false;
}
 
Example 9
Source File: CoreSwtbotTools.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find tree item.
 * <p>
 * <em>Note</em>: Throws an AssertionError if the item could not be found.
 * </p>
 *
 * @param bot
 *          to work with, must not be {@code null}
 * @param tree
 *          to search in, must not be {@code null}
 * @param item
 *          to search, must not be {@code null}
 * @return the {@link SWTBotTreeItem}, never {@code null}
 */
public static SWTBotTreeItem findTreeItem(final SWTWorkbenchBot bot, final SWTBotTree tree, final String item) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(tree, "tree");
  Assert.isNotNull(item, ARGUMENT_ITEM);
  int itemCount = 0;
  boolean itemFound = false;
  SWTBotTreeItem botTreeItem = null;
  CoreSwtbotTools.waitForTreeItem(bot, tree);

  do {
    for (SWTBotTreeItem treeItem : tree.getAllItems()) {
      itemCount = treeItem.rowCount();
      if (item.equals(treeItem.getText())) {
        itemFound = true;
        botTreeItem = treeItem;
        break;
      } else {
        for (SWTBotTreeItem treeNode : tree.getAllItems()) {
          CoreSwtbotTools.waitForItem(bot, treeNode);
          itemCount = treeNode.rowCount();
        }
      }
    }
  } while (itemCount > 0);

  assertTrue("Searching TreeItem", itemFound);

  return botTreeItem;

}
 
Example 10
Source File: FetchRemoteTracesTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void clearProfiles() {
    openRemoteProfilePreferences();
    SWTBotTree tree = fBot.tree(1);
    for (SWTBotTreeItem profile : tree.getAllItems()) {
        profile.select();
        fBot.button("Remove").click();
    }
    SWTBotUtils.pressOKishButtonInPreferences(fBot);
}
 
Example 11
Source File: CountersViewBenchmark.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void prepareView(SWTBotView view) {
    SWTBotTree tree = view.bot().tree();
    for (SWTBotTreeItem item : tree.getAllItems()) {
        item.check();
    }
}
 
Example 12
Source File: SwtBotMenuActions.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static void openNewMavenProject(SWTWorkbenchBot bot) {
  openNewOtherProjectDialog(bot);

  // filter maven options
  bot.text().setText("maven");
  bot.sleep(500);

  // click on Maven Project
  SWTBotTree tree = bot.tree();
  SWTBotTreeItem[] items = tree.getAllItems();
  SwtBotTreeActions.selectTreeItem(bot, items[0], "Maven Project");

  // move to next step
  bot.button("Next >").click();
}
 
Example 13
Source File: SuperBot.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private void selectProjectFiles(SWTBotTree tree, String project, String[] files) {
  for (SWTBotTreeItem item : tree.getAllItems()) while (item.isChecked()) item.uncheck();

  for (String file : files) {
    String[] nodes = file.split("/|\\\\");
    List<String> regex = new ArrayList<String>(nodes.length + 1);
    regex.add(Pattern.quote(project));

    for (String node : nodes) regex.add(Pattern.quote(node));

    WidgetUtil.getTreeItemWithRegex(tree, regex.toArray(new String[0])).check();
  }
}
 
Example 14
Source File: ContextMenusInPEView.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
private List<String> getTextOfItems(SWTBotTree tree) {
  List<String> allItemTexts = new ArrayList<String>();
  for (SWTBotTreeItem item : tree.getAllItems()) {
    allItemTexts.add(item.getText());
  }
  return allItemTexts;
}
 
Example 15
Source File: SuperBot.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
public void confirmShellShareProjectFiles(String project, String[] files, JID[] jids) {
  SWTBot bot = new SWTBot();
  SWTBotShell shell = bot.shell(SHELL_SHARE_PROJECT);
  shell.activate();

  // wait for tree update
  bot.sleep(500);

  SWTBotTree tree = shell.bot().tree();

  selectProjectFiles(tree, project, files);

  shell.bot().button(NEXT).click();

  // wait for tree update
  bot.sleep(500);

  tree = shell.bot().tree();

  for (SWTBotTreeItem item : tree.getAllItems()) while (item.isChecked()) item.uncheck();

  for (JID jid : jids)
    WidgetUtil.getTreeItemWithRegex(tree, Pattern.quote(jid.getBase()) + ".*").check();

  shell.bot().button(FINISH).click();
  bot.waitUntil(Conditions.shellCloses(shell));
}