org.uispec4j
Class Table

java.lang.Object
  extended by org.uispec4j.AbstractUIComponent
      extended by org.uispec4j.AbstractSwingUIComponent
          extended by org.uispec4j.Table
All Implemented Interfaces:
TooltipComponent, UIComponent

public class Table
extends AbstractSwingUIComponent

Wrapper for JTable components.

The contents of the underlying table can be usually checked with String or Boolean values, as in the following example:


 assertTrue(table.contentEquals(new String[]{
   {"Bart", "Simpson"},
   {"Marge", "Simpson"}
 }));
 
The conversion between the values (Strings) given in the test and the values actually displayed by the table renderer is performed by a dedicated TableCellValueConverter, which retrieves the graphical component that draws the table cells and determines the displayed value accordingly. A DefaultTableCellValueConverter is used by default by the Table component.


Nested Class Summary
 class Table.Cell
          Represents a table cell.
 class Table.Header
           
 
Field Summary
static java.lang.Class[] SWING_CLASSES
           
static java.lang.String TYPE_NAME
           
 
Constructor Summary
Table(javax.swing.JTable table)
           
 
Method Summary
 void addRowToSelection(int row)
           
 Assertion backgroundEquals(java.lang.Object[][] colors)
          Checks the background color of the table cells using either Color or String objects
 Assertion backgroundNear(int row, int column, java.lang.Object expected)
           
 Assertion blockEquals(int fromRowIndex, int fromColumnIndex, int columnCount, int rowCount, java.lang.Object[][] expected)
           
 Assertion borderEquals(javax.swing.border.Border[][] borders)
           
 Assertion cellEquals(int row, int column, java.lang.Object expectedValue)
          Checks the contents of a given cell.
 Assertion cellEquals(int row, int column, java.lang.Object expectedValue, TableCellValueConverter converter)
          Checks the contents of a given cell using a specific data converter.
 Assertion cellIsEditable(int rowIndex, int columnIndex)
           
 Assertion cellIsSelected(int rowIndex, int columnIndex)
           
 void clearSelection()
           
 void click(int row, int column)
           
 void click(int row, int column, Key.Modifier modifier)
           
 Assertion columnCountEquals(int count)
           
 Assertion columnEquals(int columnIndex, java.lang.Object[] expectedColumn)
           
 Assertion columnIsEditable(int columnIndex, boolean isEditable)
           
 Assertion columnIsEditable(java.lang.String columnName, boolean shouldBeEditable)
           
 Assertion columnSizeEquals(int columnIndex, int expectedWidth)
           
 Assertion columnSizeEquals(java.lang.String columnName, int expectedWidth)
           
 Assertion containsRow(int columnIndex, java.lang.Object cellContent)
          Checks that the table contains a row with a given cell.
 Assertion containsRow(java.lang.Object[] expectedRow)
          Checks that the table contains a complete row.
 Assertion contentEquals(java.lang.Object[][] expected)
          Checks the values displayed in the table.

Sample usage:

 Assertion contentEquals(java.lang.String[] columnNames, java.lang.Object[][] expected)
          Checks the values displayed in the table for a given set of columns.
 void doubleClick(int row, int column)
           
 Table.Cell editCell(int row, int column)
          Returns a Table.Cell object for interacting with the content of an individual table cell.

Sample usage:

 void editCell(int row, int column, java.lang.String value, boolean validateChange)
          Inputs some text in a given cell.

This method only works when the underlying editor is a JTextField or a JComboBox - it will throw an exception if this is not the case, or if the cell is not editable.

 Assertion endsWith(java.lang.Object[][] expectedEndRows)
          Asserts that the contents of the table ends with the specified rows.
 Assertion foregroundEquals(java.lang.Object[][] colors)
          Checks the foreground color of the table cells using either Color or String objects
 Assertion foregroundNear(int row, int column, java.lang.Object expected)
           
 javax.swing.JTable getAwtComponent()
          Returns the Java GUI component represented by this object.
 int getColumnCount()
           
 int getColumnIndex(java.lang.String columnName)
           
 java.lang.Object getContentAt(int row, int column)
          Returns the object (String or Boolean) displayed in a given cell.

