68
68
*/
69
69
public abstract class CompositeEditorPanel extends JPanel
70
70
implements CompositeEditorModelListener , ComponentCellEditorListener , Draggable , Droppable {
71
- private static final long serialVersionUID = 1L ;
71
+
72
72
// Normal color for selecting components in the table.
73
73
// TODO: Why do we choose a different selection color?
74
74
//private static final Color SELECTION_COLOR = Color.YELLOW.brighter().brighter();
@@ -179,12 +179,12 @@ private void setupTableCellEditor() {
179
179
table .addPropertyChangeListener ("tableCellEditor" , evt -> {
180
180
TableCellEditor fieldEditor = (TableCellEditor ) evt .getNewValue ();
181
181
if (fieldEditor == null ) {
182
- // Ending cell edit.
183
- SwingUtilities . invokeLater (() -> model .endEditingField ());
182
+ // Ending cell edit
183
+ Swing . runLater (() -> model .endEditingField ());
184
184
}
185
185
else {
186
- // Starting cell edit.
187
- SwingUtilities . invokeLater (() -> {
186
+ // Starting cell edit
187
+ Swing . runLater (() -> {
188
188
int editingRow = table .getEditingRow ();
189
189
if (editingRow < 0 ) {
190
190
return ;
@@ -255,11 +255,11 @@ protected void startCellEditing(int row, int viewColumn) {
255
255
public void moveCellEditor (final int direction , final String value ) {
256
256
stopCellEditing ();
257
257
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
259
259
// 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
261
261
// event, then the focusLost() will trigger our new edit to be cancelled.
262
- SwingUtilities . invokeLater (() -> doMoveCellEditor (direction , value ));
262
+ Swing . runLater (() -> doMoveCellEditor (direction , value ));
263
263
}
264
264
265
265
private void doMoveCellEditor (int direction , String value ) {
@@ -457,8 +457,10 @@ protected boolean editBelowField() {
457
457
}
458
458
459
459
/**
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
462
464
*/
463
465
protected boolean editNextField (int currentRow ) {
464
466
if (locateNextEditField (currentRow )) {
@@ -479,13 +481,6 @@ protected boolean editPreviousField(int currentRow) {
479
481
return false ;
480
482
}
481
483
482
- /* (non-Javadoc)
483
- * @see ghidra.app.plugin.compositeeditor.CompositeEditorModelListener#lockStateChanged(int)
484
- */
485
- public void lockStateChanged (int type ) {
486
- // no-op
487
- }
488
-
489
484
/**
490
485
* Scrolls the table so that the table cell indicated becomes viewable.
491
486
* @param rowIndex the row of the table cell
@@ -585,7 +580,15 @@ private void createTable() {
585
580
if (e .getValueIsAdjusting ()) {
586
581
return ;
587
582
}
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
+ }
589
592
});
590
593
591
594
JPanel tablePanel = new JPanel (new BorderLayout ());
@@ -870,23 +873,14 @@ public Transferable getTransferable(Point p) {
870
873
return new DataTypeTransferable (dt );
871
874
}
872
875
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
- */
882
876
@ Override
883
877
public boolean isDropOk (DropTargetDragEvent e ) {
884
878
return true ;
885
879
}
886
880
887
881
/**
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.
890
884
*
891
885
* @param obj Transferable object that is to be dropped.
892
886
* @param e has current state of drop operation
@@ -913,13 +907,11 @@ public void add(Object obj, DropTargetDropEvent e, DataFlavor f) {
913
907
}
914
908
915
909
/**
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.
918
912
*
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
923
915
*/
924
916
public void insertAtPoint (Point p , DataType dt ) {
925
917
endFieldEditing (); // Make sure a field isn't being edited.
@@ -934,13 +926,11 @@ public void insertAtPoint(Point p, DataType dt) {
934
926
}
935
927
936
928
/**
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
944
934
*/
945
935
public void addAtPoint (Point p , DataType dt ) {
946
936
endFieldEditing (); // Make sure a field isn't being edited.
@@ -1217,10 +1207,6 @@ public ComponentNameCellEditor() {
1217
1207
super (new JTextField ());
1218
1208
}
1219
1209
1220
- /**
1221
- * Calls <code>fireEditingStopped</code> and returns true.
1222
- * @return true
1223
- */
1224
1210
@ Override
1225
1211
public boolean stopCellEditing () {
1226
1212
try {
@@ -1238,7 +1224,7 @@ public boolean stopCellEditing() {
1238
1224
1239
1225
private class ComponentDataTypeCellEditor extends AbstractCellEditor
1240
1226
implements TableCellEditor {
1241
- private static final long serialVersionUID = 1L ;
1227
+
1242
1228
private DataTypeSelectionEditor editor ;
1243
1229
private DataType dt ;
1244
1230
private int maxLength ;
@@ -1295,8 +1281,6 @@ public void editingStopped(ChangeEvent e) {
1295
1281
1296
1282
// force a small button for the table's cell editor
1297
1283
JButton dataTypeChooserButton = new JButton ("..." ) {
1298
- private static final long serialVersionUID = 1L ;
1299
-
1300
1284
@ Override
1301
1285
public Dimension getPreferredSize () {
1302
1286
Dimension preferredSize = super .getPreferredSize ();
@@ -1305,28 +1289,22 @@ public Dimension getPreferredSize() {
1305
1289
}
1306
1290
};
1307
1291
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 ));
1317
1296
}
1318
- }));
1319
- FocusAdapter focusListener = new FocusAdapter () {
1297
+ });
1298
+
1299
+ textField .addFocusListener (new FocusAdapter () {
1320
1300
@ Override
1321
1301
public void focusGained (FocusEvent e ) {
1322
1302
textField .selectAll ();
1323
1303
textField .removeFocusListener (this );
1324
1304
}
1325
- };
1326
- textField .addFocusListener (focusListener );
1305
+ });
1327
1306
1328
1307
editorPanel = new JPanel () {
1329
-
1330
1308
@ Override
1331
1309
public void requestFocus () {
1332
1310
textField .requestFocus ();
@@ -1337,6 +1315,18 @@ public void requestFocus() {
1337
1315
editorPanel .add (dataTypeChooserButton , BorderLayout .EAST );
1338
1316
}
1339
1317
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
+
1340
1330
@ Override
1341
1331
public Object getCellEditorValue () {
1342
1332
return dt ;
@@ -1503,7 +1493,7 @@ public CompositeTable(TableModel dm) {
1503
1493
// overridden because the editor component was not being given focus
1504
1494
public Component prepareEditor (TableCellEditor editor , int row , int column ) {
1505
1495
final Component component = super .prepareEditor (editor , row , column );
1506
- SwingUtilities . invokeLater (() -> component .requestFocus ());
1496
+ Swing . runLater (() -> component .requestFocus ());
1507
1497
return component ;
1508
1498
}
1509
1499
}
0 commit comments