From 17eb10ad38d541ffd64d359afe359a268384866c Mon Sep 17 00:00:00 2001 From: Jussi Malinen Date: Mon, 9 Feb 2015 16:04:05 +0200 Subject: [PATCH] The fix for Get Table Cell Value causing ClassCastExceptions for boolean text. (issue #59) Still missing tests. --- .../org/robotframework/swing/table/CellValueExtractor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/robotframework/swing/table/CellValueExtractor.java b/src/main/java/org/robotframework/swing/table/CellValueExtractor.java index b79594f0..3d3e032c 100644 --- a/src/main/java/org/robotframework/swing/table/CellValueExtractor.java +++ b/src/main/java/org/robotframework/swing/table/CellValueExtractor.java @@ -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) { @@ -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) {