private boolean findRowByCriteria(JTableFixture tFixture, TableCommandRequest tcommand, int i, int totalFound) { for(TableCommandRequestQueryCriteria criterion: tcommand.query.criteria){ JTableCellFixture cell = tFixture.cell(TableCellByColumnId.row(i).columnId(criterion.lookupCol)); if (cell.value().equals(criterion.lookupValue)) { totalFound++; } if(totalFound == tcommand.query.criteria.size()){ return true; } } return false; }
/** * Get table row count * * @throws VerificationException if the table element doesn't exist */ @Override @PublicAtsApi public int getRowCount() { new SwingElementState(this).waitToBecomeExisting(); return ((JTableFixture) SwingElementLocator.findFixture(this)).rowCount(); }
@Override protected Integer executeInEDT() throws Throwable { return tableFixture.component().getColumnCount(); }
private String handle(JTable target, final TableCommandRequest command) { JTableFixture tFixture = new JTableFixture(rbt, (JTable) target); switch (command.action) { case COUNT: int tries = 30; while (tFixture.rowCount() == 0 && tries > 0) { try { tries--; return String.valueOf(tFixture.rowCount()); case FIND: TableCommandRequest tcommand = (TableCommandRequest) command; for (int i = 0; i < tFixture.rowCount(); i++) { JTableCellFixture cell = tFixture.cell(TableCellByColumnId.row(i).columnId(tcommand.query.lookupCol)); if (cell.value().equals(command.value)) { JTableCellFixture cell2 = tFixture.cell(TableCellByColumnId.row(i).columnId(tcommand.query.resultCol)); String value = cell2.value(); cell2.select(); case DOUBLE_CLICK: tcommand = (TableCommandRequest) command; for (int i = 0; i < tFixture.rowCount(); i++) { JTableCellFixture cell = tFixture.cell(TableCellByColumnId.row(i).columnId(tcommand.query.lookupCol)); if (cell.value().equals(command.value)) { cell.select(); case SELECT_MENU: tcommand = (TableCommandRequest) command; for (int i = 0; i < tFixture.rowCount(); i++) { JTableCellFixture cell = tFixture.cell(TableCellByColumnId.row(i).columnId(tcommand.query.lookupCol));
/** * Gets table cell backgrounds (as {@link Color}) of all table cells. * * @return array of java.awt.Color objects one for each cell. First index is * table row and second is the column in this row. */ @PublicAtsApi public Color[][] getCellBackgroundColors() { new SwingElementState(this).waitToBecomeExisting(); final JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); int rowCount = tableFixture.rowCount(); // SwingUtilities. int columnCount = GuiActionRunner.execute(new GuiQuery<Integer>() { @Override protected Integer executeInEDT() throws Throwable { return tableFixture.component().getColumnCount(); } }); Color[][] resultArr = new Color[rowCount][columnCount]; for (int i = 0; i < rowCount; i++) { for (int j = 0; j < columnCount; j++) { resultArr[i][j] = tableFixture.backgroundAt(new TableCell(i, j) {}).target(); } } return resultArr; }
/** * Set table field value * * @param value the value to set * @param row the row number * @param column the column number * @throws VerificationException if the element doesn't exist */ @Override @PublicAtsApi public void setFieldValue( String value, int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); try { TableCell tableCell = new TableCell(row, column) {}; tableFixture.selectCell(tableCell); // if the cell coordinates are wrong, the exception will be thrown if (tableFixture.component().isCellEditable(row, column)) { tableFixture.enterValue(tableCell, value); } else { throw new NotSupportedOperationException("The table cell [" + row + "," + column + "] is not editable. " + toString()); } } catch (IndexOutOfBoundsException ioobe) { throw new UiElementException(ioobe.getMessage(), this); } }
} else if (componentClass.equals(JTable.class)) { return (ComponentFixture<? extends Component>) new JTableFixture(containerFixture.robot, (JTable) findElement(uiElement)); } else if (componentClass.equals(JSpinner.class)) {
/** * Simulates a user dropping an item into a specific table cell * * @param row the row number * @param column the column number */ @PublicAtsApi public void drop( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); ((JTableFixture) SwingElementLocator.findFixture(this)).drop(new TableCell(row, column) {}); }
/** * Simulates a user dragging a cell from this table * * @param row the row number * @param column the column number */ @PublicAtsApi public void drag( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); ((JTableFixture) SwingElementLocator.findFixture(this)).drag(new TableCell(row, column) {}); }
/** * Returns the table cell background {@link Color} * * @param row the row number * @param column the column number */ @PublicAtsApi public Color getCellBackgroundColor( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); return tableFixture.backgroundAt(new TableCell(row, column) {}).target(); }
/** * Returns the table cell foreground {@link Color} * * @param row the row number * @param column the column number */ @PublicAtsApi public Color getCellForegroundColor( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); return tableFixture.foregroundAt(new TableCell(row, column) {}).target(); }
private String handle(JTable target, final TableCommandRequest command) { JTableFixture tFixture = new JTableFixture(FestRobotInstance.getRobot(), (JTable) target); switch (command.action) { case COUNT: int tries = 30; while (tFixture.rowCount() == 0 && tries > 0) { try { tries--; return String.valueOf(tFixture.rowCount()); case FIND: TableCommandRequest tcommand = (TableCommandRequest) command; if(tFixture.rowCount() == 0){ return "The table is empty !"; for (int i = 0; i < tFixture.rowCount(); i++) { int totalFound = 0; boolean found = findRowByCriteria(tFixture, tcommand, i, totalFound); if(found){ if(tcommand.query.resultCol != null){ JTableCellFixture cell = tFixture.cell(TableCellByColumnId.row(i).columnId(tcommand.query.resultCol)); cell.select(); return cell.value(); case DOUBLE_CLICK: tcommand = (TableCommandRequest) command; for (int i = 0; i < tFixture.rowCount(); i++) { int totalFound = 0; boolean found = findRowByCriteria(tFixture, tcommand, i, totalFound);
/** * Double click table cell * * @param row the row number * @param column the column number * @throws VerificationException if the element doesn't exist */ @PublicAtsApi public void doubleClickCell( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); try { tableFixture.cell(new TableCell(row, column) {}).doubleClick(); } catch (Exception e) { throw new UiElementException(e.getMessage(), this); } }
/** * Get selected rows in the table * * @return an array with the selected rows * @throws VerificationException if the table element doesn't exist */ @PublicAtsApi public int[] getSelectedRows() { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); try { return tableFixture.component().getSelectedRows(); } catch (Exception e) { throw new UiElementException(e.getMessage(), this); } }
/** * Right click on table cell * * @param row the row number * @param column the column number * @throws VerificationException if the table element doesn't exist */ @PublicAtsApi public void rightClickCell( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); try { tableFixture.cell(new TableCell(row, column) {}).rightClick(); } catch (Exception e) { throw new UiElementException(e.getMessage(), this); } }
/** * Click table cell * * @param row the row number * @param column the column number * @throws VerificationException if the table element doesn't exist */ @PublicAtsApi public void clickCell( int row, int column ) { new SwingElementState(this).waitToBecomeExisting(); JTableFixture tableFixture = (JTableFixture) SwingElementLocator.findFixture(this); try { tableFixture.cell(new TableCell(row, column) {}).click(); } catch (Exception e) { throw new UiElementException(e.getMessage(), this); } }