org.assertj.swing.driver
Class AbstractJTableCellWriter

java.lang.Object
  extended by org.assertj.swing.driver.AbstractJTableCellWriter
All Implemented Interfaces:
JTableCellWriter
Direct Known Subclasses:
BasicJTableCellWriter, JTableCheckBoxEditorCellWriter, JTableComboBoxEditorCellWriter, JTableTextComponentEditorCellWriter

public abstract class AbstractJTableCellWriter
extends Object
implements JTableCellWriter

Template for implementations of JTableCellWriter.

Author:
Alex Ruiz, Yvonne Wang

Field Summary
protected  Robot robot
           
 
Constructor Summary
AbstractJTableCellWriter(Robot robot)
           
 
Method Summary
 void cancelCellEditing(JTable table, int row, int column)
          Cancels editing the given cell of the JTable.
protected static ActionFailedException cannotFindOrActivateEditor(int row, int column)
          Throws a ActionFailedException if this JTableCellWriter could not find or activate the cell editor of the supported type.
protected  TableCellEditor cellEditor()
           
protected static TableCellEditor cellEditor(JTable table, int row, int column)
          Returns the editor for the given JTable cell.
protected  void cellEditor(TableCellEditor newCellEditor)
          Sets the cell editor being currently used.
protected static Point cellLocation(JTable table, int row, int column, JTableLocation location)
          Returns the location of the given table cell.
protected static
<T extends Component>
T
editor(JTable table, int row, int column, Class<T> supportedType)
           Finds the AWT or Swing Component used as editor for the given JTable.
 Component editorForCell(JTable table, int row, int column)
           Returns the AWT or Swing Component used as editor of the given cell.
protected  JTableLocation location()
           
protected static void scrollToCell(JTable table, int row, int column, JTableLocation location)
           Scrolls the given JTable to the given cell.
 void stopCellEditing(JTable table, int row, int column)
          Stops editing the given cell of the JTable.
protected static void validate(JTable table, int row, int column)
           Validates that: the given JTable is enabled and showing on the screen the row and column indices are correct (not out of bounds) the table cell at the given indices is editable
protected
<T extends Component>
T
waitForEditorActivation(ComponentMatcher matcher, JTable table, int row, int column, Class<T> supportedType)
          Waits until the editor of the given table cell is showing on the screen.
protected
<T extends Component>
T
waitForEditorActivation(JTable table, int row, int column, Class<T> supportedType)
          Waits until the editor of the given table cell is showing on the screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.assertj.swing.cell.JTableCellWriter
enterValue, startCellEditing
 

Field Detail

robot

protected final Robot robot
Constructor Detail

AbstractJTableCellWriter

public AbstractJTableCellWriter(@Nonnull
                                Robot robot)
Method Detail

cancelCellEditing

@RunsInEDT
public void cancelCellEditing(@Nonnull
                                        JTable table,
                                        int row,
                                        int column)
Description copied from interface: JTableCellWriter
Cancels editing the given cell of the JTable. This method should be called after manipulating the AWT or Swing Component returned by @link #editorForCell(JTable, int, int)}.

Specified by:
cancelCellEditing in interface JTableCellWriter
Parameters:
table - the target JTable.
row - the row index of the cell.
column - the column index of the cell.
See Also:
JTableCellWriter.editorForCell(JTable, int, int)

stopCellEditing

@RunsInEDT
public void stopCellEditing(@Nonnull
                                      JTable table,
                                      int row,
                                      int column)
Description copied from interface: JTableCellWriter
Stops editing the given cell of the JTable. This method should be called after manipulating the AWT or Swing Component returned by JTableCellWriter.editorForCell(JTable, int, int).

Specified by:
stopCellEditing in interface JTableCellWriter
Parameters:
table - the target JTable.
row - the row index of the cell.
column - the column index of the cell.
See Also:
JTableCellWriter.editorForCell(JTable, int, int)

cellEditor

@RunsInEDT
@Nullable
protected static TableCellEditor cellEditor(@Nonnull
                                                               JTable table,
                                                               int row,
                                                               int column)
Returns the editor for the given JTable cell. This method is executed in the EDT.

Parameters:
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
Returns:
the editor for the given JTable cell.

scrollToCell

@RunsInCurrentThread
protected static void scrollToCell(JTable table,
                                                       int row,
                                                       int column,
                                                       JTableLocation location)

Scrolls the given JTable to the given cell.

Note: This method is accessed in the current executing thread. Such thread may or may not be the event dispatch thread (EDT.) Client code must call this method from the EDT.

Parameters:
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
location - obtains the bounds of the given cell.

editorForCell

@RunsInEDT
@Nullable
public Component editorForCell(@Nonnull
                                                  JTable table,
                                                  int row,
                                                  int column)
Description copied from interface: JTableCellWriter

Returns the AWT or Swing Component used as editor of the given cell. To manipulate the returned Component, JTableCellWriter.startCellEditing(JTable, int, int) should be called first.

