Class AbstractJTableCellWriter

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

public abstract class AbstractJTableCellWriter extends Object implements JTableCellWriter
Understands the base class for implementations of JTableCellWriter.
  • Field Details

  • Constructor Details

    • AbstractJTableCellWriter

      public AbstractJTableCellWriter(Robot robot)
  • Method Details

    • cancelCellEditing

      @RunsInEDT public void cancelCellEditing(JTable table, int row, int column)
      Cancels editing the given cell of the JTable. This method should be called after manipulating the Component returned by JTableCellWriter.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:
    • doCancelCellEditing

      @RunsInEDT private void doCancelCellEditing(JTable table, int row, int column)
    • doCancelCellEditing

      @RunsInEDT private void doCancelCellEditing()
    • stopCellEditing

      @RunsInEDT public void stopCellEditing(JTable table, int row, int column)
      Stops editing the given cell of the JTable. This method should be called after manipulating the 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:
    • doStopCellEditing

      @RunsInEDT private void doStopCellEditing(JTable table, int row, int column)
    • doStopCellEditing

      @RunsInEDT private void doStopCellEditing()
    • cellEditor

      @RunsInEDT protected static TableCellEditor cellEditor(JTable table, int row, int column)
      Returns the editor for the given table cell. This method is executed in the EDT.
      Parameters:
      table - the target JTable.
      row - the row index of the cell.
      column - the column index of the cell.
      Returns:
      the editor for the given table 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 not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Parameters:
      table - the target JTable.
      row - the row index of the cell.
      column - the column index of the cell.
      location - understands how to get the bounds of the given cell.
    • editorForCell

      @RunsInEDT public Component editorForCell(JTable table, int row, int column)
      Returns the 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.
    • cellEditorComponent

      @RunsInEDT private static Component cellEditorComponent(JTable table, int row, int column)
    • editor

      @RunsInCurrentThread protected static <T extends Component> T editor(JTable table, int row, int column, Class<T> supportedType)
      Finds the component used as editor for the given JTable.

      Note: This method is not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Type Parameters:
      T - the generic type of the supported editor type.
      Parameters:
      table - the target 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 protected static Point cellLocation(JTable table, int row, int column, JTableLocation location)
      Returns the location of the given table cell.
      Parameters:
      table - the target 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(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 not executed in the event dispatch thread (EDT.) Clients are responsible for invoking this method in the EDT.

      Parameters:
      table - the target 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 protected final <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. Component lookup is performed by type.
      Type Parameters:
      T - the generic type of the cell editor.
      Parameters:
      table - the target 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 protected final <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.
      Type Parameters:
      T - the generic type of the cell editor.
      Parameters:
      matcher - the condition that the cell editor to look for needs to satisfy.
      table - the target 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

      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

      protected final TableCellEditor cellEditor()
      Returns the cell editor being currently used. This method will return null if no table cell is being currently edited.
      Returns:
      the cell editor being currently used, or null if no table cell is being currently edited.
    • cellEditor

      protected final void cellEditor(TableCellEditor newCellEditor)
      Sets the cell editor being currently used.
      Parameters:
      newCellEditor - the cell editor being currently used.