Java 类org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem 实例源码

项目:scanning    文件:ControlTreeViewerTest.java   
@Ignore("Travis does not like this one, rather a shame that")
@Test
public void addANumericScannable() throws Exception {

    SWTBotTreeItem item = bot.tree(0).getTreeItem("Experimental Conditions");
    item.select();

    bot.getDisplay().syncExec(()->viewer.addNode());

    SWTBotCCombo combo = bot.ccomboBox(0);
    assertNotNull(combo);
    combo.setSelection("a");

    assertEquals("a",   item.cell(1, 0));
    assertEquals("10.0    mm", item.cell(1, 1));

}
项目:scanning    文件:ControlTreeViewerTest.java   
@Ignore("Travis does not like this one, rather a shame that")
@Test
public void addAStringScannable() throws Exception {

    SWTBotTreeItem item = bot.tree(0).getTreeItem("Experimental Conditions");
    item.select();

    bot.getDisplay().syncExec(()->viewer.addNode());

    SWTBotCCombo combo = bot.ccomboBox(0);
    assertNotNull(combo);
    combo.setSelection("portshutter");

    assertEquals("portshutter",   item.cell(1, 0));
    assertEquals("Open", item.cell(1, 1));

}
项目:scanning    文件:ControlTreeViewerTest.java   
@Test
public void checkValuesTree3() throws Exception {

    ControlTree ct = getControlTree("control_tree3.xml");
    bot.getDisplay().syncExec(()->viewer.setControlTree(ct));

    assertEquals(2, bot.tree(0).columnCount());
    assertEquals(1, bot.tree(0).rowCount());

    assertEquals("Machine", bot.tree(0).cell(0, 0));

    SWTBotTreeItem item = bot.tree(0).getTreeItem("Machine");
    List<String> children = item.getNodes();
    assertEquals(Arrays.asList("Current"), children);

    assertEquals("Current",   item.cell(0, 0));
    assertEquals("5.0    mA", item.cell(0, 1));
}
项目:scanning    文件:ControlTreeViewerTest.java   
@Test
public void checkSetStageXValue() throws Exception {

    SWTBotTreeItem item = bot.tree(0).getTreeItem("Translations");
    assertEquals("Stage X",   item.cell(0, 0));

    SWTBotTreeItem node = item.getNode("Stage X");

    node.click(1);
    setEditorValue("10.0");
    assertEquals("10.0    mm", item.cell(0, 1));

    node.click(1);
    setEditorValue("0.0");
    assertEquals("0.0    mm", item.cell(0, 1));
}
项目:scanning    文件:ControlTreeViewerTest.java   
@Test
public void checkSetTemperatureValue() throws Exception {

    SWTBotTreeItem item = bot.tree(0).getTreeItem("Experimental Conditions");
    assertEquals("Temperature",   item.cell(0, 0));

    SWTBotTreeItem node = item.getNode("Temperature");

    node.click(1);
    setEditorValue("290.0");
    assertEquals("290.0    K", item.cell(0, 1));

    node.click(1);
    setEditorValue("295.0");
    assertEquals("295.0    K", item.cell(0, 1));
}
项目:scanning    文件:ControlTreeViewerTest.java   
@Test
public void checkSettingScannableValue() throws Exception {

    Services.getConnector().getScannable("stage_x").setPosition(1.0d);
    Services.getConnector().getScannable("stage_y").setPosition(2.0d);
    Thread.sleep(500);

    try {

        SWTBotTreeItem item = bot.tree(0).getTreeItem("Translations");
        List<String> children = item.getNodes();
        assertEquals(Arrays.asList("Stage X", "Stage Y", "Stage Z"), children);

        assertEquals("Stage X",   item.cell(0, 0));
        assertEquals("1.0    mm", item.cell(0, 1));
        assertEquals("Stage Y",   item.cell(1, 0));
        assertEquals("2.0    mm", item.cell(1, 1));

    } finally {

        Services.getConnector().getScannable("stage_x").setPosition(0.0d);
        Services.getConnector().getScannable("stage_y").setPosition(0.0d);
        Thread.sleep(500);

    }
}
项目:gw4e.project    文件:OutLineTest.java   
@Test
public void testFilterName() throws CoreException {
    GW4EProject project = new GW4EProject(bot, PROJECT_NAME);
    String[] resources = project.createWithSharedTemplate(PROJECT_NAME);

    editor = bot.gefEditor(resources[0]);
    editor.show();
    OutLineView oview = new OutLineView(bot,editor);
    oview.toggleFilterOn();
    oview.setNameText("v_A"); 
    bot.waitUntil(oview.createTreeRowCountCondition (4));
    Map<String,SWTBotTreeItem> map = oview.geVisibleTreeItems ();

    String [] keys  = new String [] { "v_A" ,"e_v_A_to_v_A" ,"e_v_A_to_v_B", "e_v_B_to_v_A" };

    for (String key : keys) {
        map.remove(key);
    }       
    assertTrue("Invalid filter result (name)", map.size()==0);
}
项目:gw4e.project    文件:OutLineTest.java   
@Test
public void testFilterDescription() throws CoreException {
    GW4EProject project = new GW4EProject(bot, PROJECT_NAME);
    String[] resources = project.createWithSharedTemplate(PROJECT_NAME);

    editor = bot.gefEditor(resources[0]);
    editor.show();

    VertexProperties gp = new VertexProperties(bot,editor);
    SWTBotGefEditPart vA = editor.getEditPart("v_A");

    gp.setDescription(vA, "new description");

    OutLineView oview = new OutLineView(bot,editor);
    oview.toggleFilterOn();
    oview.setDescriptionText("new description"); 
    bot.waitUntil(oview.createTreeRowCountCondition (1));
    Map<String,SWTBotTreeItem> map = oview.geVisibleTreeItems ();

    String [] keys  = new String [] { "v_A" };
    for (String key : keys) {
        map.remove(key);
    }       
    assertTrue("Invalid filter result (description)", map.size()==0);
}
项目:gw4e.project    文件:ToolbarEditorTest.java   
@Test
public void testSelectionVertex2() throws CoreException {
    GW4EProject project = new GW4EProject(bot, PROJECT_NAME);
    String[] resources = project.createWithSharedTemplate(PROJECT_NAME);
    editor = bot.gefEditor(resources[1]);
    editor.close();

    editor = bot.gefEditor(resources[0]);
    editor.show();

    OutLineView oview = new OutLineView(bot, editor);
    VertexProperties gp = new VertexProperties(bot, editor);

    oview.select("v_A");
    SWTBotGefEditPart vA = editor.getEditPart("v_A");
    oview.isSelected(vA);
    gp.assertPropertiesShown(vA);
    VertexId vertexId = new VertexId (((GWNode) vA.part().getModel()).getId());

    IToolbar toolbar = getToolbar();
    toolbar.delete(new UnexistingVertexCondition(vertexId,"v_A"));

    Map<String,SWTBotTreeItem> map = oview.geVisibleTreeItems();
    assertNull(map.get("v_A"));
    }
