Skip to content

Commit dff40c5

Browse files
committed
Merge remote-tracking branch
'origin/GT-3308-dragonmacher-structure-editor-F2-with-arrow-keys' (fixes NationalSecurityAgency#703 again)
2 parents 91bd142 + 24b0a6c commit dff40c5

File tree

5 files changed

+195
-230
lines changed

5 files changed

+195
-230
lines changed

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
*/
6969
public abstract class CompositeEditorPanel extends JPanel
7070
implements CompositeEditorModelListener, ComponentCellEditorListener, Draggable, Droppable {
71-
private static final long serialVersionUID = 1L;
71+
7272
// Normal color for selecting components in the table.
7373
// TODO: Why do we choose a different selection color?
7474
//private static final Color SELECTION_COLOR = Color.YELLOW.brighter().brighter();
@@ -179,12 +179,12 @@ private void setupTableCellEditor() {
179179
table.addPropertyChangeListener("tableCellEditor", evt -> {
180180
TableCellEditor fieldEditor = (TableCellEditor) evt.getNewValue();
181181
if (fieldEditor == null) {
182-
// Ending cell edit.
183-
SwingUtilities.invokeLater(() -> model.endEditingField());
182+
// Ending cell edit
183+
Swing.runLater(() -> model.endEditingField());
184184
}
185185
else {
186-
// Starting cell edit.
187-
SwingUtilities.invokeLater(() -> {
186+
// Starting cell edit
187+
Swing.runLater(() -> {
188188
int editingRow = table.getEditingRow();
189189
if (editingRow < 0) {
190190
return;
@@ -255,11 +255,11 @@ protected void startCellEditing(int row, int viewColumn) {
255255
public void moveCellEditor(final int direction, final String value) {
256256
stopCellEditing();
257257

258-
// Note: We perform an invokeLater here due to focus dependencies (SCR 6915). When we call
258+
// Note: We run this later due to focus dependencies. When we call
259259
// stopCellEditing() this will trigger a focusLost() event, which itself happens in
260-
// an invokeLater(). If we do not trigger the moving of the cell editor after that focus
260+
// a Swing.runLater(). If we do not trigger the moving of the cell editor after that focus
261261
// event, then the focusLost() will trigger our new edit to be cancelled.
262-
SwingUtilities.invokeLater(() -> doMoveCellEditor(direction, value));
262+
Swing.runLater(() -> doMoveCellEditor(direction, value));
263263
}
264264

265265
private void doMoveCellEditor(int direction, String value) {
@@ -457,8 +457,10 @@ protected boolean editBelowField() {
457457
}
458458

459459
/**
460-
* Puts the next editable cell into edit mode.
461-
* @return true if there was a table cell that could be edited.
460+
* Puts the next editable cell into edit mode
461+
*
462+
* @param currentRow the current row
463+
* @return true if there was a table cell that could be edited
462464
*/
463465
protected boolean editNextField(int currentRow) {
464466
if (locateNextEditField(currentRow)) {
@@ -479,13 +481,6 @@ protected boolean editPreviousField(int currentRow) {
479481
return false;
480482
}
481483

482-
/* (non-Javadoc)
483-
* @see ghidra.app.plugin.compositeeditor.CompositeEditorModelListener#lockStateChanged(int)
484-
*/
485-
public void lockStateChanged(int type) {
486-
// no-op
487-
}
488-
489484
/**
490485
* Scrolls the table so that the table cell indicated becomes viewable.
491486
* @param rowIndex the row of the table cell
@@ -585,7 +580,15 @@ private void createTable() {
585580
if (e.getValueIsAdjusting()) {
586581
return;
587582
}
588-
model.setColumn(e.getFirstIndex());
583+
584+
TableColumnModel cm = table.getColumnModel();
585+
int[] selected = cm.getSelectedColumns();
586+
if (selected.length == 1) {
587+
model.setColumn(selected[0]);
588+
}
589+
else {
590+
model.setColumn(-1);
591+
}
589592
});
590593

591594
JPanel tablePanel = new JPanel(new BorderLayout());
@@ -870,23 +873,14 @@ public Transferable getTransferable(Point p) {
870873
return new DataTypeTransferable(dt);
871874
}
872875

873-
/**
874-
* Return true if it is OK to drop the transferable at the location
875-
* specified by the event.
876-
* Data Types can only be dropped on undefined bytes in locked state
877-
* and only if they fit there.
878-
*
879-
* @param e event that has current state of drag and drop operation
880-
* @param obj the DataType being dropped
881-
*/
882876
@Override
883877
public boolean isDropOk(DropTargetDragEvent e) {
884878
return true;
885879
}
886880

887881
/**
888-
* Add the object to the droppable component. The DragSrcAdapter
889-
* calls this method from its drop() method.
882+
* Add the object to the droppable component. The DragSrcAdapter calls this method from its
883+
* drop() method.
890884
*
891885
* @param obj Transferable object that is to be dropped.
892886
* @param e has current state of drop operation
@@ -913,13 +907,11 @@ public void add(Object obj, DropTargetDropEvent e, DataFlavor f) {
913907
}
914908

915909
/**
916-
* Add the object to the droppable component. The DragSrcAdapter
917-
* calls this method from its drop() method.
910+
* Add the object to the droppable component. The DragSrcAdapter calls this method from its
911+
* drop() method.
918912
*
919-
* @param obj Transferable object that is to be dropped.
920-
* @param e has current state of drop operation
921-
* @param f represents the opaque concept of a data format as
922-
* would appear on a clipboard, during drag and drop.
913+
* @param p the point of insert
914+
* @param dt the data type to insert
923915
*/
924916
public void insertAtPoint(Point p, DataType dt) {
925917
endFieldEditing(); // Make sure a field isn't being edited.
@@ -934,13 +926,11 @@ public void insertAtPoint(Point p, DataType dt) {
934926
}
935927

936928
/**
937-
* Add the object to the droppable component. The DragSrcAdapter
938-
* calls this method from its drop() method.
939-
*
940-
* @param obj Transferable object that is to be dropped.
941-
* @param e has current state of drop operation
942-
* @param f represents the opaque concept of a data format as
943-
* would appear on a clipboard, during drag and drop.
929+
* Add the object to the droppable component. The DragSrcAdapter calls this method from its
930+
* drop() method.
931+
*
932+
* @param p the point of insert
933+
* @param dt the data type to insert
944934
*/
945935
public void addAtPoint(Point p, DataType dt) {
946936
endFieldEditing(); // Make sure a field isn't being edited.
@@ -1217,10 +1207,6 @@ public ComponentNameCellEditor() {
12171207
super(new JTextField());
12181208
}
12191209

1220-
/**
1221-
* Calls <code>fireEditingStopped</code> and returns true.
1222-
* @return true
1223-
*/
12241210
@Override
12251211
public boolean stopCellEditing() {
12261212
try {
@@ -1238,7 +1224,7 @@ public boolean stopCellEditing() {
12381224

12391225
private class ComponentDataTypeCellEditor extends AbstractCellEditor
12401226
implements TableCellEditor {
1241-
private static final long serialVersionUID = 1L;
1227+
12421228
private DataTypeSelectionEditor editor;
12431229
private DataType dt;
12441230
private int maxLength;
@@ -1295,8 +1281,6 @@ public void editingStopped(ChangeEvent e) {
12951281

12961282
// force a small button for the table's cell editor
12971283
JButton dataTypeChooserButton = new JButton("...") {
1298-
private static final long serialVersionUID = 1L;
1299-
13001284
@Override
13011285
public Dimension getPreferredSize() {
13021286
Dimension preferredSize = super.getPreferredSize();
@@ -1305,28 +1289,22 @@ public Dimension getPreferredSize() {
13051289
}
13061290
};
13071291

1308-
dataTypeChooserButton.addActionListener(e -> SwingUtilities.invokeLater(() -> {
1309-
DataTypeManagerService service = tool.getService(DataTypeManagerService.class);
1310-
DataType dataType = service.getDataType((String) null);
1311-
if (dataType != null) {
1312-
editor.setCellEditorValue(dataType);
1313-
editor.stopCellEditing();
1314-
}
1315-
else {
1316-
editor.cancelCellEditing();
1292+
dataTypeChooserButton.addActionListener(new ActionListener() {
1293+
@Override
1294+
public void actionPerformed(ActionEvent e) {
1295+
Swing.runLater(() -> stopEdit(tool));
13171296
}
1318-
}));
1319-
FocusAdapter focusListener = new FocusAdapter() {
1297+
});
1298+
1299+
textField.addFocusListener(new FocusAdapter() {
13201300
@Override
13211301
public void focusGained(FocusEvent e) {
13221302
textField.selectAll();
13231303
textField.removeFocusListener(this);
13241304
}
1325-
};
1326-
textField.addFocusListener(focusListener);
1305+
});
13271306

13281307
editorPanel = new JPanel() {
1329-
13301308
@Override
13311309
public void requestFocus() {
13321310
textField.requestFocus();
@@ -1337,6 +1315,18 @@ public void requestFocus() {
13371315
editorPanel.add(dataTypeChooserButton, BorderLayout.EAST);
13381316
}
13391317

1318+
private void stopEdit(PluginTool tool) {
1319+
DataTypeManagerService service = tool.getService(DataTypeManagerService.class);
1320+
DataType dataType = service.getDataType((String) null);
1321+
if (dataType != null) {
1322+
editor.setCellEditorValue(dataType);
1323+
editor.stopCellEditing();
1324+
}
1325+
else {
1326+
editor.cancelCellEditing();
1327+
}
1328+
}
1329+
13401330
@Override
13411331
public Object getCellEditorValue() {
13421332
return dt;
@@ -1503,7 +1493,7 @@ public CompositeTable(TableModel dm) {
15031493
// overridden because the editor component was not being given focus
15041494
public Component prepareEditor(TableCellEditor editor, int row, int column) {
15051495
final Component component = super.prepareEditor(editor, row, column);
1506-
SwingUtilities.invokeLater(() -> component.requestFocus());
1496+
Swing.runLater(() -> component.requestFocus());
15071497
return component;
15081498
}
15091499
}

0 commit comments

Comments
 (0)