The returned object is that returned by the current TableCellValueConverter used by the table.

 java.lang.Object getContentAt(int row, int column, TableCellValueConverter converter)
          Returns the value displayed in a given cell using a specific converter.
 java.lang.String getDescriptionTypeName()
          Returns the name of the component as it will appear in the XML representation returned by UIComponent.getDescription().
 Table.Header getHeader()
          Returns a helper interface which gives access to the table header.
 javax.swing.JTable getJTable()
           
 int getRowCount()
           
 int getRowIndex(int column, java.lang.Object value)
           
 int[] getRowIndices(int column, java.lang.Object value)
           
 java.awt.Component getSwingEditorComponentAt(int row, int column)
           
 java.awt.Component getSwingRendererComponentAt(int row, int column)
           
 Assertion hasHeader()
          Checks whether a header is displayed for this table.
 Assertion isEditable(boolean[][] expected)
           
 Assertion isEmpty()
           
 void removeRowFromSelection(int row)
           
 void resizeColumn(java.lang.String columnName, int width)
           
 void rightClick(int row, int column)
           
 Assertion rowCountEquals(int count)
           
 Assertion rowEquals(int rowIndex, int fromColumnIndex, int columnCount, java.lang.Object[] expectedRow)
           
 Assertion rowEquals(int rowIndex, java.lang.Object[] expectedRow)
           
 Assertion rowEquals(int rowIndex, java.lang.String[] columnNames, java.lang.Object[] expected)
           
 Assertion rowIsSelected(int rowIndex)
           
 Assertion rowsAreSelected(int... rowIndexes)
           
 void selectAllRows()
           
 void selectBlock(int top, int left, int bottom, int right)
           
 void selectCell(int row, int column)
           
 Assertion selectionEquals(boolean[][] expected)
          Checks the selection on a cell-by-cell basis.
 Assertion selectionIsEmpty()
           
 void selectRow(int row)
           
 void selectRows(int... rowIndexes)
           
 void selectRowSpan(int start, int end)
           
 void selectRowsWithText(int column, java.lang.String... labels)
          Selects all rows where the content of the given column is one of the given labels.
 void setCellValueConverter(int column, TableCellValueConverter tableCellValueConverter)
          Sets a new converter for analyzing the cells of a given column.
 void setDefaultCellValueConverter(TableCellValueConverter cellValueConverter)
          Sets a new converter for analyzing the table cells content.
 Assertion startsWith(java.lang.Object[][] expectedFirstRows)
          Asserts that the contents of the table starts with the specified rows.
 java.lang.String toString()
           
 Trigger triggerClick(int row, int column, Key.Modifier modifier)
           
 Trigger triggerDoubleClick(int row, int column)
           
 Trigger triggerRightClick(int row, int column)
           
 
Methods inherited from class org.uispec4j.AbstractSwingUIComponent
tooltipContains, tooltipEquals
 
Methods inherited from class org.uispec4j.AbstractUIComponent
addAttributes, backgroundEquals, backgroundNear, foregroundEquals, foregroundNear, getContainer, getContainer, getDescription, getDescription, getLabel, getName, getSubDescription, isEnabled, isVisible, pressKey, releaseKey, typeKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_NAME

public static final java.lang.String TYPE_NAME
See Also:
Constant Field Values

SWING_CLASSES

public static final java.lang.Class[] SWING_CLASSES
Constructor Detail

Table

public Table(javax.swing.JTable table)
Method Detail

getDescriptionTypeName

public java.lang.String getDescriptionTypeName()
Description copied from interface: UIComponent
Returns the name of the component as it will appear in the XML representation returned by UIComponent.getDescription().


getAwtComponent

public javax.swing.JTable getAwtComponent()
Description copied from interface: UIComponent
Returns the Java GUI component represented by this object.

Specified by:
getAwtComponent in interface UIComponent
Specified by:
getAwtComponent in class AbstractSwingUIComponent

getJTable

