/**
   * Checks Content Assist content on specified position within editor with editorTitle and checks
   * if expectedProposalList is equal to current Proposal List
   *
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @param expectedProposalList
   * @param mustEquals
   */
  public static SWTBotEditor checkContentAssistContent(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex,
      List<String> expectedProposalList,
      boolean mustEquals) {

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

    bot.sleep(Timing.time1S());

    SWTBotEditorExt editor = SWTTestExt.bot.swtBotEditorExtByTitle(editorTitle);
    ContentAssistBot contentAssist = editor.contentAssist();
    List<String> currentProposalList = contentAssist.getProposalList();
    assertTrue(
        "Code Assist menu has incorrect menu items.\n"
            + "Expected Proposal Menu Labels vs. Current Proposal Menu Labels :\n"
            + FormatUtils.getListsDiffFormatted(expectedProposalList, currentProposalList),
        mustEquals
            ? expectedProposalList.equals(currentProposalList)
            : currentProposalList.containsAll(expectedProposalList));

    return editor;
  }
  /**
   * Checks Content Assist auto proposal. It's case when there is only one content assist item and
   * that item is automatically inserted into editor and checks if expectedProposalList is equal to
   * current Proposal List
   *
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   * @param expectedInsertedText
   */
  public static SWTBotEditor checkContentAssistAutoProposal(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex,
      String expectedInsertedText) {

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

    bot.sleep(Timing.time1S());

    SWTBotEditorExt editor = SWTTestExt.bot.swtBotEditorExtByTitle(editorTitle);
    String editorLineBeforeInsert = editor.getTextOnCurrentLine();
    int xPos = editor.cursorPosition().column;
    String expectedEditorLineAfterInsert =
        editorLineBeforeInsert.substring(0, xPos)
            + expectedInsertedText
            + editorLineBeforeInsert.substring(xPos);
    ContentAssistBot contentAssist = editor.contentAssist();
    contentAssist.invokeContentAssist();
    String editorLineAfterInsert = editor.getTextOnCurrentLine();
    assertTrue(
        "Text on current line should be:\n"
            + expectedEditorLineAfterInsert
            + "\nbut is:\n"
            + editorLineAfterInsert,
        editorLineAfterInsert.equals(expectedEditorLineAfterInsert));

    return editor;
  }
  /**
   * Applies Content Assist auto proposal. It's case when there is only one content assist item and
   * that item is automatically inserted into editor
   *
   * @param editorTitle
   * @param textToSelect
   * @param selectionOffset
   * @param selectionLength
   * @param textToSelectIndex
   */
  public static SWTBotEditor applyContentAssistAutoProposal(
      SWTBotExt bot,
      String editorTitle,
      String textToSelect,
      int selectionOffset,
      int selectionLength,
      int textToSelectIndex) {

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

    bot.sleep(Timing.time1S());

    SWTBotEditorExt editor = SWTTestExt.bot.swtBotEditorExtByTitle(editorTitle);
    ContentAssistBot contentAssist = editor.contentAssist();
    contentAssist.invokeContentAssist();

    return editor;
  }
  /**
   * Creates Drools Rule and checks result
   *
   * @param droolsRuletName
   */
  private void createDroolsRule(String droolsRuleName) {

    packageExplorer.show();
    SWTBotTreeItem tiDroolsRules =
        packageExplorer.selectTreeItem(
            DroolsAllBotTests.SRC_MAIN_RULES_TREE_NODE,
            new String[] {DroolsAllBotTests.DROOLS_PROJECT_NAME});

    tiDroolsRules.select();
    eclipse.createNew(EntityType.DROOLS_RULE);

    bot.textWithLabel(IDELabel.NewDroolsRuleDialog.FILE_NAME).setText(droolsRuleName);
    bot.textWithLabel(IDELabel.NewDroolsRuleDialog.RULE_PACKAGE_NAME)
        .setText(DroolsAllBotTests.COM_SAMPLE_TREE_NODE);
    bot.button(IDELabel.Button.FINISH).click();
    bot.sleep(Timing.time1S());
    tiDroolsRules.expand();
    // Test if new Drools Rule is within package tree view
    boolean isRuleCreated = true;
    try {
      tiDroolsRules.getNode(droolsRuleName);
    } catch (WidgetNotFoundException wnfe) {
      isRuleCreated = false;
    }
    assertTrue(
        "New Drools Rule was not created properly. It's not present within Package Explorer",
        isRuleCreated);
    // Test if new Drools Rule is opened in editor
    isRuleCreated = true;
    try {
      bot.editorByTitle(droolsRuleName);
    } catch (WidgetNotFoundException wnfe) {
      isRuleCreated = false;
    }
    assertTrue(
        "New Drools Rule was not created properly. File "
            + droolsRuleName
            + " is not opened in editor",
        isRuleCreated);
  }