Search in sources :

Example 6 with RecordRowTable

use of com.revolsys.swing.table.record.RecordRowTable in project com.revolsys.open by revolsys.

the class RecordValidationDialog method newInvalidRecordsTablePanel.

private TablePanel newInvalidRecordsTablePanel() {
    final RecordDefinition recordDefinition = this.layer.getRecordDefinition();
    final List<String> fieldNames = this.layer.getFieldNames();
    final RecordListTableModel model = new RecordListTableModel(recordDefinition, this.invalidRecords, fieldNames);
    model.setReadOnlyFieldNames(this.layer.getUserReadOnlyFieldNames());
    final RecordRowTable table = new RecordRowTable(model);
    table.setVisibleRowCount(Math.min(10, model.getRowCount() + 1));
    table.setSortable(true);
    table.resizeColumnsToContent();
    final HighlightPredicate invalidFieldPredicate = (final Component renderer, final ComponentAdapter adapter) -> {
        try {
            final int rowIndex = adapter.convertRowIndexToModel(adapter.row);
            final int columnIndex = adapter.convertColumnIndexToModel(adapter.column);
            final Map<String, String> fieldErrors = this.invalidRecordErrors.get(rowIndex);
            if (!fieldErrors.isEmpty()) {
                final String fieldName = this.layer.getFieldName(columnIndex);
                final String errorMessage = fieldErrors.get(fieldName);
                if (Property.hasValue(errorMessage)) {
                    final JComponent jcomponent = (JComponent) renderer;
                    jcomponent.setToolTipText(errorMessage);
                    return true;
                }
            }
        } catch (final Throwable e) {
        }
        return false;
    };
    final Highlighter invalidFieldHighlighter = new ColorHighlighter(invalidFieldPredicate, WebColors.newAlpha(Color.RED, 64), Color.RED, Color.RED, Color.YELLOW);
    table.addHighlighter(invalidFieldHighlighter);
    final HighlightPredicate validRecordPredicate = (final Component renderer, final ComponentAdapter adapter) -> {
        try {
            final int rowIndex = adapter.convertRowIndexToModel(adapter.row);
            final Map<String, String> fieldErrors = this.invalidRecordErrors.get(rowIndex);
            if (fieldErrors.isEmpty()) {
                return true;
            }
        } catch (final Throwable e) {
        }
        return false;
    };
    table.addHighlighter(new ColorHighlighter(new AndHighlightPredicate(validRecordPredicate, HighlightPredicate.EVEN), WebColors.newAlpha(WebColors.LimeGreen, 127), WebColors.Black, WebColors.newAlpha(WebColors.DarkGreen, 191), Color.WHITE));
    table.addHighlighter(new ColorHighlighter(new AndHighlightPredicate(validRecordPredicate, HighlightPredicate.ODD), WebColors.LimeGreen, WebColors.Black, WebColors.DarkGreen, Color.WHITE));
    final TablePanel tablePanel = new TablePanel(table);
    tablePanel.setBorder(BorderFactory.createTitledBorder(table.getRowCount() + " invalid records"));
    return tablePanel;
}
Also used : JComponent(javax.swing.JComponent) RecordDefinition(com.revolsys.record.schema.RecordDefinition) ColorHighlighter(com.revolsys.swing.table.highlighter.ColorHighlighter) HighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate) AndHighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate) JComponent(javax.swing.JComponent) Component(java.awt.Component) AndHighlightPredicate(org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate) HashMap(java.util.HashMap) Map(java.util.Map) RecordListTableModel(com.revolsys.swing.table.record.model.RecordListTableModel) ComponentAdapter(org.jdesktop.swingx.decorator.ComponentAdapter) RecordRowTable(com.revolsys.swing.table.record.RecordRowTable) Highlighter(org.jdesktop.swingx.decorator.Highlighter) ColorHighlighter(com.revolsys.swing.table.highlighter.ColorHighlighter) TablePanel(com.revolsys.swing.table.TablePanel)

Example 7 with RecordRowTable

use of com.revolsys.swing.table.record.RecordRowTable in project com.revolsys.open by revolsys.

the class RecordListTableModel method newPanel.

public static TablePanel newPanel(final RecordDefinition recordDefinition, final Collection<? extends Record> records, final Collection<String> fieldNames) {
    final RecordListTableModel model = new RecordListTableModel(recordDefinition, records, fieldNames);
    final BaseJTable table = new RecordRowTable(model);
    return new TablePanel(table);
}
Also used : BaseJTable(com.revolsys.swing.table.BaseJTable) RecordRowTable(com.revolsys.swing.table.record.RecordRowTable) TablePanel(com.revolsys.swing.table.TablePanel)

Example 8 with RecordRowTable

use of com.revolsys.swing.table.record.RecordRowTable in project com.revolsys.open by revolsys.

the class RecordRowTableModel method isSelected.

@Override
public boolean isSelected(boolean selected, final int rowIndex, final int columnIndex) {
    final RecordRowTable table = getTable();
    final int[] selectedRows = table.getSelectedRows();
    selected = false;
    for (final int selectedRow : selectedRows) {
        if (rowIndex == selectedRow) {
            return true;
        }
    }
    return false;
}
Also used : RecordRowTable(com.revolsys.swing.table.record.RecordRowTable)

Aggregations

RecordRowTable (com.revolsys.swing.table.record.RecordRowTable)8 TablePanel (com.revolsys.swing.table.TablePanel)5 Record (com.revolsys.record.Record)3 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)3 RecordListTableModel (com.revolsys.swing.table.record.model.RecordListTableModel)3 ListSelectionModel (javax.swing.ListSelectionModel)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 ColorHighlighter (com.revolsys.swing.table.highlighter.ColorHighlighter)2 HighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate)2 AndHighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate)2 WebColors (com.revolsys.awt.WebColors)1 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)1 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)1 BaseJTable (com.revolsys.swing.table.BaseJTable)1 SortableTableModel (com.revolsys.swing.table.SortableTableModel)1 Component (java.awt.Component)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1