public javax.swing.JTable getJTable()

getHeader

public Table.Header getHeader()
Returns a helper interface which gives access to the table header.


setDefaultCellValueConverter

public void setDefaultCellValueConverter(TableCellValueConverter cellValueConverter)
Sets a new converter for analyzing the table cells content.


setCellValueConverter

public void setCellValueConverter(int column,
                                  TableCellValueConverter tableCellValueConverter)
Sets a new converter for analyzing the cells of a given column.


click

public void click(int row,
                  int column)

click

public void click(int row,
                  int column,
                  Key.Modifier modifier)

rightClick

public void rightClick(int row,
                       int column)

doubleClick

public void doubleClick(int row,
                        int column)

triggerClick

public Trigger triggerClick(int row,
                            int column,
                            Key.Modifier modifier)

triggerRightClick

public Trigger triggerRightClick(int row,
                                 int column)

triggerDoubleClick

public Trigger triggerDoubleClick(int row,
                                  int column)

getRowCount

public int getRowCount()

rowCountEquals

public Assertion rowCountEquals(int count)

getColumnCount

public int getColumnCount()

columnCountEquals

public Assertion columnCountEquals(int count)

getContentAt

public java.lang.Object getContentAt(int row,
                                     int column)
Returns the object (String or Boolean) displayed in a given cell.

The returned object is that returned by the current TableCellValueConverter used by the table.

See Also:
setCellValueConverter(int,TableCellValueConverter), setDefaultCellValueConverter(TableCellValueConverter)

getContentAt

public java.lang.Object getContentAt(int row,
                                     int column,
                                     TableCellValueConverter converter)
Returns the value displayed in a given cell using a specific converter.


editCell

public Table.Cell editCell(int row,
                           int column)
Returns a Table.Cell object for interacting with the content of an individual table cell.

Sample usage:


 ComboBox comboBox = table.editCell(0, 0).getComboBox();
 assertTrue(comboBox.contentEquals(choices));
 comboBox.select("b");
 


getRowIndex

public int getRowIndex(int column,
                       java.lang.Object value)

getRowIndices

public int[] getRowIndices(int column,
                           java.lang.Object value)

editCell

public void editCell(int row,
                     int column,
                     java.lang.String value,
                     boolean validateChange)
Inputs some text in a given cell.

This method only works when the underlying editor is a JTextField or a JComboBox - it will throw an exception if this is not the case, or if the cell is not editable. Please refer to editCell(int,int) for a more flexible edition method.


hasHeader

public Assertion hasHeader()
Checks whether a header is displayed for this table.


contentEquals

public Assertion contentEquals(java.lang.Object[][] expected)
Checks the values displayed in the table.

Sample usage:


 assertTrue(table.contentEquals(new Object[][]{
   {"a", Boolean.TRUE, "3"},
   {"c", Boolean.FALSE, "4"}
 }));
 
The conversion between the displayed values and the objects to be given in the array can be customized with setCellValueConverter(int,TableCellValueConverter)


blockEquals

public Assertion blockEquals(int fromRowIndex,
                             int fromColumnIndex,
                             int columnCount,
                             int rowCount,
                             java.lang.Object[][] expected)

contentEquals

public Assertion contentEquals(java.lang.String[] columnNames,
                               java.lang.Object[][] expected)
Checks the values displayed in the table for a given set of columns.

See Also:
contentEquals(Object[][])

cellEquals

public Assertion cellEquals(int row,
                            int column,
                            java.lang.Object expectedValue)
Checks the contents of a given cell. The conversion between the displayed values and the objects provided in this method can be customized with setCellValueConverter(int,TableCellValueConverter)

See Also:
getContentAt(int,int)

cellEquals

public Assertion cellEquals(int row,
                            int column,
                            java.lang.Object expectedValue,
                            TableCellValueConverter converter)
Checks the contents of a given cell using a specific data converter. The conversion between the displayed values and the objects provided in this method can be customized with setCellValueConverter(int,TableCellValueConverter)

See Also:
getContentAt(int,int,TableCellValueConverter)

rowEquals