项目:gw4e.project    文件:ToolbarEditorTest.java   
@Test
public void testSelectionEdge2() throws CoreException {
    GW4EProject project = new GW4EProject(bot, PROJECT_NAME);
    String[] resources = project.createWithSharedTemplate(PROJECT_NAME);
    editor = bot.gefEditor(resources[1]);
    editor.close();

    editor = bot.gefEditor(resources[0]);
    editor.show();

    OutLineView oview = new OutLineView(bot, editor);

    VertexProperties gp = new VertexProperties(bot, editor);
    oview.select("e_to_V_A");
    SWTBotGefEditPart vA = editor.getEditPart("e_to_V_A");
    oview.isSelected(vA);
    gp.assertPropertiesShown(vA);

    IToolbar toolbar = getToolbar();
    toolbar.delete(new UnexistingEdgeCondition("e_to_V_A"));

    Map<String,SWTBotTreeItem> map = oview.geVisibleTreeItems();
    assertNull(map.get("e_to_V_A"));
    }
项目:gw4e.project    文件:GW4EProject.java   
public void convertExistingProject() throws CoreException {
    SWTBotTree tree = getProjectTree();
    SWTBotTreeItem item = tree.expandNode(this.projectName);
    item.setFocus();
    item.select();
    SWTBotMenu menu = item.contextMenu("Configure").contextMenu("Convert to GW4E");
    menu.click();
    bot.waitUntil(new DefaultCondition() {
        @Override
        public boolean test() throws Exception {
            boolean b = GW4ENature
                    .hasGW4ENature(ResourceManager.getProject(projectName));
            return b;
        }

        @Override
        public String getFailureMessage() {
            return "GraphWalker has not GraphWalker Nature ";
        }
    });
    cleanBuild();
}
项目:gw4e.project    文件:GW4EProject.java   
private ConvertDialog prepareConvertTo(String project, String packageRootFragment, String pkg,
        String targetFilename, String targetFormat, String... nodes) {
    SWTBotTree tree = getProjectTree();
    SWTBotTreeItem item = tree.expandNode(nodes);
    item.select();
    item.setFocus();

    SWTBotMenu menu = item.contextMenu("GW4E").contextMenu("Convert to...");
    menu.click();

    bot.waitUntil(Conditions.shellIsActive("GW4E Conversion File"));
    SWTBotShell shell = bot.shell("GW4E Conversion File");

    ConvertDialog cd = new ConvertDialog(shell);
    return cd;
}
项目:gw4e.project    文件:ProblemView.java   
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;
}
项目:gw4e.project    文件:IsItemSelectedInErrors.java   
public boolean test() throws Exception {
    try {

        SWTBotTreeItem item = this.problemView.expandErrorItem ();
        SWTBotTreeItem[] child = item.getItems();
        for (int i = 0; i < child.length; i++) {
            if (child[i].isSelected() && child[i].row().get(0).equalsIgnoreCase(checkedItem.row().get(0))) {
                return true;
            }
        }
        retry ();
        return false;
    } catch (WidgetNotFoundException e) {
        retry ();
        return false;
    }
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
/**
 * 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 WidgetNotFoundException 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();
        waitUntilTreeHasText(bot, item);
        if (item.getNode(subchildName) != null) {
          return item;
        }
      } catch (WidgetNotFoundException ex) {
        // Ignore
      }
    }
  }

  throw new WidgetNotFoundException(
      "The " + itemName + " node with a child of " + subchildName + " must exist in the tree.");
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
/**
 * Blocks the caller until the tree item has the given item text.
 * 
 * @param tree the tree item to search
 * @param nodeText the item text to look for
 * @throws org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException if the item could not
 *         be found within the timeout period
 */
private static void waitUntilTreeItemHasItem(SWTBot bot, final SWTBotTreeItem tree,
    final String nodeText) {

  // Attempt #1
  if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
    // Attempt #2: Something went wrong, try to cautiously reopen it.
    bot.sleep(1000);

    // There isn't a method to collapse, so double-click instead
    tree.doubleClick();
    bot.waitUntil(new TreeCollapsedCondition(tree.widget));

    bot.sleep(1000);

    tree.expand();
    bot.waitUntil(new TreeExpandedCondition(tree.widget));

    if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
      printTree(tree.widget);
      throw new TimeoutException(
          String.format("Timed out waiting for %s, giving up...", nodeText));
    }
  }
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
/**
 * Wait until a tree item contains a child with the given text.
 * 
 * @throws TimeoutException if the child does not appear within the default timeout
 */
