Table column fix for disappearing/moving table columns

This commit is contained in:
dragonmacher 2022-01-19 17:55:51 -05:00
parent ed0a7d925c
commit 4faa5d2b2a
4 changed files with 31 additions and 10 deletions

View file

@ -136,8 +136,7 @@ public class GTableColumnModel
}
private int findVisibleInsertionIndex(TableColumn column) {
int completeIndex = visibleColumns.indexOf(column);
int completeIndex = completeList.indexOf(column);
int size = visibleColumns.size();
for (int i = completeIndex + 1; i < size; i++) {
TableColumn nextColumn = completeList.get(i);
@ -483,6 +482,10 @@ public class GTableColumnModel
columnModelState.saveState();
}
void forceSaveState() {
columnModelState.forceSaveState();
}
void restoreState() {
columnModelState.restoreState();
}
@ -626,5 +629,4 @@ public class GTableColumnModel
public void restoreFromXML(Element element) {
columnModelState.restoreFromXML(element);
}
}

View file

@ -58,8 +58,10 @@ public class SelectColumnsDialog extends DialogComponentProvider {
// Skip column 0, which has already been set to a boolean renderer
for (int i = 1; i < ghidraTable.getColumnCount(); i++) {
ghidraTable.getColumnModel().getColumn(i).setCellRenderer(
new ColumnSelectorStringRenderer());
ghidraTable.getColumnModel()
.getColumn(i)
.setCellRenderer(
new ColumnSelectorStringRenderer());
}
ghidraTable.setBorder(BorderFactory.createEtchedBorder());
@ -78,6 +80,7 @@ public class SelectColumnsDialog extends DialogComponentProvider {
}
private void initialize() {
List<TableColumn> columns = columnModel.getAllColumns();
columnList = new ArrayList<>(columns.size());
for (TableColumn column : columns) {
@ -134,6 +137,11 @@ public class SelectColumnsDialog extends DialogComponentProvider {
columnModel.setVisible(column, visible);
}
}
// force a save of the new table column state here so clients to not use the table with
// a pending state save
columnModel.forceSaveState();
close();
}

View file

@ -149,6 +149,12 @@ public class TableColumnModelState implements SortListener {
}
}
// used only in special circumstances to force a save
void forceSaveState() {
doSaveState(saveToXML());
saveUpdateManager.stop();
}
private void doSaveState() {
if (restoreUpdateManager.isBusy()) {
@ -182,11 +188,14 @@ public class TableColumnModelState implements SortListener {
List<TableColumn> columnList = columnModel.getAllColumns();
for (TableColumn column : columnList) {
String columnName = getColumnName(column);
String width = Integer.toString(column.getWidth());
boolean visible = columnModel.isVisible(column);
Element columnElement = new Element(XML_COLUMN);
columnElement.setAttribute(XML_COLUMN_NAME, getColumnName(column));
columnElement.setAttribute(XML_COLUMN_WIDTH, Integer.toString(column.getWidth()));
columnElement.setAttribute(XML_COLUMN_VISIBLE,
Boolean.toString(columnModel.isVisible(column)));
columnElement.setAttribute(XML_COLUMN_NAME, columnName);
columnElement.setAttribute(XML_COLUMN_WIDTH, width);
columnElement.setAttribute(XML_COLUMN_VISIBLE, Boolean.toString(visible));
saveColumnSettings(columnElement, column);
xmlElement.addContent(columnElement);
}
@ -347,8 +356,10 @@ public class TableColumnModelState implements SortListener {
List<Settings> settingsList = new ArrayList<>();
for (Object object : children) {
Element element = (Element) object;
String columnName = element.getAttributeValue(XML_COLUMN_NAME);
TableColumn column = getColumn(columnName, oldCompleteList);
if (column == null) {
setDefaultColumnsVisible();