mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GT-2921 - Fixed exception in Data Settings Dialog related to recent
refactoring
This commit is contained in:
@@ -127,6 +127,10 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
|||||||
setHelpLocation(new HelpLocation("DataPlugin", "SettingsOnStructureComponents"));
|
setHelpLocation(new HelpLocation("DataPlugin", "SettingsOnStructureComponents"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GTable getSettingsTable() {
|
||||||
|
return settingsTable;
|
||||||
|
}
|
||||||
|
|
||||||
SettingsTableModel getSettingsTableModel() {
|
SettingsTableModel getSettingsTableModel() {
|
||||||
return settingsTableModel;
|
return settingsTableModel;
|
||||||
}
|
}
|
||||||
@@ -666,6 +670,20 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
|||||||
return null;
|
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
|
@Override
|
||||||
public Object getColumnValueForRow(SettingsRowObject t, int columnIndex) {
|
public Object getColumnValueForRow(SettingsRowObject t, int columnIndex) {
|
||||||
switch (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 ENUM = 0;
|
||||||
final static int BOOLEAN = 1;
|
final static int BOOLEAN = 1;
|
||||||
@@ -710,9 +728,10 @@ public class DataSettingsDialog extends DialogComponentProvider {
|
|||||||
comboBox.addItemListener(e -> fireEditingStopped());
|
comboBox.addItemListener(e -> fireEditingStopped());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
GComboBox<String> getComboBox() {
|
||||||
* @see javax.swing.CellEditor#getCellEditorValue()
|
return comboBox;
|
||||||
*/
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getCellEditorValue() {
|
public Object getCellEditorValue() {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
|
|||||||
@@ -40,8 +40,6 @@ import ghidra.program.util.ProgramSelection;
|
|||||||
* {@link #setNavigateOnSelectionEnabled(boolean)} with a value of false.
|
* {@link #setNavigateOnSelectionEnabled(boolean)} with a value of false.
|
||||||
* <p>
|
* <p>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
// Suppress - we are using the deprecated reference to DefaultSortedTableModel to handle old code
|
|
||||||
public class GhidraTable extends GTable {
|
public class GhidraTable extends GTable {
|
||||||
|
|
||||||
private Navigatable navigatable;
|
private Navigatable navigatable;
|
||||||
|
|||||||
@@ -20,19 +20,25 @@ import static org.junit.Assert.*;
|
|||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.table.TableCellEditor;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import docking.ActionContext;
|
import docking.ActionContext;
|
||||||
import docking.action.DockingActionIf;
|
import docking.action.DockingActionIf;
|
||||||
import docking.action.MenuData;
|
import docking.action.MenuData;
|
||||||
|
import docking.widgets.combobox.GComboBox;
|
||||||
import docking.widgets.dialogs.StringChoices;
|
import docking.widgets.dialogs.StringChoices;
|
||||||
import docking.widgets.table.AbstractSortedTableModel;
|
import docking.widgets.table.AbstractSortedTableModel;
|
||||||
|
import docking.widgets.table.GTable;
|
||||||
import ghidra.app.LocationCallback;
|
import ghidra.app.LocationCallback;
|
||||||
import ghidra.app.context.ListingActionContext;
|
import ghidra.app.context.ListingActionContext;
|
||||||
import ghidra.app.events.ProgramLocationPluginEvent;
|
import ghidra.app.events.ProgramLocationPluginEvent;
|
||||||
import ghidra.app.events.ProgramSelectionPluginEvent;
|
import ghidra.app.events.ProgramSelectionPluginEvent;
|
||||||
import ghidra.app.plugin.core.clear.ClearCmd;
|
import ghidra.app.plugin.core.clear.ClearCmd;
|
||||||
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
|
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.data.DataSettingsDialog.SettingsRowObject;
|
||||||
import ghidra.app.plugin.core.navigation.NextPrevAddressPlugin;
|
import ghidra.app.plugin.core.navigation.NextPrevAddressPlugin;
|
||||||
import ghidra.docking.settings.FormatSettingsDefinition;
|
import ghidra.docking.settings.FormatSettingsDefinition;
|
||||||
@@ -134,6 +140,7 @@ public abstract class AbstractDataActionTest extends AbstractGhidraHeadedIntegra
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
|
closeAllWindows();
|
||||||
env.dispose();
|
env.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,15 +262,20 @@ public abstract class AbstractDataActionTest extends AbstractGhidraHeadedIntegra
|
|||||||
int settingsCol = model.findColumn("Settings");
|
int settingsCol = model.findColumn("Settings");
|
||||||
int rowCnt = model.getRowCount();
|
int rowCnt = model.getRowCount();
|
||||||
|
|
||||||
for (int i = 0; i < rowCnt; i++) {
|
for (int row = 0; row < rowCnt; row++) {
|
||||||
String name = (String) model.getValueAt(i, nameCol);
|
String name = (String) model.getValueAt(row, nameCol);
|
||||||
int index = findSettingIndex(settingNames, name);
|
int index = findSettingIndex(settingNames, name);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
Object v = model.getValueAt(i, settingsCol);
|
Object v = model.getValueAt(row, settingsCol);
|
||||||
if (v instanceof StringChoices) {
|
if (v instanceof StringChoices) {
|
||||||
StringChoices choices = (StringChoices) v;
|
StringChoices choices = (StringChoices) v;
|
||||||
|
|
||||||
|
triggerEdit(dlg, row, settingsCol);
|
||||||
|
setComboValue(dlg, newValues[index]);
|
||||||
|
endEdit(dlg);
|
||||||
|
|
||||||
choices.setSelectedValue(newValues[index]);
|
choices.setSelectedValue(newValues[index]);
|
||||||
model.setValueAt(choices, i, settingsCol);
|
model.setValueAt(choices, row, settingsCol);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error = "Unsupported test setting: " + v.getClass();
|
error = "Unsupported test setting: " + v.getClass();
|
||||||
@@ -283,6 +295,44 @@ public abstract class AbstractDataActionTest extends AbstractGhidraHeadedIntegra
|
|||||||
waitForSwing();
|
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) {
|
protected int findSettingIndex(String[] settingNames, String name) {
|
||||||
for (int i = 0; i < settingNames.length; i++) {
|
for (int i = 0; i < settingNames.length; i++) {
|
||||||
if (settingNames[i].equals(name)) {
|
if (settingNames[i].equals(name)) {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package docking.widgets.table;
|
package docking.widgets.table;
|
||||||
|
|
||||||
import static docking.DockingUtils.CONTROL_KEY_MODIFIER_MASK;
|
import static docking.DockingUtils.*;
|
||||||
import static docking.action.MenuData.NO_MNEMONIC;
|
import static docking.action.MenuData.*;
|
||||||
import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
|
import static java.awt.event.InputEvent.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
@@ -69,7 +69,6 @@ import resources.ResourceManager;
|
|||||||
*
|
*
|
||||||
* @see GTableFilterPanel
|
* @see GTableFilterPanel
|
||||||
*/
|
*/
|
||||||
// Suppress - we are using the deprecated reference to DefaultSortedTableModel to handle old code
|
|
||||||
public class GTable extends JTable implements KeyStrokeConsumer, DockingActionProviderIf {
|
public class GTable extends JTable implements KeyStrokeConsumer, DockingActionProviderIf {
|
||||||
|
|
||||||
private static final String LAST_EXPORT_FILE = "LAST_EXPORT_DIR";
|
private static final String LAST_EXPORT_FILE = "LAST_EXPORT_DIR";
|
||||||
|
|||||||
Reference in New Issue
Block a user