mirror of
https://github.com/NationalSecurityAgency/ghidra
synced 2024-09-13 05:37:14 +00:00
Merge remote-tracking branch 'origin/GP-1-dragonmacher-table-sort-fix--SQUASHED' into patch
This commit is contained in:
commit
37fb96328b
|
@ -22,6 +22,7 @@ import javax.swing.table.TableModel;
|
|||
|
||||
import docking.widgets.table.sort.DefaultColumnComparator;
|
||||
import docking.widgets.table.sort.RowBasedColumnComparator;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.Swing;
|
||||
import ghidra.util.datastruct.WeakDataStructureFactory;
|
||||
import ghidra.util.datastruct.WeakSet;
|
||||
|
@ -242,6 +243,14 @@ public abstract class AbstractSortedTableModel<T> extends AbstractGTableModel<T>
|
|||
}
|
||||
|
||||
protected TableSortingContext<T> createSortingContext(TableSortState newSortState) {
|
||||
|
||||
if (!isValidSortState(newSortState)) {
|
||||
Msg.error(this, """
|
||||
"Table '%s' sort is invalid. Assuming columns have been removed. \
|
||||
Setting unsorted.""".formatted(getName()));
|
||||
newSortState = TableSortState.createUnsortedSortState();
|
||||
}
|
||||
|
||||
return new TableSortingContext<>(newSortState, getComparatorChain(newSortState));
|
||||
}
|
||||
|
||||
|
|
|
@ -194,6 +194,19 @@ public class ThreadedTableTest extends AbstractThreadedTableTest {
|
|||
assertDidNotFilter();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovingSortedColumn() {
|
||||
|
||||
sortOnLastColumn();
|
||||
|
||||
// removing the last column will invalidate the last sort
|
||||
removeLastColumn();
|
||||
|
||||
// check sort becomes 'unsorted'
|
||||
TableSortingContext<Long> sortingContext = model.getSortingContext();
|
||||
assertTrue(sortingContext.isUnsorted());
|
||||
}
|
||||
|
||||
// Note: this is now handled the ThreadedTableFilterTest
|
||||
//
|
||||
// public void testContinuedFilteringUsesPreviousFilteredData() throws Exception {
|
||||
|
@ -555,6 +568,18 @@ public class ThreadedTableTest extends AbstractThreadedTableTest {
|
|||
// Private Methods
|
||||
//==================================================================================================
|
||||
|
||||
private void sortOnLastColumn() {
|
||||
int index = model.getColumnCount() - 1;
|
||||
sortColumn(index);
|
||||
checkSort(index);
|
||||
}
|
||||
|
||||
private void removeLastColumn() {
|
||||
int n = model.getColumnCount();
|
||||
model.removeTableColumn(n - 1);
|
||||
waitForTableModel(model);
|
||||
}
|
||||
|
||||
private void assertPendingPanelShowing() {
|
||||
JComponent pendingPanel = (JComponent) getInstanceField("pendingPanel", threadedTablePanel);
|
||||
|
||||
|
@ -810,8 +835,7 @@ public class ThreadedTableTest extends AbstractThreadedTableTest {
|
|||
|
||||
List<Object> modelValues = getModelValues(model, TestDataKeyModel.STRING_COL);
|
||||
assertEquals("Filter did not match the expected row count", 3, modelValues.size());
|
||||
for (int i = 0; i < modelValues.size(); i++) {
|
||||
Object value = modelValues.get(i);
|
||||
for (Object value : modelValues) {
|
||||
assertEquals(text, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import docking.widgets.table.*;
|
|||
import ghidra.docking.settings.Settings;
|
||||
import ghidra.framework.plugintool.ServiceProvider;
|
||||
import ghidra.framework.plugintool.TestDummyServiceProvider;
|
||||
import ghidra.util.Swing;
|
||||
import ghidra.util.datastruct.Accumulator;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
@ -36,26 +37,34 @@ public class TestDataKeyModel extends ThreadedTableModelStub<Long> {
|
|||
public final static int STRING_COL = 6;
|
||||
|
||||
private Byte[] bytes = new Byte[] { Byte.valueOf((byte) 0x09), Byte.valueOf((byte) 0x03),
|
||||
Byte.valueOf((byte) 0x0c), Byte.valueOf((byte) 0x55), Byte.valueOf((byte) 0x00), Byte.valueOf((byte) 0xdf),
|
||||
Byte.valueOf((byte) 0xff), Byte.valueOf((byte) 0x03), Byte.valueOf((byte) 0x16), Byte.valueOf((byte) 0x02),
|
||||
Byte.valueOf((byte) 0x0c), Byte.valueOf((byte) 0x55), Byte.valueOf((byte) 0x00),
|
||||
Byte.valueOf((byte) 0xdf),
|
||||
Byte.valueOf((byte) 0xff), Byte.valueOf((byte) 0x03), Byte.valueOf((byte) 0x16),
|
||||
Byte.valueOf((byte) 0x02),
|
||||
Byte.valueOf((byte) 0x03), Byte.valueOf((byte) 0x04), };
|
||||
|
||||
private Short[] shorts = new Short[] { Short.valueOf((short) 0x0841), Short.valueOf((short) 0xb0f7),
|
||||
private Short[] shorts = new Short[] { Short.valueOf((short) 0x0841),
|
||||
Short.valueOf((short) 0xb0f7),
|
||||
Short.valueOf((short) 0xf130), Short.valueOf((short) 0x84e3), Short.valueOf((short) 0x2976),
|
||||
Short.valueOf((short) 0x17d9), Short.valueOf((short) 0xf146), Short.valueOf((short) 0xc4a5),
|
||||
Short.valueOf((short) 0x88f1), Short.valueOf((short) 0x966d), Short.valueOf((short) 0x966e),
|
||||
Short.valueOf((short) 0x966f), };
|
||||
|
||||
private Integer[] ints =
|
||||
new Integer[] { Integer.valueOf(0x039D492B), Integer.valueOf(0x0A161497), Integer.valueOf(0x06AA1497),
|
||||
new Integer[] { Integer.valueOf(0x039D492B), Integer.valueOf(0x0A161497),
|
||||
Integer.valueOf(0x06AA1497),
|
||||
Integer.valueOf(0x0229EE9E), Integer.valueOf(0xFB7428E1), Integer.valueOf(0xD2B4ED2F),
|
||||
Integer.valueOf(0x0C1F67DE), Integer.valueOf(0x0E61C987), Integer.valueOf(0x0133751F),
|
||||
Integer.valueOf(0x07B39541), Integer.valueOf(0x07B39542), Integer.valueOf(0x07B39542), };
|
||||
Integer.valueOf(0x07B39541), Integer.valueOf(0x07B39542),
|
||||
Integer.valueOf(0x07B39542), };
|
||||
|
||||
private Long[] longs = new Long[] { Long.valueOf(0x0000000DFAA00C4FL),
|
||||
Long.valueOf(0x00000001FD7CA6A6L), Long.valueOf(0xFFFFFFF4D0EB4AB8L), Long.valueOf(0x0000000445246143L),
|
||||
Long.valueOf(0xFFFFFFF5696F1780L), Long.valueOf(0x0000000685526E5DL), Long.valueOf(0x00000009A1FD98EEL),
|
||||
Long.valueOf(0x00000004AD2B1869L), Long.valueOf(0x00000002928E64C8L), Long.valueOf(0x000000071CE1DDB2L),
|
||||
Long.valueOf(0x00000001FD7CA6A6L), Long.valueOf(0xFFFFFFF4D0EB4AB8L),
|
||||
Long.valueOf(0x0000000445246143L),
|
||||
Long.valueOf(0xFFFFFFF5696F1780L), Long.valueOf(0x0000000685526E5DL),
|
||||
Long.valueOf(0x00000009A1FD98EEL),
|
||||
Long.valueOf(0x00000004AD2B1869L), Long.valueOf(0x00000002928E64C8L),
|
||||
Long.valueOf(0x000000071CE1DDB2L),
|
||||
Long.valueOf(0x000000071CE1DDB3L), Long.valueOf(0x000000071CE1DDB4L), };
|
||||
|
||||
private Float[] floats =
|
||||
|
@ -112,6 +121,13 @@ public class TestDataKeyModel extends ThreadedTableModelStub<Long> {
|
|||
return ROWCOUNT;
|
||||
}
|
||||
|
||||
void removeTableColumn(int index) {
|
||||
Swing.runNow(() -> {
|
||||
DynamicTableColumn<Long, ?, ?> column = getColumn(index);
|
||||
removeTableColumn(column);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doLoad(Accumulator<Long> accumulator, TaskMonitor monitor)
|
||||
throws CancelledException {
|
||||
|
|
Loading…
Reference in a new issue