Skip to content

Commit

Permalink
The fix for Get Table Cell Value causing ClassCastExceptions for bool…
Browse files Browse the repository at this point in the history
…ean text. (issue #59)

Still missing tests.
  • Loading branch information
jussimalinen committed Feb 9, 2015
1 parent dd0ecc7 commit 17eb10a
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CellValueExtractor(JTableOperator jTableOperator) {
public String textOf(int row, int col) {
try {
Component cellRendererComponent = getCellRendererComponent(row, col);
if (isCheckboxRenderer(cellRendererComponent))
if (isButtonBasedRenderer(cellRendererComponent))
return new Boolean(((AbstractButton) cellRendererComponent).isSelected()).toString();
return coerceToWithText(cellRendererComponent).getText();
} catch (AllMethodsNotImplementedException e) {
Expand All @@ -39,9 +39,10 @@ public Component getCellRendererComponent(int row, int column) {
return getTableCellRendererComponentSmoothly(row, column, renderer, table, value, isSelected, hasFocus);
}

private boolean isCheckboxRenderer(Component cellRendererComponent) {
private boolean isButtonBasedRenderer(Component cellRendererComponent) {
TableCellRenderer defaultCheckboxRenderer = ((JTable) jTableOperator.getSource()).getDefaultRenderer(Boolean.class);
return (defaultCheckboxRenderer.getClass().isInstance(cellRendererComponent));
return (defaultCheckboxRenderer.getClass().isInstance(cellRendererComponent) &&
cellRendererComponent instanceof AbstractButton);
}

private WithText coerceToWithText(Object element) {
Expand Down

0 comments on commit 17eb10a

Please sign in to comment.