mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-12 23:23:17 +00:00
GT-2921 - Fixed exception in Data Settings Dialog related to recent
refactoring
This commit is contained in:
parent
398db09cec
commit
2d0b9dd787
@ -127,6 +127,10 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
||||
setHelpLocation(new HelpLocation("DataPlugin", "SettingsOnStructureComponents"));
|
||||
}
|
||||
|
||||
GTable getSettingsTable() {
|
||||
return settingsTable;
|
||||
}
|
||||
|
||||
SettingsTableModel getSettingsTableModel() {
|
||||
return settingsTableModel;
|
||||
}
|
||||
@ -666,6 +670,20 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
// override this to force the correct cell editors to be used
|
||||
@Override
|
||||
public Class<?> getColumnClass(int col) {
|
||||
switch (col) {
|
||||
case 0:
|
||||
return String.class;
|
||||
case 1:
|
||||
return Settings.class;
|
||||
case 2:
|
||||
return Boolean.class;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getColumnValueForRow(SettingsRowObject t, int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
@ -698,7 +716,7 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingsEditor extends AbstractCellEditor implements TableCellEditor {
|
||||
class SettingsEditor extends AbstractCellEditor implements TableCellEditor {
|
||||
|
||||
final static int ENUM = 0;
|
||||
final static int BOOLEAN = 1;
|
||||
@ -710,9 +728,10 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
||||
comboBox.addItemListener(e -> fireEditingStopped());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.CellEditor#getCellEditorValue()
|
||||
*/
|
||||
GComboBox<String> getComboBox() {
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getCellEditorValue() {
|
||||
switch (mode) {
|
||||
|
@ -40,8 +40,6 @@ import ghidra.program.util.ProgramSelection;
|
||||
* {@link #setNavigateOnSelectionEnabled(boolean)} with a value of false.
|
||||
* <p>
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
// Suppress - we are using the deprecated reference to DefaultSortedTableModel to handle old code
|
||||
public class GhidraTable extends GTable {
|
||||
|
||||
private Navigatable navigatable;
|
||||
|
@ -20,19 +20,25 @@ import static org.junit.Assert.*;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.table.TableCellEditor;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import docking.ActionContext;
|
||||
import docking.action.DockingActionIf;
|
||||
import docking.action.MenuData;
|
||||
import docking.widgets.combobox.GComboBox;
|
||||
import docking.widgets.dialogs.StringChoices;
|
||||
import docking.widgets.table.AbstractSortedTableModel;
|
||||
import docking.widgets.table.GTable;
|
||||
import ghidra.app.LocationCallback;
|
||||
import ghidra.app.context.ListingActionContext;
|
||||
import ghidra.app.events.ProgramLocationPluginEvent;
|
||||
import ghidra.app.events.ProgramSelectionPluginEvent;
|
||||
import ghidra.app.plugin.core.clear.ClearCmd;
|
||||
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
|
||||
import ghidra.app.plugin.core.data.DataSettingsDialog.SettingsEditor;
|
||||
import ghidra.app.plugin.core.data.DataSettingsDialog.SettingsRowObject;
|
||||
import ghidra.app.plugin.core.navigation.NextPrevAddressPlugin;
|
||||
import ghidra.docking.settings.FormatSettingsDefinition;
|
||||
@ -134,6 +140,7 @@ public abstract class AbstractDataActionTest extends AbstractGhidraHeadedIntegra
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
closeAllWindows();
|
||||
env.dispose();
|
||||
}
|
||||
|
||||
@ -255,15 +262,20 @@ public abstract class AbstractDataActionTest extends AbstractGhidraHeadedIntegra
|
||||
int settingsCol = model.findColumn("Settings");
|
||||
int rowCnt = model.getRowCount();
|
||||
|
||||
for (int i = 0; i < rowCnt; i++) {
|
||||
String name = (String) model.getValueAt(i, nameCol);
|
||||
for (int row = 0; row < rowCnt; row++) {
|
||||
String name = (String) model.getValueAt(row, nameCol);
|
||||
int index = findSettingIndex(settingNames, name);
|
||||
if (index != -1) {
|
||||
Object v = model.getValueAt(i, settingsCol);
|
||||
Object v = model.getValueAt(row, settingsCol);
|
||||
if (v instanceof StringChoices) {
|
||||
StringChoices choices = (StringChoices) v;
|
||||
|
||||
triggerEdit(dlg, row, settingsCol);
|
||||
setComboValue(dlg, newValues[index]);
|
||||
endEdit(dlg);
|
||||
|
||||
choices.setSelectedValue(newValues[index]);
|
||||
model.setValueAt(choices, i, settingsCol);
|
||||
model.setValueAt(choices, row, settingsCol);
|
||||
}
|
||||
else {
|
||||
error = "Unsupported test setting: " + v.getClass();
|
||||
@ -283,6 +295,44 @@ public abstract class AbstractDataActionTest extends AbstractGhidraHeadedIntegra
|
||||
waitForSwing();
|
||||
}
|
||||
|
||||
private void endEdit(DataSettingsDialog d) {
|
||||
GTable table = d.getSettingsTable();
|
||||
runSwing(() -> table.editingStopped(new ChangeEvent(table)));
|
||||
}
|
||||
|
||||
private void setComboValue(DataSettingsDialog d, String string) {
|
||||
GTable table = d.getSettingsTable();
|
||||
TableCellEditor activeEditor = runSwing(() -> table.getCellEditor());
|
||||
assertNotNull("Table should be editing, but is not", activeEditor);
|
||||
assertTrue("Editor type is not correct", activeEditor instanceof SettingsEditor);
|
||||
|
||||
SettingsEditor settingsEditor = (SettingsEditor) activeEditor;
|
||||
GComboBox<String> combo = settingsEditor.getComboBox();
|
||||
|
||||
int index = runSwing(() -> {
|
||||
int n = combo.getItemCount();
|
||||
for (int i = 0; i < n; i++) {
|
||||
String item = combo.getItemAt(i);
|
||||
if (item.equals(string)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
|
||||
assertNotEquals("Combo does not contain item '" + string + "'", -1, index);
|
||||
|
||||
runSwing(() -> {
|
||||
combo.setSelectedIndex(index);
|
||||
});
|
||||
}
|
||||
|
||||
private void triggerEdit(DataSettingsDialog d, int row, int col) {
|
||||
GTable table = d.getSettingsTable();
|
||||
boolean editStarted = runSwing(() -> table.editCellAt(row, col));
|
||||
assertTrue("Unable to edit dialog table cell at " + row + ", " + col, editStarted);
|
||||
}
|
||||
|
||||
protected int findSettingIndex(String[] settingNames, String name) {
|
||||
for (int i = 0; i < settingNames.length; i++) {
|
||||
if (settingNames[i].equals(name)) {
|
||||
|
@ -15,9 +15,9 @@
|
||||
*/
|
||||
package docking.widgets.table;
|
||||
|
||||
import static docking.DockingUtils.CONTROL_KEY_MODIFIER_MASK;
|
||||
import static docking.action.MenuData.NO_MNEMONIC;
|
||||
import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
|
||||
import static docking.DockingUtils.*;
|
||||
import static docking.action.MenuData.*;
|
||||
import static java.awt.event.InputEvent.*;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
@ -69,7 +69,6 @@ import resources.ResourceManager;
|
||||
*
|
||||
* @see GTableFilterPanel
|
||||
*/
|
||||
// Suppress - we are using the deprecated reference to DefaultSortedTableModel to handle old code
|
||||
public class GTable extends JTable implements KeyStrokeConsumer, DockingActionProviderIf {
|
||||
|
||||
private static final String LAST_EXPORT_FILE = "LAST_EXPORT_DIR";
|
||||
|
Loading…
Reference in New Issue
Block a user