Search in sources :

Example 1 with Highlighter

use of org.jdesktop.swingx.decorator.Highlighter in project com.revolsys.open by revolsys.

the class ErrorPredicate method add.

public static void add(final RecordRowTable table) {
    final RecordRowTableModel model = table.getTableModel();
    final Highlighter highlighter = getHighlighter(model);
    table.addHighlighter(highlighter);
}
Also used : RecordRowTableModel(com.revolsys.swing.table.record.model.RecordRowTableModel) Highlighter(org.jdesktop.swingx.decorator.Highlighter) ColorHighlighter(org.jdesktop.swingx.decorator.ColorHighlighter)

Example 2 with Highlighter

use of org.jdesktop.swingx.decorator.Highlighter 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 3 with Highlighter

use of org.jdesktop.swingx.decorator.Highlighter in project com.revolsys.open by revolsys.

the class MergedRecordPredicate method add.

public static void add(final RecordRowTable table) {
    final MergedRecordsTableModel model = table.getTableModel();
    final MergedRecordPredicate predicate = new MergedRecordPredicate(model);
    final Highlighter colors = new ColorHighlighter(predicate, WebColors.newAlpha(WebColors.Green, 64), WebColors.Black, WebColors.Green, WebColors.White);
    table.addHighlighter(colors);
}
Also used : ColorHighlighter(org.jdesktop.swingx.decorator.ColorHighlighter) MergedRecordsTableModel(com.revolsys.swing.map.layer.record.table.model.MergedRecordsTableModel) Highlighter(org.jdesktop.swingx.decorator.Highlighter) ColorHighlighter(org.jdesktop.swingx.decorator.ColorHighlighter)

Aggregations

Highlighter (org.jdesktop.swingx.decorator.Highlighter)3 ColorHighlighter (org.jdesktop.swingx.decorator.ColorHighlighter)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 MergedRecordsTableModel (com.revolsys.swing.map.layer.record.table.model.MergedRecordsTableModel)1 TablePanel (com.revolsys.swing.table.TablePanel)1 ColorHighlighter (com.revolsys.swing.table.highlighter.ColorHighlighter)1 RecordRowTable (com.revolsys.swing.table.record.RecordRowTable)1 RecordListTableModel (com.revolsys.swing.table.record.model.RecordListTableModel)1 RecordRowTableModel (com.revolsys.swing.table.record.model.RecordRowTableModel)1 Component (java.awt.Component)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JComponent (javax.swing.JComponent)1 ComponentAdapter (org.jdesktop.swingx.decorator.ComponentAdapter)1 HighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate)1 AndHighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate.AndHighlightPredicate)1