public static void waitUntilTreeItemHasChild(SWTWorkbenchBot bot, final SWTBotTreeItem treeItem,
    final String childText) {
  bot.waitUntil(new DefaultCondition() {
    @Override
    public String getFailureMessage() {
      System.err.println(treeItem + ": expanded? " + treeItem.isExpanded());
      for (SWTBotTreeItem childNode : treeItem.getItems()) {
        System.err.println("    " + childNode);
      }
      return "Tree item never appeared";
    }

    @Override
    public boolean test() throws Exception {
      return treeItem.getNodes().contains(childText);
    }
  });
}
项目:google-cloud-eclipse    文件:SwtBotTreeUtilities.java   
/**
 * Wait until the tree item contains the given text with the timeout specified.
 */
public static void waitUntilTreeContainsText(SWTWorkbenchBot bot,
                                             final SWTBotTreeItem treeItem,
                                             final String text,
                                             long timeout) {
  bot.waitUntil(new DefaultCondition() {
    @Override
    public boolean test() throws Exception {
      return treeItem.getText().contains(text);
    }

    @Override
    public String getFailureMessage() {
      return "Text never appeared";
    }
  }, timeout);
}
项目:google-cloud-eclipse    文件:SwtBotProjectActions.java   
/**
 * Creates a Java class with the specified name.
 *
 * @param projectName the name of the project the class should be created in
 * @param sourceFolder the name of the source folder in which the class should be created.
 *        Typically "src" for normal Java projects, or "src/main/java" for Maven projects
 * @param packageName the name of the package the class should be created in
 * @param className the name of the class to be created
 */
