Ghidra is a software reverse engineering (SRE) framework
GT-3308 - Structure Editor - review fixes
dragonmacher24b0a6cac1fe
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.javaindex b0c71433a9..7bdafa4d5c 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java@@ -68,7 +68,7 @@ import ghidra.util.layout.VerticalLayout;*/public abstract class CompositeEditorPanel extends JPanelimplements CompositeEditorModelListener, ComponentCellEditorListener, Draggable, Droppable {- private static final long serialVersionUID = 1L;+// Normal color for selecting components in the table.// TODO: Why do we choose a different selection color?//private static final Color SELECTION_COLOR = Color.YELLOW.brighter().brighter();@@ -255,7 +255,7 @@ public abstract class CompositeEditorPanel extends JPanelpublic void moveCellEditor(final int direction, final String value) {stopCellEditing();- // Note: We run this later due to focus dependencies (SCR 6915). When we call+ // Note: We run this later due to focus dependencies. When we call// stopCellEditing() this will trigger a focusLost() event, which itself happens in// a Swing.runLater(). If we do not trigger the moving of the cell editor after that focus// event, then the focusLost() will trigger our new edit to be cancelled.@@ -481,10 +481,6 @@ public abstract class CompositeEditorPanel extends JPanelreturn false;}- public void lockStateChanged(int type) {- // no-op- }-/*** Scrolls the table so that the table cell indicated becomes viewable.* @param rowIndex the row of the table cell@@ -884,7 +880,7 @@ public abstract class CompositeEditorPanel extends JPanel/*** Add the object to the droppable component. The DragSrcAdapter calls this method from its- * drop() method+ * drop() method.** @param obj Transferable object that is to be dropped.* @param e has current state of drop operation@@ -931,7 +927,7 @@ public abstract class CompositeEditorPanel extends JPanel/*** Add the object to the droppable component. The DragSrcAdapter calls this method from its- * drop() method+ * drop() method.** @param p the point of insert* @param dt the data type to insert@@ -1211,10 +1207,6 @@ public abstract class CompositeEditorPanel extends JPanelsuper(new JTextField());}- /**- * Calls <code>fireEditingStopped</code> and returns true.- * @return true- */@Overridepublic boolean stopCellEditing() {try {@@ -1232,7 +1224,7 @@ public abstract class CompositeEditorPanel extends JPanelprivate class ComponentDataTypeCellEditor extends AbstractCellEditorimplements TableCellEditor {- private static final long serialVersionUID = 1L;+private DataTypeSelectionEditor editor;private DataType dt;private int maxLength;@@ -1289,8 +1281,6 @@ public abstract class CompositeEditorPanel extends JPanel// force a small button for the table's cell editorJButton dataTypeChooserButton = new JButton("...") {- private static final long serialVersionUID = 1L;-@Overridepublic Dimension getPreferredSize() {Dimension preferredSize = super.getPreferredSize();@@ -1299,28 +1289,22 @@ public abstract class CompositeEditorPanel extends JPanel}};- dataTypeChooserButton.addActionListener(e -> Swing.runLater(() -> {- DataTypeManagerService service = tool.getService(DataTypeManagerService.class);- DataType dataType = service.getDataType((String) null);- if (dataType != null) {- editor.setCellEditorValue(dataType);- editor.stopCellEditing();- }- else {- editor.cancelCellEditing();+ dataTypeChooserButton.addActionListener(new ActionListener() {+ @Override+ public void actionPerformed(ActionEvent e) {+ Swing.runLater(() -> stopEdit(tool));}- }));- FocusAdapter focusListener = new FocusAdapter() {+ });++ textField.addFocusListener(new FocusAdapter() {@Overridepublic void focusGained(FocusEvent e) {textField.selectAll();textField.removeFocusListener(this);}- };- textField.addFocusListener(focusListener);+ });editorPanel = new JPanel() {-@Overridepublic void requestFocus() {textField.requestFocus();@@ -1331,6 +1315,18 @@ public abstract class CompositeEditorPanel extends JPaneleditorPanel.add(dataTypeChooserButton, BorderLayout.EAST);}+ private void stopEdit(PluginTool tool) {+ DataTypeManagerService service = tool.getService(DataTypeManagerService.class);+ DataType dataType = service.getDataType((String) null);+ if (dataType != null) {+ editor.setCellEditorValue(dataType);+ editor.stopCellEditing();+ }+ else {+ editor.cancelCellEditing();+ }+ }+@Overridepublic Object getCellEditorValue() {return dt;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.javaindex b3538adb40..5d1debdf18 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java@@ -17,6 +17,7 @@ package ghidra.app.plugin.core.compositeeditor;import java.math.BigInteger;import java.util.ArrayList;+import java.util.List;import javax.swing.table.AbstractTableModel;@@ -47,9 +48,9 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManagerprotected Composite viewComposite;protected DataTypeManager viewDTM;- protected ArrayList<CompositeViewerModelListener> modelListeners = new ArrayList<>(1);+ protected List<CompositeViewerModelListener> modelListeners = new ArrayList<>();/** OriginalCompositeListeners */- protected ArrayList<OriginalCompositeListener> originalListeners = new ArrayList<>(1);+ protected List<OriginalCompositeListener> originalListeners = new ArrayList<>();/** the current status */protected String status = "";/** The selection associated with the components. */@@ -459,8 +460,8 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager}/**- * Gets the component display field widths- * @return the offsets+ * Gets the component display field offsets+ * @return the offsets*/int[] getFieldOffsets() {return columnOffsets;@@ -480,7 +481,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager}/**- * Adjusts the total width of the component field area.+ * Adjusts the total width of the component field area*/private void adjustWidth() {int newWidth = leftMargin;@@ -492,16 +493,16 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager}/**- * Gets the component display field area's total width.+ * Gets the component display field area's total width*- * @return the total width of the component field area.+ * @return the total width of the component field area*/public int getWidth() {return width;}/**- * Gets the display width of the component field at the specified column index.+ * Gets the display width of the component field at the specified column index** @param columnIndex the field index within the component.* @return the width of the component field.@@ -511,49 +512,6 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager: columnWidths[columnIndex]);}- /**- * Sets the component display width for the field- *- * @param width the width of the component field- * @param columnIndex the field index within the component- * @return true if the width changed- */- boolean setFieldWidth(int width, int columnIndex) {- if (columnIndex >= 0 && columnIndex < getColumnCount()) {- columnWidths[columnIndex] = width;- adjustWidth();- adjustOffsets();- fireTableDataChanged();- componentDataChanged();- return true;- }- return false;- }-- /**- * Gets the component display field widths.- *- * @return an array indicating each component field's width.- */- public int[] getFieldWidths() {- return columnWidths;- }-- /**- * Sets the component display field widths- *- * @param widths an array indicating each component field's width- * @return true- */- boolean setFieldWidths(int[] widths) {- int numCols = getColumnCount();- for (int i = 0; i < numCols && i < widths.length; i++) {- columnWidths[i] = widths[i];- }- adjustWidth();- return true;- }-/*** Returns the number of component rows in the viewer. There may be a* blank row at the end for selecting. Therefore this number can be@@ -838,13 +796,6 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManagerreturn originalDataTypePath;}- /*******************************************************************- * CategoryChangeListener methods.- ********************************************************************/-- /**- * @see ghidra.program.model.data.DataTypeManagerChangeListener#categoryAdded(ghidra.program.model.data.DataTypeManager, ghidra.program.model.data.CategoryPath)- */@Overridepublic void categoryAdded(DataTypeManager dtm, CategoryPath path) {// new categories don't matter@@ -1153,7 +1104,7 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManagerDataType subDt = component.getDataType();String subDtPath = subDt.getPathName();- if (subDtPath.equals(dtPath)) {+ if (subDtPath.equals(dtPath.getPath())) {return true;}else if (subDt instanceof Composite) {@@ -1466,9 +1417,6 @@ class CompositeViewerModel extends AbstractTableModel implements DataTypeManager: ("-" + prefix + Integer.toHexString(-offset)));}- // **********************************************************************- // * METHODS FOR THE ROW- // **********************************************************************/*** If there is a selection, this changes the row to the minimum row selected.*/