public ConfigTableModel(Resources messages, StyleRules styleRules) { super(); this.messages = messages; this.styleRules = styleRules; styleRules.addListener(this); styleRules.addStyleRuleListener(this); }
@Override public void listStructureChanged(StyleRules newStyleRules) { int oldRowCount = styleRules.getPatternStyles().size(); int newRowCount = newStyleRules.getPatternStyles().size(); styleRules.removeListener(this); styleRules = newStyleRules; styleRules.addListener(this); // Remove first since we do not want to be registered twice on old // rules. styleRules.removeStyleRuleListener(this); styleRules.addStyleRuleListener(this); // fireTableDataChanged() - Which would seem like the perfect event // messes up the selections in the table. TableRowsUpdated does not even // if we say that all rows are updated if (oldRowCount > newRowCount) { fireTableRowsDeleted(newRowCount, oldRowCount); } else { fireTableRowsInserted(oldRowCount, newRowCount); } int rowsToUpdate = Math.min(oldRowCount, newRowCount); fireTableRowsUpdated(0, rowsToUpdate); }