public static void createJavaClass(final SWTWorkbenchBot bot, String sourceFolder,
    String projectName,
    String packageName, final String className) {
  SWTBotTreeItem project = SwtBotProjectActions.selectProject(bot, projectName);
  selectProjectItem(project, sourceFolder, packageName).select();
  SwtBotTestingUtilities.performAndWaitForWindowChange(bot, new Runnable() {
    @Override
    public void run() {
      MenuItem menuItem = ContextMenuHelper.contextMenu(getProjectRootTree(bot), "New", "Class");
      new SWTBotMenu(menuItem).click();
    }
  });

  SwtBotTestingUtilities.performAndWaitForWindowChange(bot, new Runnable() {
    @Override
    public void run() {
      bot.activeShell();
      bot.textWithLabel("Name:").setText(className);
      SwtBotTestingUtilities.clickButtonAndWaitForWindowClose(bot, bot.button("Finish"));
    }
  });
}
项目:google-cloud-eclipse    文件:SwtBotAppEngineActions.java   
private static void openImportProjectsWizard(SWTWorkbenchBot bot,
    String wizardCategory, String importWizardName) {
  for (int tries = 1; true; tries++) {
    SWTBotShell shell = null;
    try {
      bot.menu("File").menu("Import...").click();
      shell = bot.shell("Import");
      shell.activate();

      SwtBotTreeUtilities.waitUntilTreeHasItems(bot, bot.tree());
      SWTBotTreeItem treeItem = bot.tree().expandNode(wizardCategory);
      SwtBotTreeUtilities.waitUntilTreeItemHasChild(bot, treeItem, importWizardName);
      treeItem.select(importWizardName);
      break;
    } catch (TimeoutException e) {
      if (tries == 2) {
        throw e;
      } else if (shell != null) {
        shell.close();
      }
    }
  }
}
项目:mesfavoris    文件:BookmarksViewTest.java   
@Test
public void testGotoBookmarkOnDoubleClick() throws Exception {
    // Given
    Bookmark bookmark = new Bookmark(new BookmarkId(), ImmutableMap.of(Bookmark.PROPERTY_NAME, "bookmark",
            PROP_WORKSPACE_PATH, "/BookmarksViewTest/src/main/java/org/apache/commons/cli/DefaultParser.java",
            PROP_LINE_CONTENT,
            "for (Enumeration<?> enumeration = properties.propertyNames(); enumeration.hasMoreElements();)"));
    addBookmark(getBookmarksRootFolderId(), bookmark);
    SWTBotTreeItem bookmarkTreeItem = waitUntil("Cannot find new bookmark",
            () -> bookmarksViewDriver.tree().getTreeItem("bookmark"));

    // When
    bookmarkTreeItem.doubleClick();

    // Then
    waitUntil("cannot go to bookmark", () -> "DefaultParser.java".equals(getActivePart().getTitle()));
    IWorkbenchPart workbenchPart = getActivePart();
    ITextSelection selection = (ITextSelection) getSelection(workbenchPart);
    assertEquals("DefaultParser.java", workbenchPart.getTitle());
    assertEquals(146, selection.getStartLine());
}
项目:mesfavoris    文件:BookmarksViewTest.java   
@Test
public void testBookmarkProblemAddedOnDoubleClick() throws Exception {
    // Given
    Bookmark bookmark = new Bookmark(new BookmarkId(), ImmutableMap.of(Bookmark.PROPERTY_NAME, "bookmark",
            PROP_WORKSPACE_PATH, "/BookmarksViewTest/src/main/java/org/apache/commons/cli/DefaultParser.java",
            PROP_LINE_CONTENT,
            "for (Enumeration<?> enumeration = properties.propertyNames(); enumeration.hasMoreElements();)"));
    addBookmark(getBookmarksRootFolderId(), bookmark);
    SWTBotTreeItem bookmarkTreeItem = waitUntil("Cannot find new bookmark",
            () -> bookmarksViewDriver.tree().getTreeItem("bookmark"));

    // When
    bookmarkTreeItem.doubleClick();

    // Then
    waitUntil("There should be a bookmark problem",
            () -> "One bookmark problem detected".equals(bookmarksViewDriver.form().getMessage()));
}
项目:mesfavoris    文件:BookmarksViewTest.java   
@Test
public void testUpdateBookmarkPropertiesAction() throws Exception {
    // Given
    BookmarkId bookmarkId = new BookmarkId();
    Bookmark bookmark = new Bookmark(bookmarkId, ImmutableMap.of(Bookmark.PROPERTY_NAME, "bookmark",
            PROP_WORKSPACE_PATH, "/BookmarksViewTest/src/main/java/org/apache/commons/cli/DefaultParser.java",
            PROP_LINE_CONTENT,
            "for (Enumeration<?> enumeration = properties.propertyNames(); enumeration.hasMoreElements();)"));
    addBookmark(getBookmarksRootFolderId(), bookmark);
    SWTBotTreeItem bookmarkTreeItem = waitUntil("Cannot find new bookmark",
            () -> bookmarksViewDriver.tree().getTreeItem("bookmark"));
    bookmarkTreeItem.doubleClick();
    waitUntil("There should be a bookmark problem",
            () -> "One bookmark problem detected".equals(bookmarksViewDriver.form().getMessage()));

    // When
    bookmarksViewDriver.form().toolbarButtonWithTooltip("Use new properties", 0).click();

    // Then
    waitUntil("There should be no bookmark problem", () -> bookmarksViewDriver.form().getMessage() == null);
    assertEquals("for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();)",
            getBookmarksTree().getBookmark(bookmarkId)
                    .getPropertyValue(TextEditorBookmarkProperties.PROP_LINE_CONTENT));
}
项目:dsl-devkit    文件:SwtBotViewUtil.java   
/**
 * Wait until the contents of the given {@link SWTBotView} are loaded.
 *
 * @param view
 *          the view to be loaded
 */
