Java源码示例:org.eclipse.swtbot.swt.finder.finders.ContextMenuHelper

示例1
/**
 * 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(SWTWorkbenchBot bot, String sourceFolder, String projectName,
    String packageName, String className) {
  SWTBotTreeItem project = SwtBotProjectActions.selectProject(bot, projectName);
  selectProjectItem(project, sourceFolder, packageName).select();
  SwtBotTestingUtilities.performAndWaitForWindowChange(bot, () -> {
    MenuItem menuItem = ContextMenuHelper.contextMenu(getProjectRootTree(bot), "New", "Class");
    new SWTBotMenu(menuItem).click();
  });

  SwtBotTestingUtilities.performAndWaitForWindowChange(bot, () -> {
    bot.activeShell();
    bot.textWithLabel("Name:").setText(className);
    SwtBotTestingUtilities.clickButtonAndWaitForWindowClose(bot, bot.button("Finish"));
  });
}
 
示例2
/**
 * 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"));
    }
  });
}
 
示例3
public static SWTBotMenu clickableContextMenu(final SWTBotEclipseEditor editor, final String... text) {
  MenuItem _contextMenu = ContextMenuHelper.contextMenu(editor.getStyledText(), text);
  return new SWTBotMenu(_contextMenu);
}