use of com.revolsys.swing.table.record.model.AbstractSingleRecordTableModel in project com.revolsys.open by revolsys.
the class SingleRecordTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, int rowIndex, int columnIndex) {
if (table instanceof JXTable) {
final JXTable jxTable = (JXTable) table;
rowIndex = jxTable.convertRowIndexToModel(rowIndex);
columnIndex = jxTable.convertColumnIndexToModel(columnIndex);
}
final AbstractSingleRecordTableModel model = (AbstractSingleRecordTableModel) table.getModel();
final RecordDefinition recordDefinition = model.getRecordDefinition();
JComponent component = null;
final String name = model.getColumnFieldName(rowIndex, columnIndex);
final boolean required = recordDefinition.isFieldRequired(name);
this.valueComponent.setBorder(new EmptyBorder(1, 2, 1, 2));
if (columnIndex == 0) {
this.valueComponent.setText(String.valueOf(rowIndex + 1));
this.valueComponent.setHorizontalAlignment(SwingConstants.RIGHT);
this.valueComponent.setHorizontalTextPosition(SwingConstants.RIGHT);
component = this.valueComponent;
} else if (columnIndex == 1) {
final String title = model.getFieldTitle(name);
this.labelComponent.setText(title);
this.labelComponent.setBorder(new EmptyBorder(1, 2, 1, 2));
component = this.labelComponent;
} else {
final String text = model.toDisplayValue(rowIndex, rowIndex, value);
this.valueComponent.setText(text);
if (BigDecimals.isNumber(text)) {
this.valueComponent.setHorizontalAlignment(SwingConstants.RIGHT);
this.valueComponent.setHorizontalTextPosition(SwingConstants.RIGHT);
} else {
this.valueComponent.setHorizontalAlignment(SwingConstants.LEFT);
this.valueComponent.setHorizontalTextPosition(SwingConstants.LEFT);
}
component = this.valueComponent;
}
if (required && model.getObjectValue(rowIndex, columnIndex) == null) {
component.setBackground(new Color(255, 0, 0, 100));
component.setForeground(table.getForeground());
}
component.setToolTipText(null);
return component;
}
Aggregations