Search in sources :

Example 1 with RecordListTableModel

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

the class MergeRecordsDialog method setMergedRecords.

public void setMergedRecords(String errorMessage, final Map<Record, Set<LayerRecord>> mergedRecords) {
    final Set<Record> unMergeableRecords = new HashSet<>(this.mergeableToOiginalRecordMap.keySet());
    unMergeableRecords.removeAll(mergedRecords.keySet());
    if (!mergedRecords.isEmpty()) {
        int i = 0;
        for (final Entry<Record, Set<LayerRecord>> mergedEntry : mergedRecords.entrySet()) {
            final Record mergedObject = mergedEntry.getKey();
            final Set<LayerRecord> originalObjects = mergedEntry.getValue();
            setMergedRecord(i, mergedObject, originalObjects);
            i++;
        }
    }
    if (!unMergeableRecords.isEmpty() || Property.hasValue(errorMessage)) {
        final Set<LayerRecord> records = new LinkedHashSet<>();
        for (final Record record : unMergeableRecords) {
            final LayerRecord originalRecord = this.mergeableToOiginalRecordMap.get(record);
            if (originalRecord != null) {
                records.add(originalRecord);
            }
        }
        final TablePanel tablePanel = RecordListTableModel.newPanel(this.layer, records);
        final RecordListTableModel tableModel = tablePanel.getTableModel();
        tableModel.setEditable(false);
        tablePanel.setPreferredSize(new Dimension(100, 50 + unMergeableRecords.size() * 22));
        final JPanel panel = Panels.titledTransparentBorderLayout(unMergeableRecords.size() + " Un-Mergeable Records");
        if (!Property.hasValue(errorMessage)) {
            errorMessage = "The following records could not be merged and will not be modified.";
        }
        final JLabel unMergeLabel = new JLabel("<html><p style=\"color:red\">" + errorMessage + "</p></html>");
        panel.add(unMergeLabel, BorderLayout.NORTH);
        panel.add(tablePanel, BorderLayout.SOUTH);
        this.mergedRecordsPanel.add(panel);
    }
    SwingUtil.autoAdjustPosition(this);
    setVisible(true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) JPanel(javax.swing.JPanel) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) RecordListTableModel(com.revolsys.swing.table.record.model.RecordListTableModel) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) TablePanel(com.revolsys.swing.table.TablePanel)

Example 2 with RecordListTableModel

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

the class RecordValidationDialog method newValidRecordsTablePanel.

private TablePanel newValidRecordsTablePanel() {
    final RecordDefinition recordDefinition = this.layer.getRecordDefinition();
    final List<String> fieldNames = this.layer.getFieldNames();
    final RecordListTableModel model = new RecordListTableModel(recordDefinition, this.validRecords, fieldNames);
    final RecordRowTable table = new RecordRowTable(model);
    table.setVisibleRowCount(Math.min(10, model.getRowCount() + 1));
    table.setSortable(true);
    table.setEditable(false);
    table.resizeColumnsToContent();
    final TablePanel tablePanel = new TablePanel(table);
    tablePanel.setBorder(BorderFactory.createTitledBorder(table.getRowCount() + " valid records"));
    return tablePanel;
}
Also used : RecordListTableModel(com.revolsys.swing.table.record.model.RecordListTableModel) RecordDefinition(com.revolsys.record.schema.RecordDefinition) RecordRowTable(com.revolsys.swing.table.record.RecordRowTable) TablePanel(com.revolsys.swing.table.TablePanel)

Example 3 with RecordListTableModel

use of com.revolsys.swing.table.record.model.RecordListTableModel 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)

Aggregations

TablePanel (com.revolsys.swing.table.TablePanel)3 RecordListTableModel (com.revolsys.swing.table.record.model.RecordListTableModel)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 RecordRowTable (com.revolsys.swing.table.record.RecordRowTable)2 ArrayRecord (com.revolsys.record.ArrayRecord)1 Record (com.revolsys.record.Record)1 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)1 ColorHighlighter (com.revolsys.swing.table.highlighter.ColorHighlighter)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 ComponentAdapter (org.jdesktop.swingx.decorator.ComponentAdapter)1 HighlightPredicate (org.jdesktop.swingx.decorator.HighlightPredicate)1