/**
   * @see https://community.jboss.org/message/732539#732539
   * @param projectName
   * @param pkgName
   */
  private void jaxWsApi22RequirementWorkaround(String projectName, String pkgName) {
    SWTBotEclipseEditor editor =
        packageExplorer
            .openFile(projectName, "src", pkgName, "AreaService_Service.java")
            .toTextEditor();

    String text = editor.getText();
    boolean putComment = false;
    StringBuilder output = new StringBuilder();
    for (String line : text.split(System.getProperty("line.separator"))) {
      if (line.contains(
          "This constructor requires JAX-WS API 2.2. You will need to endorse the 2.2")) {
        putComment = true;
      }
      if (putComment) {
        output.append("//");
        if (line.contains("}")) {
          putComment = false;
        }
      }
      output.append(line);
      output.append(System.getProperty("line.separator"));
    }
    editor.setText(output.toString());
    editor.saveAndClose();
  }
Exemplo n.º 2
0
  /*
   * Verify that the POM XML editor is smart enough to offer proper content assist even if the POM does not explicitly
   * declare a schema (MNGECLIPSE-1770).
   */
  @Test
  public void testContentAssistWithoutSchema() throws Exception {
    String name = PROJECT_NAME + "/ca.pom";
    String str =
        "<project>\n" //
            + "<modelVersion>4.0.0</modelVersion>\n" //
            + "<groupId>test</groupId>\n" //
            + "<artifactId>ca</artifactId>\n" //
            + "<packaging>jar</packaging>\n" //
            + "<version>0.0.1-SNAPSHOT</version>\n" //
            + "<build>\n" //
            + "</build>\n" //
            + "</project>\n";
    createFile(name, str);

    openPomFile(name);

    selectEditorTab(TAB_POM_XML);
    findText("</build>");

    SWTBotEclipseEditor editor = bot.activeEditor().toTextEditor();
    editor.pressShortcut(KeyStroke.getInstance(SWT.ARROW_LEFT));
    editor.pressShortcut(SWT.CTRL, ' ');
    editor.pressShortcut(KeyStroke.getInstance(SWT.LF));
    String text = editor.getText();
    assertTrue(text, text.contains("<defaultGoal>"));
  }
  /**
   * Selects textToSelect within Source Pane of editor with title editorTitle
   *
   * @param bot
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @return SWTBotEclipseEditor
   */
  public static SWTBotEclipseEditor selectTextInSourcePane(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex) {

    SWTBotEclipseEditor editor = bot.editorByTitle(editorTitle).toTextEditor();
    String editorText = editor.getText();
    boolean found = false;
    int iStartIndex = 0;
    int iRow = 0;
    if (editorText != null && editorText.length() > 0 && editorText.contains(textToSelect)) {
      int iOccurenceIndex = 0;
      while (!found && iRow < editor.getLineCount()) {
        String lineText = editor.getTextOnLine(iRow);
        iStartIndex = 0;
        while (!found && lineText.contains(textToSelect)) {
          if (iOccurenceIndex == textToSelectIndex) {
            found = true;
            iStartIndex += lineText.indexOf(textToSelect);
          } else {
            iOccurenceIndex++;
            int iNewStartIndex = lineText.indexOf(textToSelect) + textToSelect.length();
            iStartIndex += iNewStartIndex;
            lineText = lineText.substring(iNewStartIndex);
          }
        }
        if (!found) {
          iRow++;
        }
      }
    }

    if (found) {
      int column = iStartIndex + selectionOffset;
      editor.selectRange(iRow, column, selectionLength);
      bot.waitUntil(new CursorAtPosition(editor, new Position(iRow, column)));
    } else {
      throw new SelectTextInSourcePaneException(
          "Wrong parameters specified for method selectTextInSourcePane.\n"
              + "Unable to select required text '"
              + textToSelect
              + "' within editor with title "
              + editorTitle
              + ".\n"
              + "Editor text is: "
              + editorText);
    }
    return editor;
  }
 /**
  * Debug Drools Rule and checks result
  *
  * @param droolsRuletName
  */
 private void debugDroolsRule(String droolsRuleName) {
   packageExplorer.show();
   SWTBotTreeItem tiDroolsRule =
       packageExplorer.selectTreeItem(
           DroolsAllBotTests.SAMPLE_DROOLS_RULE_NAME,
           new String[] {
             DroolsAllBotTests.DROOLS_PROJECT_NAME, DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE
           });
   SWTBot packageExplorerBot = bot.viewByTitle(ViewType.PACKAGE_EXPLORER.getViewLabel()).bot();
   SWTBotTree tree = packageExplorerBot.tree();
   // Select and Open Rule File
   ContextMenuHelper.prepareTreeItemForContextMenu(tree, tiDroolsRule);
   new SWTBotMenu(ContextMenuHelper.getContextMenu(tree, IDELabel.Menu.OPEN, true)).click();
   SWTBotEclipseEditor ruleEditor = bot.editorByTitle(droolsRuleName).toTextEditor();
   ruleEditor.selectRange(8, 0, 0);
   bot.menu(IDELabel.Menu.RUN).menu(IDELabel.Menu.TOGGLE_BREAKPOINT).click();
   SWTBotTreeItem tiDroolsTest =
       packageExplorer.selectTreeItem(
           DroolsAllBotTests.DROOLS_TEST_JAVA_TREE_NODE,
           new String[] {
             DroolsAllBotTests.DROOLS_PROJECT_NAME,
             DroolsAllBotTests.SRC_MAIN_JAVA_TREE_NODE,
             DroolsAllBotTests.COM_SAMPLE_TREE_NODE
           });
   console.clearConsole();
   eclipse.debugTreeItemAsDroolsApplication(tiDroolsTest);
   eclipse.closeConfirmPerspectiveSwitchShellIfOpened(false);
   String consoleText = console.getConsoleText(3 * 1000L, 3 * 1000L, true);
   assertTrue(
       "Drools Rule was not debuged properly.\nConsole content should have been empty but is:\n"
           + consoleText,
       consoleText.length() == 0);
   SWTBotView debugView = bot.viewByTitle(ViewType.DEBUG.getViewLabel());
   debugView.toolbarButton(IDELabel.DebugView.BUTTON_STEP_OVER_TOOLTIP).click();
   consoleText = console.getConsoleText(3 * 1000L, 60 * 1000L, true);
   assertTrue(
       "Drools Rule was not debuged properly.\nConsole content should be:\n'Hello World\n' but is:\n"
           + consoleText,
       consoleText.equals("Hello World\n"));
   debugView.toolbarButton(IDELabel.DebugView.BUTTON_RESUME_TOOLTIP).click();
   consoleText = console.getConsoleText(3 * 1000L, 60 * 1000L, true);
   assertTrue(
       "Drools Rule was not debuged properly.\nConsole content should be:Hello World\nGoodbye cruel world\n"
           + consoleText,
       consoleText.equals("Hello World\nGoodbye cruel world\n"));
 }
  /**
   * Applies Open On (F3) on textToSelect within editor with editorTitle and checks if
   * expectedOpenedFileName was opened
   *
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @param expectedOpenedFileName
   */
  public static SWTBotEditor checkOpenOnFileIsOpened(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex,
      String expectedOpenedFileName) {

    SWTBotEclipseEditor sourceEditor =
        SWTJBTExt.selectTextInSourcePane(
            bot, editorTitle, textToSelect, selectionOffset, selectionLength, textToSelectIndex);

    bot.sleep(Timing.time3S());

    sourceEditor.setFocus();
    // process UI Events
    UIThreadRunnable.syncExec(
        new VoidResult() {
          @Override
          public void run() {}
        });
    bot.sleep(Timing.time3S());
    new SWTUtilExt(bot).waitForNonIgnoredJobs();

    KeyboardHelper.typeKeyCodeUsingAWT(KeyEvent.VK_F3);
    // process UI Events
    UIThreadRunnable.syncExec(
        new VoidResult() {
          @Override
          public void run() {}
        });
    bot.sleep(Timing.time3S());
    new SWTUtilExt(bot).waitForNonIgnoredJobs();

    return checkActiveEditorTitle(bot, expectedOpenedFileName);
  }