public static void waitUntilViewIsLoaded(final SWTBotView view) {
  view.bot().waitUntil(new DefaultCondition() {

    @Override
    public boolean test() {
      SWTBotTreeItem[] allItems = view.bot().tree().getAllItems();
      return allItems.length == 0 || !allItems[0].getText().equals(LOADING_VIEW_MESSAGE);
    }

    @Override
    public String getFailureMessage() {
      return "View must be loaded: " + view.getTitle();
    }

  }, TIMEOUT_FOR_VIEW_TO_LOAD);
}
项目:dsl-devkit    文件:SwtBotWizardUtil.java   
/**
 * Select a tree item.
 *
 * @param treeItem
 *          the tree node
 * @param name
 *          the name of the item to look for
 * @return true, if item was found and selected
 */
private static boolean selectTreeItem(final SWTBotTreeItem treeItem, final String name) {
  if (name.equals(treeItem.getText())) {
    treeItem.select();
    return true;
  }
  if (!treeItem.isExpanded()) {
    treeItem.expand();
  }
  for (SWTBotTreeItem item : treeItem.getItems()) {
    if (selectTreeItem(item, name)) {
      return true;
    }
  }
  return false;
}
项目:dsl-devkit    文件:CoreSwtbotTools.java   
/**
 * 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();
}
项目:dsl-devkit    文件:CoreSwtbotTools.java   
/**
 * Waits until the node collapses.
 *
 * @param bot
 *          bot to work with, must not be {@code null}
 * @param node
 *          node to wait for, must not be {@code null}
 */
