29
29
import ghidra .util .exception .*;
30
30
import ghidra .util .task .TaskMonitor ;
31
31
32
- public abstract class CompEditorModel extends CompositeEditorModel {
32
+ public abstract class CompEditorModel < T extends Composite > extends CompositeEditorModel < T > {
33
33
34
34
private volatile boolean consideringReplacedDataType = false ;
35
35
36
36
/**
37
37
* Creates a model for editing a composite data type.
38
38
* @param provider the provider that is using this model for editing.
39
39
*/
40
- CompEditorModel (CompositeEditorProvider provider ) {
40
+ CompEditorModel (CompositeEditorProvider < T , ? extends CompEditorModel < T >> provider ) {
41
41
super (provider );
42
42
}
43
43
@@ -54,7 +54,7 @@ public boolean hasChanges() {
54
54
* @param dataType the composite data type being edited.
55
55
*/
56
56
@ Override
57
- public void load (Composite dataType ) {
57
+ public void load (T dataType ) {
58
58
super .load (dataType );
59
59
fixSelection ();
60
60
selectionChanged ();
@@ -76,7 +76,7 @@ public boolean apply() throws InvalidDataTypeException {
76
76
}
77
77
78
78
FieldSelection saveSelection = new FieldSelection (selection );
79
- Composite originalDt = getOriginalComposite ();
79
+ T originalDt = getOriginalComposite ();
80
80
if (originalDt == null || originalDTM == null ) {
81
81
throw new IllegalStateException (
82
82
"Can't apply edits without a data type or data type manager." );
@@ -118,7 +118,8 @@ public boolean apply() throws InvalidDataTypeException {
118
118
load (originalDt );
119
119
}
120
120
else {
121
- Composite dt = (Composite ) originalDTM .resolve (viewComposite , null );
121
+ @ SuppressWarnings ("unchecked" )
122
+ T dt = (T ) originalDTM .resolve (viewComposite , null );
122
123
load (dt );
123
124
}
124
125
return true ;
@@ -376,7 +377,6 @@ protected void deleteComponent(int rowIndex) {
376
377
int componentOrdinal = convertRowToOrdinal (rowIndex );
377
378
delete (componentOrdinal );
378
379
fixSelection ();
379
- componentEdited ();
380
380
selectionChanged ();
381
381
}
382
382
@@ -411,8 +411,6 @@ void deleteComponentRange(int startRowIndex, int endRowIndex, TaskMonitor monito
411
411
}
412
412
viewDTM .withTransaction ("Delete Components" , () -> viewComposite .delete (ordinals ));
413
413
fixSelection ();
414
- componentEdited ();
415
- notifyCompositeChanged ();
416
414
selectionChanged ();
417
415
}
418
416
@@ -427,12 +425,7 @@ public void deleteSelectedComponents() throws UsrException {
427
425
428
426
int [] selectedComponents = getSelectedComponentRows ();
429
427
int firstRowIndex = !selection .isEmpty () ? selectedComponents [0 ] : getRowCount ();
430
- try {
431
- delete (selectedComponents );
432
- }
433
- finally {
434
- componentEdited ();
435
- }
428
+ delete (selectedComponents );
436
429
selection .addRange (firstRowIndex , firstRowIndex + 1 );
437
430
fixSelection ();
438
431
selectionChanged ();
@@ -532,7 +525,6 @@ public DataTypeComponent insert(int rowIndex, DataType datatype, int length)
532
525
}
533
526
DataTypeComponent dtc = insert (rowIndex , datatype , length , null , null );
534
527
fixSelection ();
535
- componentEdited ();
536
528
selectionChanged ();
537
529
return dtc ;
538
530
}
@@ -562,7 +554,6 @@ protected void insertComponentMultiple(int rowIndex, DataType dataType, int dtLe
562
554
checkIsAllowableDataType (dataType );
563
555
insertMultiple (rowIndex , dataType , dtLen , multiple , monitor );
564
556
fixSelection ();
565
- componentEdited ();
566
557
selectionChanged ();
567
558
}
568
559
@@ -601,7 +592,7 @@ public DataTypeComponent add(int rowIndex, DataType dt) throws UsrException {
601
592
});
602
593
603
594
fixSelection ();
604
- componentEdited ();
595
+ // componentEdited();
605
596
selectionChanged ();
606
597
return dtc ;
607
598
}
@@ -637,7 +628,7 @@ public DataTypeComponent add(int rowIndex, DataType dt, int dtLength) throws Usr
637
628
}
638
629
639
630
fixSelection ();
640
- componentEdited ();
631
+ // componentEdited();
641
632
selectionChanged ();
642
633
return dtc ;
643
634
}
@@ -753,7 +744,6 @@ public DataTypeComponent replace(int rowIndex, DataType datatype, int length)
753
744
replace (rowIndex , datatype , newCompSize , oldDtc .getFieldName (), oldDtc .getComment ());
754
745
755
746
fixSelection ();
756
- componentEdited ();
757
747
selectionChanged ();
758
748
return dtc ;
759
749
}
@@ -806,7 +796,6 @@ protected DataTypeComponent replaceComponentRange(int startRowIndex, int endRowI
806
796
}
807
797
dtc .setComment (oldDtc .getComment ());
808
798
fixSelection ();
809
- componentEdited ();
810
799
selectionChanged ();
811
800
return dtc ;
812
801
}
@@ -994,7 +983,6 @@ public boolean moveUp() throws NoSuchElementException {
994
983
int newIndex = startIndex - 1 ;
995
984
moved = shiftComponentsUp (startIndex , endIndex );
996
985
if (moved ) {
997
- componentEdited ();
998
986
FieldSelection tmpFieldSelection = new FieldSelection ();
999
987
tmpFieldSelection .addRange (newIndex , newIndex + numSelected );
1000
988
setSelection (tmpFieldSelection );
@@ -1018,7 +1006,6 @@ public boolean moveDown() throws NoSuchElementException {
1018
1006
int newIndex = startIndex + 1 ;
1019
1007
moved = shiftComponentsDown (startIndex , endIndex );
1020
1008
if (moved ) {
1021
- componentEdited ();
1022
1009
FieldSelection tmpFieldSelection = new FieldSelection ();
1023
1010
tmpFieldSelection .addRange (newIndex , newIndex + numSelected );
1024
1011
setSelection (tmpFieldSelection );
@@ -1038,7 +1025,6 @@ public void duplicateMultiple(int rowIndex, int multiple, TaskMonitor monitor)
1038
1025
// Adjust the selection since we added some components. Select last component added.
1039
1026
setSelection (new int [] { rowIndex + multiple });
1040
1027
1041
- componentEdited ();
1042
1028
lastNumDuplicates = multiple ;
1043
1029
}
1044
1030
@@ -1143,9 +1129,7 @@ public int getRowCount() {
1143
1129
public void setValueAt (Object aValue , int rowIndex , int modelColumnIndex ) {
1144
1130
try {
1145
1131
settingValueAt = true ;
1146
- if (fieldEdited (aValue , rowIndex , modelColumnIndex )) {
1147
- componentEdited ();
1148
- }
1132
+ fieldEdited (aValue , rowIndex , modelColumnIndex );
1149
1133
}
1150
1134
finally {
1151
1135
settingValueAt = false ;
@@ -1284,7 +1268,7 @@ public void restored(DataTypeManager dataTypeManager) {
1284
1268
return ;
1285
1269
}
1286
1270
1287
- Composite composite = getOriginalComposite ();
1271
+ T composite = getOriginalComposite ();
1288
1272
boolean reload = true ;
1289
1273
if (hasChanges || !viewComposite .isEquivalent (composite )) {
1290
1274
hasChanges = true ;
@@ -1323,7 +1307,11 @@ public void restored(DataTypeManager dataTypeManager) {
1323
1307
public void dataTypeRemoved (DataTypeManager dtm , DataTypePath path ) {
1324
1308
1325
1309
if (dtm != originalDTM ) {
1326
- return ; // Different DTM than the one for this data type.
1310
+ throw new AssertException ("Listener only supports original DTM" );
1311
+ }
1312
+
1313
+ if (!isLoaded ()) {
1314
+ return ;
1327
1315
}
1328
1316
1329
1317
DataType dataType = viewDTM .getDataType (path .getCategoryPath (), path .getDataTypeName ());
@@ -1380,7 +1368,7 @@ public void dataTypeRemoved(DataTypeManager dtm, DataTypePath path) {
1380
1368
public void dataTypeRenamed (DataTypeManager dtm , DataTypePath oldPath , DataTypePath newPath ) {
1381
1369
1382
1370
if (dtm != originalDTM ) {
1383
- return ; // Different DTM than the one for this data type.
1371
+ throw new AssertException ( "Listener only supports original DTM" );
1384
1372
}
1385
1373
1386
1374
if (!isLoaded ()) {
@@ -1434,7 +1422,11 @@ public void dataTypeRenamed(DataTypeManager dtm, DataTypePath oldPath, DataTypeP
1434
1422
public void dataTypeMoved (DataTypeManager dtm , DataTypePath oldPath , DataTypePath newPath ) {
1435
1423
1436
1424
if (dtm != originalDTM ) {
1437
- return ; // Different DTM than the one for this data type.
1425
+ throw new AssertException ("Listener only supports original DTM" );
1426
+ }
1427
+
1428
+ if (!isLoaded ()) {
1429
+ return ;
1438
1430
}
1439
1431
1440
1432
DataType dt = viewDTM .getDataType (oldPath );
@@ -1468,20 +1460,14 @@ public void dataTypeMoved(DataTypeManager dtm, DataTypePath oldPath, DataTypePat
1468
1460
public void dataTypeChanged (DataTypeManager dtm , DataTypePath path ) {
1469
1461
try {
1470
1462
1471
- if (! isLoaded () ) {
1472
- return ;
1463
+ if (dtm != originalDTM ) {
1464
+ throw new AssertException ( "Listener only supports original DTM" ) ;
1473
1465
}
1474
1466
1475
- if (dtm instanceof CompositeViewerDataTypeManager ) {
1476
- // required to detect settings changes
1477
- componentEdited ();
1467
+ if (!isLoaded ()) {
1478
1468
return ;
1479
1469
}
1480
1470
1481
- if (dtm != originalDTM ) {
1482
- return ; // Different DTM than the one for this data type.
1483
- }
1484
-
1485
1471
// If we don't currently have any modifications that need applying and
1486
1472
// the structure in the editor just changed, then show the changed
1487
1473
// structure.
@@ -1566,7 +1552,7 @@ public void dataTypeReplaced(DataTypeManager dtm, DataTypePath oldPath, DataType
1566
1552
DataType newDataType ) {
1567
1553
1568
1554
if (dtm != originalDTM ) {
1569
- return ; // Different DTM than the one for this data type.
1555
+ throw new AssertException ( "Listener only supports original DTM" );
1570
1556
}
1571
1557
1572
1558
if (!isLoaded ()) {
@@ -1723,15 +1709,6 @@ public int getLastNumDuplicates() {
1723
1709
return lastNumDuplicates ;
1724
1710
}
1725
1711
1726
- /**
1727
- * Called whenever the data structure's modification state changes.
1728
- */
1729
- void componentEdited () {
1730
- updateAndCheckChangeState (); // Update the composite's change state information.
1731
- fireTableDataChanged ();
1732
- componentDataChanged ();
1733
- }
1734
-
1735
1712
protected int convertRowToOrdinal (int rowIndex ) {
1736
1713
return rowIndex ;
1737
1714
}
0 commit comments