Skip to content

Commit

Permalink
Get Table Cell Value enhancement (#163)
Browse files Browse the repository at this point in the history
* Get Table Cell Value enhancement for cell in Property Sheet Table using Combo Box Renderer

Co-authored-by: ricu <[email protected]>
  • Loading branch information
ricualex and ricu authored Oct 17, 2022
1 parent 3be6143 commit aa27f9e
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import java.awt.Component;

import javax.swing.AbstractButton;
import javax.swing.JTable;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;

import org.jretrofit.AllMethodsNotImplementedException;
Expand Down Expand Up @@ -48,6 +47,11 @@ private String getTextFromCellComponent(int row, int col) {
Component cellRendererComponent = getCellRendererComponent(row, col);
if (isButtonBasedRenderer(cellRendererComponent))
return new Boolean(((AbstractButton) cellRendererComponent).isSelected()).toString();
if (isComboBoxBasedRenderer(cellRendererComponent)) {
if (jTableOperator.getModel().getValueAt(row, col) instanceof String)
return jTableOperator.getModel().getValueAt(row, col).toString();
return ((JComboBox) cellRendererComponent).getSelectedItem().toString();
}
return coerceToWithText(cellRendererComponent).getText();
}

Expand All @@ -66,6 +70,10 @@ private boolean isButtonBasedRenderer(Component cellRendererComponent) {
cellRendererComponent instanceof AbstractButton);
}

private boolean isComboBoxBasedRenderer(Component cellRendererComponent) {
return cellRendererComponent instanceof JComboBox;
}

private WithText coerceToWithText(Object element) {
return (WithText) Retrofit.complete(element, WithText.class);
}
Expand Down

0 comments on commit aa27f9e

Please sign in to comment.