public static void safeBlockingCollapse(final SWTWorkbenchBot bot, final SWTBotTreeItem node) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(node, ARGUMENT_NODE);
  if (node.isExpanded()) {
    node.collapse();
    try {
      bot.waitUntil(new DefaultCondition() {

        @Override
        @SuppressWarnings("PMD.JUnit4TestShouldUseTestAnnotation")
        public boolean test() {
          return !node.isExpanded();
        }

        @Override
        public String getFailureMessage() {
          return "Timeout for node to collapse";
        }
      }, TIMEOUT_FOR_NODE_TO_COLLAPSE_EXPAND);
    } catch (TimeoutException e) {
      // Try one last time and do not wait anymore
      node.collapse();
    }
  }
}
项目:dsl-devkit    文件:CoreSwtbotTools.java   
/**
 * Attempts to expand all nodes along the path specified by the node array parameter.
 * The method is copied from SWTBotTree with an additional check if the node is already expanded.
 *
 * @param bot
 *          tree bot, must not be {@code null}
 * @param nodes
 *          node path to expand, must not be {@code null} or empty
 * @return the last tree item that was expanded, or {@code null} if no item was found
 */
public static SWTBotTreeItem expandNode(final SWTBotTree bot, final String... nodes) {
  Assert.isNotNull(bot, ARGUMENT_BOT);
  Assert.isNotNull(nodes, ARGUMENT_NODES);
  assertArgumentIsNotEmpty(nodes, ARGUMENT_NODES);
  new SWTBot().waitUntil(widgetIsEnabled(bot));
  SWTBotTreeItem item = bot.getTreeItem(nodes[0]);
  if (!item.isExpanded()) {
    item.expand();
  }

  final List<String> asList = new ArrayList<String>(Arrays.asList(nodes));
  asList.remove(0);
  if (!asList.isEmpty()) {
    item = expandNode(item, asList.toArray(new String[asList.size()]));
  }

  return item;
}
项目:scenarioo-example-swtbot-e4    文件:OrderOverviewContextMenuHandler.java   
private void openContextMenuForTreeItem(final SWTBotTreeItem treeItem) {

        treeItem.select();
        Display.getDefault().syncExec(new Runnable() {

            @Override
            public void run() {
                Menu menu = orderOverviewTree.widget.getMenu();
                Point menuItemLocation = getMenuItemLocation(treeItem);
                menu.setLocation(menuItemLocation.x, menuItemLocation.y);
                menu.setVisible(true);
            }
        });
        bot.sleep(200); // remove this sleep with waitUntil context menu is open
        LOGGER.info("popup is opened: " + treeItem.getText());
    }
项目:scenarioo-example-swtbot-e4    文件:OrderOverviewCleanUpStatement.java   
private void removeAllOrdersFromOrderOverview() {

        LOGGER.info("\n-----------------------------------------------------------------"
                + "\nThe order overview clean up is executed..\n"
                + "-----------------------------------------------------------------");
        int ordersCount = tree.getAllItems().length;
        for (int i = ordersCount - 1; i >= 0; i--) {
            SWTBotTreeItem treeItem = tree.getAllItems()[i];
            List<SWTBotTreeItem> allItems = Arrays.asList(tree.getAllItems());
            LOGGER.info("remove order: " + treeItem.getText() + ", size=" + tree.getAllItems().length + ", allItems="
                    + allItems.toString());
            treeItem.contextMenu("Remove Order").click();
            bot.waitUntil(new OrderRemovedCondition(treeItem));
        }
        LOGGER.info("The order overview clean up statement is finished.\n\n");
    }
