2929import ghidra .util .exception .*;
3030import ghidra .util .task .TaskMonitor ;
3131
32- public abstract class CompEditorModel extends CompositeEditorModel {
32+ public abstract class CompEditorModel < T extends Composite > extends CompositeEditorModel < T > {
3333
3434 private volatile boolean consideringReplacedDataType = false ;
3535
3636 /**
3737 * Creates a model for editing a composite data type.
3838 * @param provider the provider that is using this model for editing.
3939 */
40- CompEditorModel (CompositeEditorProvider provider ) {
40+ CompEditorModel (CompositeEditorProvider < T , ? extends CompEditorModel < T >> provider ) {
4141 super (provider );
4242 }
4343
@@ -54,7 +54,7 @@ public boolean hasChanges() {
5454 * @param dataType the composite data type being edited.
5555 */
5656 @ Override
57- public void load (Composite dataType ) {
57+ public void load (T dataType ) {
5858 super .load (dataType );
5959 fixSelection ();
6060 selectionChanged ();
@@ -76,7 +76,7 @@ public boolean apply() throws InvalidDataTypeException {
7676 }
7777
7878 FieldSelection saveSelection = new FieldSelection (selection );
79- Composite originalDt = getOriginalComposite ();
79+ T originalDt = getOriginalComposite ();
8080 if (originalDt == null || originalDTM == null ) {
8181 throw new IllegalStateException (
8282 "Can't apply edits without a data type or data type manager." );
@@ -118,7 +118,8 @@ public boolean apply() throws InvalidDataTypeException {
118118 load (originalDt );
119119 }
120120 else {
121- Composite dt = (Composite ) originalDTM .resolve (viewComposite , null );
121+ @ SuppressWarnings ("unchecked" )
122+ T dt = (T ) originalDTM .resolve (viewComposite , null );
122123 load (dt );
123124 }
124125 return true ;
@@ -376,7 +377,6 @@ protected void deleteComponent(int rowIndex) {
376377 int componentOrdinal = convertRowToOrdinal (rowIndex );
377378 delete (componentOrdinal );
378379 fixSelection ();
379- componentEdited ();
380380 selectionChanged ();
381381 }
382382
@@ -411,8 +411,6 @@ void deleteComponentRange(int startRowIndex, int endRowIndex, TaskMonitor monito
411411 }
412412 viewDTM .withTransaction ("Delete Components" , () -> viewComposite .delete (ordinals ));
413413 fixSelection ();
414- componentEdited ();
415- notifyCompositeChanged ();
416414 selectionChanged ();
417415 }
418416
@@ -427,12 +425,7 @@ public void deleteSelectedComponents() throws UsrException {
427425
428426 int [] selectedComponents = getSelectedComponentRows ();
429427 int firstRowIndex = !selection .isEmpty () ? selectedComponents [0 ] : getRowCount ();
430- try {
431- delete (selectedComponents );
432- }
433- finally {
434- componentEdited ();
435- }
428+ delete (selectedComponents );
436429 selection .addRange (firstRowIndex , firstRowIndex + 1 );
437430 fixSelection ();
438431 selectionChanged ();
@@ -532,7 +525,6 @@ public DataTypeComponent insert(int rowIndex, DataType datatype, int length)
532525 }
533526 DataTypeComponent dtc = insert (rowIndex , datatype , length , null , null );
534527 fixSelection ();
535- componentEdited ();
536528 selectionChanged ();
537529 return dtc ;
538530 }
@@ -562,7 +554,6 @@ protected void insertComponentMultiple(int rowIndex, DataType dataType, int dtLe
562554 checkIsAllowableDataType (dataType );
563555 insertMultiple (rowIndex , dataType , dtLen , multiple , monitor );
564556 fixSelection ();
565- componentEdited ();
566557 selectionChanged ();
567558 }
568559
@@ -601,7 +592,7 @@ public DataTypeComponent add(int rowIndex, DataType dt) throws UsrException {
601592 });
602593
603594 fixSelection ();
604- componentEdited ();
595+ // componentEdited();
605596 selectionChanged ();
606597 return dtc ;
607598 }
@@ -637,7 +628,7 @@ public DataTypeComponent add(int rowIndex, DataType dt, int dtLength) throws Usr
637628 }
638629
639630 fixSelection ();
640- componentEdited ();
631+ // componentEdited();
641632 selectionChanged ();
642633 return dtc ;
643634 }
@@ -753,7 +744,6 @@ public DataTypeComponent replace(int rowIndex, DataType datatype, int length)
753744 replace (rowIndex , datatype , newCompSize , oldDtc .getFieldName (), oldDtc .getComment ());
754745
755746 fixSelection ();
756- componentEdited ();
757747 selectionChanged ();
758748 return dtc ;
759749 }
@@ -806,7 +796,6 @@ protected DataTypeComponent replaceComponentRange(int startRowIndex, int endRowI
806796 }
807797 dtc .setComment (oldDtc .getComment ());
808798 fixSelection ();
809- componentEdited ();
810799 selectionChanged ();
811800 return dtc ;
812801 }
@@ -994,7 +983,6 @@ public boolean moveUp() throws NoSuchElementException {
994983 int newIndex = startIndex - 1 ;
995984 moved = shiftComponentsUp (startIndex , endIndex );
996985 if (moved ) {
997- componentEdited ();
998986 FieldSelection tmpFieldSelection = new FieldSelection ();
999987 tmpFieldSelection .addRange (newIndex , newIndex + numSelected );
1000988 setSelection (tmpFieldSelection );
@@ -1018,7 +1006,6 @@ public boolean moveDown() throws NoSuchElementException {
10181006 int newIndex = startIndex + 1 ;
10191007 moved = shiftComponentsDown (startIndex , endIndex );
10201008 if (moved ) {
1021- componentEdited ();
10221009 FieldSelection tmpFieldSelection = new FieldSelection ();
10231010 tmpFieldSelection .addRange (newIndex , newIndex + numSelected );
10241011 setSelection (tmpFieldSelection );
@@ -1038,7 +1025,6 @@ public void duplicateMultiple(int rowIndex, int multiple, TaskMonitor monitor)
10381025 // Adjust the selection since we added some components. Select last component added.
10391026 setSelection (new int [] { rowIndex + multiple });
10401027
1041- componentEdited ();
10421028 lastNumDuplicates = multiple ;
10431029 }
10441030
@@ -1143,9 +1129,7 @@ public int getRowCount() {
11431129 public void setValueAt (Object aValue , int rowIndex , int modelColumnIndex ) {
11441130 try {
11451131 settingValueAt = true ;
1146- if (fieldEdited (aValue , rowIndex , modelColumnIndex )) {
1147- componentEdited ();
1148- }
1132+ fieldEdited (aValue , rowIndex , modelColumnIndex );
11491133 }
11501134 finally {
11511135 settingValueAt = false ;
@@ -1284,7 +1268,7 @@ public void restored(DataTypeManager dataTypeManager) {
12841268 return ;
12851269 }
12861270
1287- Composite composite = getOriginalComposite ();
1271+ T composite = getOriginalComposite ();
12881272 boolean reload = true ;
12891273 if (hasChanges || !viewComposite .isEquivalent (composite )) {
12901274 hasChanges = true ;
@@ -1323,7 +1307,11 @@ public void restored(DataTypeManager dataTypeManager) {
13231307 public void dataTypeRemoved (DataTypeManager dtm , DataTypePath path ) {
13241308
13251309 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 ;
13271315 }
13281316
13291317 DataType dataType = viewDTM .getDataType (path .getCategoryPath (), path .getDataTypeName ());
@@ -1380,7 +1368,7 @@ public void dataTypeRemoved(DataTypeManager dtm, DataTypePath path) {
13801368 public void dataTypeRenamed (DataTypeManager dtm , DataTypePath oldPath , DataTypePath newPath ) {
13811369
13821370 if (dtm != originalDTM ) {
1383- return ; // Different DTM than the one for this data type.
1371+ throw new AssertException ( "Listener only supports original DTM" );
13841372 }
13851373
13861374 if (!isLoaded ()) {
@@ -1434,7 +1422,11 @@ public void dataTypeRenamed(DataTypeManager dtm, DataTypePath oldPath, DataTypeP
14341422 public void dataTypeMoved (DataTypeManager dtm , DataTypePath oldPath , DataTypePath newPath ) {
14351423
14361424 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 ;
14381430 }
14391431
14401432 DataType dt = viewDTM .getDataType (oldPath );
@@ -1468,20 +1460,14 @@ public void dataTypeMoved(DataTypeManager dtm, DataTypePath oldPath, DataTypePat
14681460 public void dataTypeChanged (DataTypeManager dtm , DataTypePath path ) {
14691461 try {
14701462
1471- if (! isLoaded () ) {
1472- return ;
1463+ if (dtm != originalDTM ) {
1464+ throw new AssertException ( "Listener only supports original DTM" ) ;
14731465 }
14741466
1475- if (dtm instanceof CompositeViewerDataTypeManager ) {
1476- // required to detect settings changes
1477- componentEdited ();
1467+ if (!isLoaded ()) {
14781468 return ;
14791469 }
14801470
1481- if (dtm != originalDTM ) {
1482- return ; // Different DTM than the one for this data type.
1483- }
1484-
14851471 // If we don't currently have any modifications that need applying and
14861472 // the structure in the editor just changed, then show the changed
14871473 // structure.
@@ -1566,7 +1552,7 @@ public void dataTypeReplaced(DataTypeManager dtm, DataTypePath oldPath, DataType
15661552 DataType newDataType ) {
15671553
15681554 if (dtm != originalDTM ) {
1569- return ; // Different DTM than the one for this data type.
1555+ throw new AssertException ( "Listener only supports original DTM" );
15701556 }
15711557
15721558 if (!isLoaded ()) {
@@ -1723,15 +1709,6 @@ public int getLastNumDuplicates() {
17231709 return lastNumDuplicates ;
17241710 }
17251711
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-
17351712 protected int convertRowToOrdinal (int rowIndex ) {
17361713 return rowIndex ;
17371714 }
0 commit comments