Example:

 Component editor = writer.editorForCell(table, 6, 8);
 // assume editor is a JTextField
 JTextComponentFixture editorFixture = new JTextComponentFixture(robot, (JTextField) editor);
 writer.startCellEditing(table, 6, 8);
 editorFixture.enterText("Hello");
 writer.stopCellEditing(table, 6, 8);
 

Specified by:
editorForCell in interface JTableCellWriter
Parameters:
table - the target JTable.
row - the row index of the cell.
column - the column index of the cell.
Returns:
the Component used as editor of the given cell.

editor

@RunsInCurrentThread
@Nonnull
protected static <T extends Component> T editor(@Nonnull
                                                                            JTable table,
                                                                            int row,
                                                                            int column,
                                                                            @Nonnull
                                                                            Class<T> supportedType)

Finds the AWT or Swing Component used as editor for the given JTable.

Note: This method is accessed in the current executing thread. Such thread may or may not be the event dispatch thread (EDT.) Client code must call this method from the EDT.

Parameters:
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
supportedType - the type of component we expect as editor.
Returns:
the component used as editor for the given table cell.
Throws:
IndexOutOfBoundsException - if any of the indices is out of bounds or if the JTable does not have any rows.
IllegalStateException - if the JTable is disabled.
IllegalStateException - if the JTable is not showing on the screen.
IllegalStateException - if the table cell in the given coordinates is not editable.
IndexOutOfBoundsException - if any of the indices is out of bounds or if the JTable does not have any rows.
ActionFailedException - if an editor for the given cell cannot be found or cannot be activated.

cellLocation

@RunsInEDT
@Nonnull
protected static Point cellLocation(@Nonnull
                                                      JTable table,
                                                      int row,
                                                      int column,
                                                      @Nonnull
                                                      JTableLocation location)
Returns the location of the given table cell.

Parameters:
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
location - knows how to get the location of a table cell.
Returns:
the location of the given table cell.
Throws:
IllegalStateException - if the JTable is disabled.
IllegalStateException - if the JTable is not showing on the screen.
IndexOutOfBoundsException - if any of the indices is out of bounds or if the JTable does not have any rows.
IllegalStateException - if the table cell in the given coordinates is not editable.

validate

@RunsInCurrentThread
protected static void validate(@Nonnull
                                                   JTable table,
                                                   int row,
                                                   int column)

Validates that:

  1. the given JTable is enabled and showing on the screen
  2. the row and column indices are correct (not out of bounds)
  3. the table cell at the given indices is editable

Note: This method is accessed in the current executing thread. Such thread may or may not be the event dispatch thread (EDT.) Client code must call this method from the EDT.

Parameters:
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
Throws:
IllegalStateException - if the JTable is disabled.
IllegalStateException - if the JTable is not showing on the screen.
IndexOutOfBoundsException - if any of the indices is out of bounds or if the JTable does not have any rows.
IllegalStateException - if the table cell in the given coordinates is not editable.

waitForEditorActivation

@RunsInEDT
@Nullable
protected final <T extends Component> T waitForEditorActivation(@Nonnull
                                                                                   JTable table,
                                                                                   int row,
                                                                                   int column,
                                                                                   @Nonnull
                                                                                   Class<T> supportedType)
Waits until the editor of the given table cell is showing on the screen. Component lookup is performed by type.

Parameters:
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
supportedType - the type of component we expect as editor.
Returns:
the editor of the given table cell once it is showing on the screen.
Throws:
ActionFailedException - if an editor for the given cell cannot be found or cannot be activated.

waitForEditorActivation

@RunsInEDT
@Nullable
protected final <T extends Component> T waitForEditorActivation(@Nonnull
                                                                                   ComponentMatcher matcher,
                                                                                   @Nonnull
                                                                                   JTable table,
                                                                                   int row,
                                                                                   int column,
                                                                                   @Nonnull
                                                                                   Class<T> supportedType)
Waits until the editor of the given table cell is showing on the screen.

Parameters:
matcher - the condition that the cell editor to look for needs to satisfy.
table - the given JTable.
row - the row index of the cell.
column - the column index of the cell.
supportedType - the type of component we expect as editor.
Returns:
the editor of the given table cell once it is showing on the screen.
Throws:
ActionFailedException - if an editor for the given cell cannot be found or cannot be activated.

cannotFindOrActivateEditor

@Nonnull
protected static ActionFailedException cannotFindOrActivateEditor(int row,
                                                                          int column)
Throws a ActionFailedException if this JTableCellWriter could not find or activate the cell editor of the supported type.

Parameters:
row - the row index of the cell.
column - the column index of the cell.
Returns:
the thrown exception.

cellEditor

@Nullable
protected final TableCellEditor cellEditor()
Returns:
the cell editor being currently used, or null if no table cell is being currently edited.

cellEditor

protected final void cellEditor(@Nullable
                                TableCellEditor newCellEditor)
Sets the cell editor being currently used.

Parameters:
newCellEditor - the cell editor being currently used.

location

@Nonnull
protected final JTableLocation location()


Copyright © 2014–2015 AssertJ. All rights reserved.