项目:gwt-eclipse-plugin    文件:SwtBotUtils.java   
/**
 * Create a java project with the specified project name. This function opens up the Java
 * Perspective.
 *
 * @param bot The current SWTWorkbenchBot object
 * @param projectName Name of java project to be created
 */
public static void createJavaProject(SWTWorkbenchBot bot, String projectName) {
  // Open Java Perspective
  bot.perspectiveById("org.eclipse.jdt.ui.JavaPerspective").activate();

  // Open the list of new project wizards
  bot.menu("File").menu("New").menu("Project...").click();

  // Select the Java project
  SWTBotTree projectSelectionTree = bot.tree();
  SWTBotTreeItem projectSelectionTreeItem =
      SwtBotTreeActions.getUniqueTreeItem(bot, projectSelectionTree, "Java", "Java Project");
  SwtBotTreeActions.selectTreeItem(bot, projectSelectionTreeItem, "Java Project");

  bot.button("Next >").click();

  // Configure the project and then create it
  bot.textWithLabel("Project name:").setText(projectName);

  SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
}
项目:gwt-eclipse-plugin    文件:SwtBotTreeActions.java   
/**
 * 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.");
}
项目:gwt-eclipse-plugin    文件:SwtBotTreeActions.java   
/**
 * Blocks the caller until the tree item has the given item text.
 *
 * @param tree the tree item to search
 * @param nodeText the item text to look for
 * @throws org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException if the item could not
 *         be found within the timeout period
 */
private static void waitUntilTreeItemHasItem(SWTBot bot, final SWTBotTreeItem tree,
    final String nodeText) {

  // Attempt #1
  if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
    // Attempt #2: Something went wrong, try to cautiously reopen it.
    bot.sleep(1000);

    // There isn't a method to collapse, so double-click instead
    tree.doubleClick();
    bot.waitUntil(new TreeCollapsedCondition(tree.widget));

    bot.sleep(1000);

    tree.expand();
    bot.waitUntil(new TreeExpandedCondition(tree.widget));

    if (!waitUntilTreeHasItemImpl(bot, tree.widget, nodeText)) {
      printTree(tree.widget);
      throw new TimeoutException(
          String.format("Timed out waiting for %s, giving up...", nodeText));
    }
  }
}
项目:gwt-eclipse-plugin    文件:SwtBotTreeActions.java   
/**
 * Blocks the caller until all of the direct children of the tree have text. The assumption is
 * that the tree does not have any "empty" children.
 *
 * TODO: Refactor some of this logic; it follows the same general pattern as
 * {@link #waitUntilTreeItemHasItem(SWTBot, SWTBotTreeItem, String)}.
 *
 * @param tree the tree to search
 * @throws TimeoutException if all of the direct children of the tree do not have text within the
 *         timeout period
 */
public static void waitUntilTreeHasText(SWTBot bot, final SWTBotTreeItem tree)
    throws TimeoutException {
  // Attempt #1
  if (!waitUntilTreeHasTextImpl(bot, tree.widget)) {
    // Attempt #2: Something went wrong, try to cautiously reopen it.
    bot.sleep(1000);

    // There isn't a method to collapse, so double-click instead
    tree.doubleClick();
    bot.waitUntil(new TreeCollapsedCondition(tree.widget));

    bot.sleep(1000);

    tree.expand();
    bot.waitUntil(new TreeExpandedCondition(tree.widget));

    if (!waitUntilTreeHasTextImpl(bot, tree.widget)) {
      printTree(tree.widget);
      throw new TimeoutException(
          "Timed out waiting for text of the tree's children, giving up...");
    }
  }
}
项目:gwt-eclipse-plugin    文件:SwtBotProjectActions.java   
/**
 * Creates a java class with the specified name.
 *
 * @param bot The SWTWorkbenchBot.
 * @param projectName The name of the project the class should be created in.
 * @param packageName The name of the package the class should be created in.
 * @param className The name of the java class to be created.
 */