public Assertion rowEquals(int rowIndex,
                           java.lang.Object[] expectedRow)

rowEquals

public Assertion rowEquals(int rowIndex,
                           int fromColumnIndex,
                           int columnCount,
                           java.lang.Object[] expectedRow)

rowEquals

public Assertion rowEquals(int rowIndex,
                           java.lang.String[] columnNames,
                           java.lang.Object[] expected)

columnEquals

public Assertion columnEquals(int columnIndex,
                              java.lang.Object[] expectedColumn)

isEmpty

public Assertion isEmpty()

foregroundEquals

public Assertion foregroundEquals(java.lang.Object[][] colors)
Checks the foreground color of the table cells using either Color or String objects

See Also:
Using colors

foregroundNear

public Assertion foregroundNear(int row,
                                int column,
                                java.lang.Object expected)

backgroundNear

public Assertion backgroundNear(int row,
                                int column,
                                java.lang.Object expected)

backgroundEquals

public Assertion backgroundEquals(java.lang.Object[][] colors)
Checks the background color of the table cells using either Color or String objects

See Also:
Using colors

borderEquals

public Assertion borderEquals(javax.swing.border.Border[][] borders)

getColumnIndex

public int getColumnIndex(java.lang.String columnName)

isEditable

public Assertion isEditable(boolean[][] expected)

columnIsEditable

public Assertion columnIsEditable(int columnIndex,
                                  boolean isEditable)

cellIsEditable

public Assertion cellIsEditable(int rowIndex,
                                int columnIndex)

columnIsEditable

public Assertion columnIsEditable(java.lang.String columnName,
                                  boolean shouldBeEditable)

selectionIsEmpty

public Assertion selectionIsEmpty()

selectionEquals

public Assertion selectionEquals(boolean[][] expected)
Checks the selection on a cell-by-cell basis.


rowIsSelected

public Assertion rowIsSelected(int rowIndex)

cellIsSelected

public Assertion cellIsSelected(int rowIndex,
                                int columnIndex)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getSwingEditorComponentAt

public java.awt.Component getSwingEditorComponentAt(int row,
                                                    int column)

getSwingRendererComponentAt

public java.awt.Component getSwingRendererComponentAt(int row,
                                                      int column)

resizeColumn

public void resizeColumn(java.lang.String columnName,
                         int width)

columnSizeEquals

public Assertion columnSizeEquals(java.lang.String columnName,
                                  int expectedWidth)

columnSizeEquals

public Assertion columnSizeEquals(int columnIndex,
                                  int expectedWidth)

rowsAreSelected

public Assertion rowsAreSelected(int... rowIndexes)

selectCell

public void selectCell(int row,
                       int column)

selectAllRows

public void selectAllRows()

selectRow

public void selectRow(int row)

selectRows

public void selectRows(int... rowIndexes)

selectRowsWithText

public void selectRowsWithText(int column,
                               java.lang.String... labels)
Selects all rows where the content of the given column is one of the given labels.


selectRowSpan

public void selectRowSpan(int start,
                          int end)

selectBlock

public void selectBlock(int top,
                        int left,
                        int bottom,
                        int right)

addRowToSelection

public void addRowToSelection(int row)

removeRowFromSelection

public void removeRowFromSelection(int row)

clearSelection

public void clearSelection()

startsWith

public Assertion startsWith(java.lang.Object[][] expectedFirstRows)
Asserts that the contents of the table starts with the specified rows. This is useful for dealing with tables with hundreds of rows, as you can just check that the first few are correct.


endsWith

public Assertion endsWith(java.lang.Object[][] expectedEndRows)
Asserts that the contents of the table ends with the specified rows. This is useful for dealing with tables with hundreds of rows, as you can just check that the last few are correct.


containsRow

public Assertion containsRow(java.lang.Object[] expectedRow)
Checks that the table contains a complete row.


containsRow

public Assertion containsRow(int columnIndex,
                             java.lang.Object cellContent)
Checks that the table contains a row with a given cell.



Copyright © 2004-2010. All Rights Reserved.