Exemplo n.º 6
0
  /** @throws WidgetNotFoundException */
  private void perform() throws Exception {
    Display display = e.display;
    SWTEclipseBot bot = new SWTEclipseBot();

    createJavaProject(bot);
    createJavaClass(bot);
    Thread.sleep(1000);
    SWTBotEclipseEditor editor = bot.editor("HelloWorld.java"); // $NON-NLS-1$

    Thread.sleep(1000);
    editor.notifyKeyboardEvent(SWT.CTRL, '.');
    editor.quickfix("Add unimplemented methods"); // $NON-NLS-1$

    editor.navigateTo(7, 0);
    editor.autoCompleteProposal(
        "sys", "sysout - print to standard out"); // $NON-NLS-1$ //$NON-NLS-2$

    editor.typeText("\"Hello World\""); // $NON-NLS-1$

    editor.navigateTo(3, 0);
    editor.autoCompleteProposal("main", "main - main method"); // $NON-NLS-1$ //$NON-NLS-2$

    editor.typeText("new Thread (new HelloWorld ());"); // $NON-NLS-1$
    if (true) return;
    editor.notifyKeyboardEvent(SWT.CTRL, '2');
    editor.notifyKeyboardEvent(SWT.NONE, 'L');
    editor.notifyKeyboardEvent(SWT.NONE, '\n');

    editor.typeText("\n"); // $NON-NLS-1$
    editor.typeText("thread.start();\n"); // $NON-NLS-1$
    editor.typeText("thread.join();"); // $NON-NLS-1$
    editor.quickfix("Add throws declaration"); // $NON-NLS-1$
    editor.notifyKeyboardEvent(SWT.NONE, (char) 27);
    editor.notifyKeyboardEvent(SWT.NONE, '\n');

    editor.notifyKeyboardEvent(SWT.CTRL, 's');

    editor.notifyKeyboardEvent(SWT.ALT | SWT.SHIFT, 'x');
    editor.notifyKeyboardEvent(SWT.NONE, 'j');

    try {
      Thread.sleep(1000);
    } catch (InterruptedException e1) {
      e1.printStackTrace();
    }
  }
 @Override
 public boolean test() throws Exception {
   lastPostion = editor.cursorPosition();
   boolean equals = desiredPosition.equals(lastPostion);
   return equals;
 }