public static void createJavaClass(final SWTWorkbenchBot bot, String projectName,
    String packageName, final String className) {
  SWTBotTreeItem project = SwtBotProjectActions.selectProject(bot, projectName);
  selectProjectItem(project, SOURCE_FOLDER, packageName).select();
  SwtBotUtils.performAndWaitForWindowChange(bot, new Runnable() {
    @Override
    public void run() {
      MenuItem menuItem = ContextMenuHelper.contextMenu(getProjectRootTree(bot), "New", "Class");
      new SWTBotMenu(menuItem).click();
    }
  });

  SwtBotUtils.performAndWaitForWindowChange(bot, new Runnable() {
    @Override
    public void run() {
      bot.activeShell();
      bot.textWithLabel("Name:").setText(className);
      SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
    }
  });
}
项目:gwt-eclipse-plugin    文件:SwtBotProjectActions.java   
/**
 * Creates a java project with the specified project name.
 *
 * @param bot the SWTWorkbenchBot
 * @param projectName the name of the java project to create
 */
public static void createJavaProject(SWTWorkbenchBot bot, String projectName) {
  // Open Java Perspective
  bot.perspectiveById("org.eclipse.jdt.ui.JavaPerspective").activate();

  // Open the list of new project wizards
  bot.menu("File").menu("New").menu("Project...").click();

  // Select the Java project
  SWTBotTree projectSelectionTree = bot.tree();
  SWTBotTreeItem projectSelectionGoogleTreeItem =
      SwtBotTreeActions.getUniqueTreeItem(bot, projectSelectionTree, "Java", "Java Project");
  SwtBotTreeActions.selectTreeItem(bot, projectSelectionGoogleTreeItem, "Java Project");

  bot.button("Next >").click();

  // Configure the project and then create it
  bot.textWithLabel("Project name:").setText(projectName);

  SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
}
项目:gwt-eclipse-plugin    文件:SwtBotProjectActions.java   
public static void createUiBinder(final SWTWorkbenchBot bot, String projectName,
    String packageName, String name, boolean generateSampleContent, boolean generateComments) {
  // Open the list of new project wizards
  bot.menu("File").menu("New").menu("Other...").click();

  // Select the Web App project wizard
  SWTBotTree projectSelectionTree = bot.tree();
  SWTBotTreeItem projectSelectionGoogleTreeItem = SwtBotTreeActions
      .getUniqueTreeItem(bot, projectSelectionTree, "GWT Classes", "UiBinder").expand();
  SwtBotTreeActions.selectTreeItem(bot, projectSelectionGoogleTreeItem, "UiBinder");
  bot.button("Next >").click();

  // Configure the UiBinder and then create it
  String sourceFolder = projectName + "/" + SOURCE_FOLDER;
  bot.textWithLabel("Source folder:").setText(sourceFolder);
  bot.textWithLabel("Package:").setText(packageName);
  bot.textWithLabel("Name:").setText(name);

  SwtBotUtils.setCheckBox(bot.checkBox("Generate sample content"),
      generateSampleContent);
  SwtBotUtils.setCheckBox(bot.checkBox("Generate comments"), generateComments);

  SwtBotUtils.clickButtonAndWaitForWindowChange(bot, bot.button("Finish"));
}
项目:gwt-eclipse-plugin    文件:SwtBotProjectActions.java   
/**
 * 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;
}
项目:gwt-eclipse-plugin    文件:SwtBotProjectActions.java   
/**
 * 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;
}
项目:gwt-eclipse-plugin    文件:SwtBotProjectActions.java   
/**
 * 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();
}