/**
   * Selects the cell of the Table.<br>
   * With the xPos, yPos, xUnits and yUnits the click position inside the cell can be defined.
   *
   * @param row The row of the cell.
   * @param rowOperator The row header operator
   * @param col The column of the cell.
   * @param colOperator The column header operator
   * @param clickCount The number of clicks with the right mouse button
   * @param xPos what x position
   * @param xUnits should x position be pixel or percent values
   * @param yPos what y position
   * @param yUnits should y position be pixel or percent values
   * @param extendSelection Should this selection be part of a multiple selection
   * @param button what mouse button should be used
   * @throws StepExecutionException If the row or the column is invalid
   */
  public void rcSelectCell(
      final String row,
      final String rowOperator,
      final String col,
      final String colOperator,
      final int clickCount,
      final int xPos,
      final String xUnits,
      final int yPos,
      final String yUnits,
      final String extendSelection,
      int button)
      throws StepExecutionException {
    TreeTableOperationContext adapter = getContext();
    final int implRow = adapter.getRowFromString(row, rowOperator);
    final int implCol = adapter.getColumnFromString(col, colOperator, implRow != -1);
    final boolean isExtendSelection = extendSelection.equals(ValueSets.BinaryChoice.yes.rcValue());
    if (log.isDebugEnabled()) {
      log.debug("Selecting row, col: " + row + ", " + col); // $NON-NLS-1$//$NON-NLS-2$
    }

    Rectangle cellBounds;
    Object source = getRealComponent();
    // if row is header and col is existing
    if (implRow == -1 && implCol > -1) {
      cellBounds = adapter.getHeaderBounds(implCol);
      source = adapter.getTableHeader();
    } else {
      cellBounds = adapter.scrollCellToVisible(implRow, implCol);
    }
    ClickOptions clickOptions = ClickOptions.create();
    clickOptions.setClickCount(clickCount).setScrollToVisible(false);
    clickOptions.setMouseButton(button);
    try {
      if (isExtendSelection) {
        getRobot().keyPress(getRealComponent(), getExtendSelectionModifier());
      }
      getRobot()
          .click(
              source,
              cellBounds,
              clickOptions,
              xPos,
              xUnits.equalsIgnoreCase(ValueSets.Unit.pixel.rcValue()),
              yPos,
              yUnits.equalsIgnoreCase(ValueSets.Unit.pixel.rcValue()));
    } finally {
      if (isExtendSelection) {
        getRobot().keyRelease(getRealComponent(), getExtendSelectionModifier());
      }
    }
  }
  /**
   * Selects a table cell in the given row and column via click in the middle of the cell.
   *
   * @param row The row of the cell.
   * @param rowOperator The row header operator
   * @param col The column of the cell.
   * @param colOperator The column header operator
   * @param co the click options to use
   * @param extendSelection Should this selection be part of a multiple selection
   */
  private void selectCell(
      final String row,
      final String rowOperator,
      final String col,
      final String colOperator,
      final ClickOptions co,
      final String extendSelection) {

    rcSelectCell(
        row,
        rowOperator,
        col,
        colOperator,
        co.getClickCount(),
        50,
        ValueSets.Unit.percent.rcValue(),
        50,
        ValueSets.Unit.percent.rcValue(),
        extendSelection,
        co.getMouseButton());
  }
  /**
   * Selects the last node of the path given by <code>indexPath</code> at column <code>column</code>
   * .
   *
   * @param pathType whether the path is relative or absolute
   * @param preAscend Relative traversals will start this many parent nodes above the current node.
   *     Absolute traversals ignore this parameter.
   * @param indexPath the index path
   * @param clickCount the number of times to click
   * @param column the column of the item to select
   * @param button what mouse button should be used
   * @throws StepExecutionException if <code>indexPath</code> is not a valid path
   */
  public void rcSelectByIndices(
      String pathType, int preAscend, String indexPath, int clickCount, int column, int button)
      throws StepExecutionException {
    final int implCol = IndexConverter.toImplementationIndex(column);
    checkColumnIndex(implCol);

    selectByPath(
        pathType,
        preAscend,
        createIndexNodePath(splitIndexTreePath(indexPath)),
        ClickOptions.create().setClickCount(clickCount).setMouseButton(button),
        implCol);
  }
 /**
  * Verifies the editable property of the given indices.
  *
  * @param editable The editable property to verify.
  * @param row the row to select
  * @param rowOperator the row header operator
  * @param col the column to select
  * @param colOperator the column header operator
  */
 public void rcVerifyEditable(
     boolean editable, String row, String rowOperator, String col, String colOperator) {
   TreeTableOperationContext context = getContext();
   if (context.getRowFromString(row, rowOperator) == -1) {
     throw new StepExecutionException(
         "Unsupported Header Action", //$NON-NLS-1$
         EventFactory.createActionError(TestErrorEvent.UNSUPPORTED_HEADER_ACTION));
   }
   selectCell(
       row,
       rowOperator,
       col,
       colOperator,
       ClickOptions.create(),
       ValueSets.BinaryChoice.no.rcValue());
   rcVerifySelectedEditable(editable);
 }
 /**
  * Finds the first row which contains the value <code>value</code> in column <code>col</code> and
  * selects this row.
  *
  * @param col the column
  * @param colOperator the column header operator
  * @param value the value
  * @param clickCount the number of clicks.
  * @param regexOp the regex operator
  * @param extendSelection Should this selection be part of a multiple selection
  * @param searchType Determines where the search begins ("relative" or "absolute")
  * @param button what mouse button should be used
  */
 public void rcSelectRowByValue(
     String col,
     String colOperator,
     final String value,
     final String regexOp,
     int clickCount,
     final String extendSelection,
     final String searchType,
     int button) {
   selectRowByValue(
       col,
       colOperator,
       value,
       regexOp,
       extendSelection,
       searchType,
       ClickOptions.create().setClickCount(clickCount).setMouseButton(button));
 }
 /**
  * Finds the first column which contains the value <code>value</code> in the given row and selects
  * the cell.
  *
  * @param row the row to select
  * @param rowOperator the row header operator
  * @param value the value
  * @param clickCount the number of clicks
  * @param regex search using regex
  * @param extendSelection Should this selection be part of a multiple selection
  * @param searchType Determines where the search begins ("relative" or "absolute")
  * @param button what mouse button should be used
  */
 public void rcSelectCellByColValue(
     String row,
     String rowOperator,
     final String value,
     final String regex,
     int clickCount,
     final String extendSelection,
     final String searchType,
     int button) {
   selectCellByColValue(
       row,
       rowOperator,
       value,
       regex,
       extendSelection,
       searchType,
       ClickOptions.create().setClickCount(clickCount).setMouseButton(button));
 }
  /**
   * Selects the item at the end of the <code>treepath</code> at column <code>column</code>.
   *
   * @param pathType whether the path is relative or absolute
   * @param preAscend Relative traversals will start this many parent nodes above the current node.
   *     Absolute traversals ignore this parameter.
   * @param treePath The tree path.
   * @param operator If regular expressions are used to match the tree path
   * @param clickCount the click count
   * @param column the column of the item to select
   * @param button what mouse button should be used
   * @throws StepExecutionException If the tree path is invalid, if the double-click to expand the
   *     node fails, or if the selection is invalid.
   */
  public void rcSelect(
      String pathType,
      int preAscend,
      String treePath,
      String operator,
      int clickCount,
      int column,
      int button)
      throws StepExecutionException {

    final int implCol = IndexConverter.toImplementationIndex(column);
    checkColumnIndex(implCol);
    selectByPath(
        pathType,
        preAscend,
        createStringNodePath(splitTextTreePath(treePath), operator),
        ClickOptions.create().setClickCount(clickCount).setMouseButton(button),
        implCol);
  }
  /**
   * Selects the last node of the path given by <code>indexPath</code> at the column given by the
   * column path
   *
   * @param pathType whether the path is relative or absolute
   * @param preAscend Relative traversals will start this many parent nodes above the current node.
   *     Absolute traversals ignore this parameter.
   * @param indexPath the index path
   * @param clickCount the number of times to click
   * @param column the column or column path of the item to select
   * @param operator for the column path
   * @param button what mouse button should be used
   * @throws StepExecutionException if <code>indexPath</code> is not a valid path
   */
  public void rcSelectByColumnPath(
      String pathType,
      int preAscend,
      String indexPath,
      int clickCount,
      String column,
      String operator,
      int button)
      throws StepExecutionException {
    final int implCol = getContext().getColumnFromString(column, operator, true);
    checkColumnIndex(implCol);

    selectByPath(
        pathType,
        preAscend,
        createIndexNodePath(splitIndexTreePath(indexPath)),
        ClickOptions.create().setClickCount(clickCount).setMouseButton(button),
        implCol);
  }
  /**
   * clicks into the active window.
   *
   * @param count amount of clicks
   * @param button what mouse button should be used
   * @param xPos what x position
   * @param xUnits should x position be pixel or percent values
   * @param yPos what y position
   * @param yUnits should y position be pixel or percent values
   * @throws StepExecutionException error
   */
  public void rcClickDirect(int count, int button, int xPos, String xUnits, int yPos, String yUnits)
      throws StepExecutionException {

    Object activeWindow = getActiveWindow();
    if (activeWindow != null) {
      getRobot()
          .click(
              activeWindow,
              null,
              ClickOptions.create()
                  .setClickCount(count)
                  .setConfirmClick(false)
                  .setMouseButton(button),
              xPos,
              xUnits.equalsIgnoreCase(ValueSets.Unit.pixel.rcValue()),
              yPos,
              yUnits.equalsIgnoreCase(ValueSets.Unit.pixel.rcValue()));
    } else {
      throw new StepExecutionException(
          "No active window.", //$NON-NLS-1$
          EventFactory.createActionError(TestErrorEvent.NO_ACTIVE_WINDOW));
    }
  }