Search in sources :

Example 1 with AbstractSingleRecordTableModel

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;
}
Also used : JXTable(org.jdesktop.swingx.JXTable) Color(java.awt.Color) JComponent(javax.swing.JComponent) AbstractSingleRecordTableModel(com.revolsys.swing.table.record.model.AbstractSingleRecordTableModel) EmptyBorder(javax.swing.border.EmptyBorder) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 AbstractSingleRecordTableModel (com.revolsys.swing.table.record.model.AbstractSingleRecordTableModel)1 Color (java.awt.Color)1 JComponent (javax.swing.JComponent)1 EmptyBorder (javax.swing.border.EmptyBorder)1 JXTable (org.jdesktop.swingx.JXTable)1