Ghidra is a software reverse engineering (SRE) framework
GP-2945 - Updated the structure editor to maintain selection during external updates
dragonmacher2d2b2b87719c
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.javaindex 71f8eac863..3621575fde 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java@@ -80,7 +80,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {@Overridepublic boolean apply() throws InvalidDataTypeException {- // commit changes for any fields under edit+ // commit changes for any fields under editif (isEditingField()) {endFieldEditing();}@@ -135,7 +135,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {//==================================================================================================// OVERRIDDEN METHODS FOR THE SELECTION-//==================================================================================================+//==================================================================================================/*** Returns true if the GUI has the blank last line selected@@ -341,12 +341,12 @@ public abstract class CompEditorModel extends CompositeEditorModel {/*** Delete the components at the specified indices.- *+ ** <br> Note: this method does not fix the selection based on lock mode* and does not perform any edit notification.** @param rows array with each row (component) index to delete- * @throws CancelledException if cancelled+ * @throws CancelledException if cancelled*/private void delete(int[] rows) throws CancelledException {@@ -366,7 +366,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {viewComposite.delete(rowSet);- // Not sure if this is the right behavior. Assuming the deleted rows were selected,+ // Not sure if this is the right behavior. Assuming the deleted rows were selected,// restore the selection to be the first row that was deleted so that the UI leaves the// user's selection close to where it was.if (rows.length > 0) {@@ -401,7 +401,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {* @param startRowIndex index of the starting row for the components to delete.* @param endRowIndex index of the ending row (inclusive) for the components to delete.* @param monitor the task monitor- * @throws CancelledException if the work was cancelled+ * @throws CancelledException if the work was cancelled*/void deleteComponentRange(int startRowIndex, int endRowIndex, TaskMonitor monitor)throws CancelledException {@@ -456,13 +456,13 @@ public abstract class CompEditorModel extends CompositeEditorModel {/*** Inserts a new datatype at the specified index into this composite* and adjusts the selection.- * @param rowIndex the index where the new datatype is to be inserted.+ * @param rowIndex the index where the new datatype is to be inserted.* @param dataType the datatype to insert.* @param length the length to associate with the datatype.* @param name the field name to associate with this component.* @param comment the comment to associate with this component.* @return the componentDataType created.- * @throws InvalidDataTypeException if the dataType.getLength() is positive+ * @throws InvalidDataTypeException if the dataType.getLength() is positive* and does not match the given length parameter.*/protected abstract DataTypeComponent insert(int rowIndex, DataType dataType, int length,@@ -520,7 +520,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {/*** Insert the named data type before the specified index.- * Returns null, if the inserted component is an Undefined byte+ * Returns null, if the inserted component is an Undefined byte* and it gets consumed by the component before it.** @param rowIndex index of the row (component).@@ -685,7 +685,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {/*** Replaces the current component at the specified index with one that- * is the indicated data type and size. It also sets the new component's+ * is the indicated data type and size. It also sets the new component's* name and comment as indicated.* @param rowIndex the index of row where the data type should be replaced.* @param dataType the new datatype.@@ -693,7 +693,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {* @param name the field name to associate with this component.* @param comment the comment to associate with this component.* @return the componentDataType created.- * @throws InvalidDataTypeException if the dataType.getLength() is positive+ * @throws InvalidDataTypeException if the dataType.getLength() is positive* and does not match the given length parameter.*/protected abstract DataTypeComponent replace(int rowIndex, DataType dataType, int length,@@ -793,10 +793,10 @@ public abstract class CompEditorModel extends CompositeEditorModel {checkIsAllowableDataType(datatype);//- // Note: if the range being replaced is large enough, then the UI could lock-up. If we- // find that is the case, then we can update this method to take in a task monitor+ // Note: if the range being replaced is large enough, then the UI could lock-up. If we+ // find that is the case, then we can update this method to take in a task monitor// and update the clients accordingly. For now, it does not seem worth the effort.- //+ //TaskMonitor monitor = TaskMonitor.DUMMY;replaceRange(startRowIndex, endRowIndex, datatype, length, monitor);@@ -862,8 +862,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {protected abstract void replaceOriginalComponents();@Override- protected void checkIsAllowableDataType(DataType datatype)- throws InvalidDataTypeException {+ protected void checkIsAllowableDataType(DataType datatype) throws InvalidDataTypeException {super.checkIsAllowableDataType(datatype);@@ -1082,7 +1081,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {* until the end of the composite. There must be at least one undefined data type to return true.** @param rowIndex the index of the row to begin checking for undefined data types.- * @return true if an undefined data type is at the indicated row index and all components+ * @return true if an undefined data type is at the indicated row index and all components* from there to the end of the composite are undefined data types.*/protected boolean onlyUndefinedsUntilEnd(int rowIndex) {@@ -1111,7 +1110,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {* Cause the component at the specified index to consume undefined bytes* that follow it.* Note: this method adjusts the selection.- *+ ** @param rowIndex the row index* @return the number of Undefined bytes consumed.*/@@ -1299,13 +1298,9 @@ public abstract class CompEditorModel extends CompositeEditorModel {(selection.getFieldRange(0).getEnd().getIndex().intValue() < getNumComponents()));}-//==================================================================================================-// End of methods for determining if a type of edit action is allowed.-//==================================================================================================-//==================================================================================================// Override CompositeViewerModel CategoryChangeListener methods-//==================================================================================================+//==================================================================================================@Overridepublic void dataTypeChanged(DataTypeManager dtm, DataTypePath path) {@@ -1340,8 +1335,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {return;}// Return if the original is already changing. Need this since there- // can be multiple change notifications from a single data type update- // event due to replaceWith(), setLastChangeTime() and+ // can be multiple change notifications from a single data type update+ // event due to replaceWith(), setLastChangeTime() and// setLastChangeTimeInSource() each firing dataTypeChanged().if (originalIsChanging) {return;@@ -1430,8 +1425,8 @@ public abstract class CompEditorModel extends CompositeEditorModel {"\", which is a sub-component of \"" + getOriginalDataTypeName() + "\".";setStatus(msg, true);}- // NOTE: depending upon event sequence and handling a- // re-load may have occured and replcement may be uneccessary+ // NOTE: depending upon event sequence and handling a+ // re-load may have occurred and replacement may be unnecessarytry {viewDTM.replaceDataType(dt, newDataType, true);}@@ -1492,7 +1487,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {//==================================================================================================// End of Override CompositeViewerModel CategoryChangeListener methods-//==================================================================================================+//==================================================================================================@Overridepublic void fireTableDataChanged() {@@ -1504,9 +1499,9 @@ public abstract class CompEditorModel extends CompositeEditorModel {}/**- * Determine the maximum number of duplicates that can be created for+ * Determine the maximum number of duplicates that can be created for* the component at the indicated index. The duplicates would follow- * the component. The number allowed depends on how many fit based on+ * the component. The number allowed depends on how many fit based on* the current lock/unlock state of the editor.* <br>Note: This method doesn't care whether there is a selection or not.*@@ -1524,7 +1519,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {}DataType dt = getComponent(rowIndex).getDataType();int maxDups = Integer.MAX_VALUE;- // If editModel is showing undefined bytes (non-packed)+ // If editModel is showing undefined bytes (non-packed)// then constrain by number of undefined bytes that follow.if (isShowingUndefinedBytes() && (dt != DataType.DEFAULT)) {int numBytes = getNumUndefinedBytesAt(rowIndex + 1);@@ -1534,7 +1529,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {}/**- * Determine the maximum number of array elements that can be created for+ * Determine the maximum number of array elements that can be created for* the current selection. The array data type is assumed to become the* data type of the first component in the selection. The current selection* must be contiguous or 0 is returned.@@ -1578,7 +1573,7 @@ public abstract class CompEditorModel extends CompositeEditorModel {}/**- * Return the last number of duplicates the user entered when prompted for+ * Return the last number of duplicates the user entered when prompted for* creating duplicates of a component.*/@Overridediff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.javaindex a7d63a4f85..c0e0e8f37a 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorModel.java@@ -44,7 +44,7 @@ import ghidra.util.exception.*;public abstract class CompositeEditorModel extends CompositeViewerModel implements EditorModel {/**- * Whether or not an apply is occurring. Need to ignore changes to the+ * Whether or not an apply is occurring. Need to ignore changes to the* original structure, if apply is causing them.*/protected boolean applyingFieldEdit = false;@@ -85,6 +85,8 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen"Datatype " + dataType.getName() + " doesn't have a data type manager specified.");}+ long lastCompositeId = originalCompositeId;+if (isEditingField()) {endFieldEditing();}@@ -111,7 +113,12 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemenoriginalDTM.addDataTypeManagerListener(this);hadChanges = false;- setSelection(new FieldSelection());++ if (lastCompositeId != originalCompositeId) {+ // only clear the selection if loading a new type+ setSelection(new FieldSelection());+ }+clearStatus();compositeInfoChanged();fireTableDataChanged();@@ -121,9 +128,9 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen}/**- * Create view composite with the appropriate datatype manager and+ * Create view composite with the appropriate datatype manager and* changes listener(s) if required.- *+ ** @param original original composite being loaded* @return view composite to used by model*/@@ -136,10 +143,10 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen// Clone all settings some of which do not get resolved.- // NOTE: It is important to note that the editor will allow modification of component- // default settings, however the underlying datatype default settings may not get copied+ // NOTE: It is important to note that the editor will allow modification of component+ // default settings, however the underlying datatype default settings may not get copied// as they get resolved into the view datatype manager. This may result in the incorrect- // underlying datatype default setting value being presented when adjusting component+ // underlying datatype default setting value being presented when adjusting component// default settings.cloneAllComponentSettings(original, composite);@@ -180,7 +187,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen* @param rowIndex index of the row (component)* @param dt the data type to be placed at the row index* @return a new data type instance- * @throws InvalidDataTypeException if the resulting data type is not allowed to be+ * @throws InvalidDataTypeException if the resulting data type is not allowed to be* added at the indicated index* @throws CancelledException if cancelled*/@@ -253,7 +260,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen* Gets called to update/validate the current editable location in the table.* @param value the new cell value* @param rowIndex the index of the row in the component table.- * @param columnIndex the column index for the table cell in the+ * @param columnIndex the column index for the table cell in the* current model.* @return true if the field was updated or validated successfully.*/@@ -289,7 +296,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen//==================================================================================================// METHODS FOR CHANGING THE COMPOSITE-//==================================================================================================+//==================================================================================================/*** Called whenever the edit state of the data structure changes.@@ -308,7 +315,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen* Sets the name for the structure being edited.** @param name the new name.- *+ ** @throws DuplicateNameException if the name already exists.*/@Override@@ -433,11 +440,11 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen}/**- * Resolves the data type against the indicated data type manager using the specified- * conflictHandler. Transactions should have already been initiated prior to calling this- * method. If not then override this method to perform the transaction code around the+ * Resolves the data type against the indicated data type manager using the specified+ * conflictHandler. Transactions should have already been initiated prior to calling this+ * method. If not then override this method to perform the transaction code around the* resolve.- *+ ** @param dt the data type to be resolved* @param resolveDtm the data type manager to resolve the data type against* @param conflictHandler the handler to be used for any conflicts encountered while resolving@@ -693,7 +700,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen//==================================================================================================// METHODS FOR THE FIELD EDITING-//==================================================================================================+//==================================================================================================@Overridepublic boolean beginEditingField(int rowIndex, int columnIndex) {@@ -777,10 +784,10 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen}/**- * This gets the next data type in the cycle that fits in place of the+ * This gets the next data type in the cycle that fits in place of the* currently selected component. If the currently selected component's data- * type is not in the cycle group, then the first data type that fits from- * the cycle group is returned. If no new data type from the cycle group+ * type is not in the cycle group, then the first data type that fits from+ * the cycle group is returned. If no new data type from the cycle group* fits at the selected component, null is returned.** @param cycleGroup the cycle group of data types to choose from.@@ -854,13 +861,12 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen/*** Determine if the data type is a valid one to place into the current structure being edited.* If invalid, an exception will be thrown.- *+ ** @param datatype the data type* @throws InvalidDataTypeException if the structure being edited is part* of the data type being inserted or doesn't have a valid size.*/- protected void checkIsAllowableDataType(DataType datatype)- throws InvalidDataTypeException {+ protected void checkIsAllowableDataType(DataType datatype) throws InvalidDataTypeException {if (!allowsZeroLengthComponents() && DataTypeComponent.usesZeroLengthComponent(datatype)) {throw new InvalidDataTypeException("Zero-length datatype not permitted: " + datatype.getName());@@ -1024,9 +1030,9 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen}/**- * If the component at the indicated index is a composite data type,+ * If the component at the indicated index is a composite data type,* this gets the number of components that it contains.- *+ ** @param rowIndex the index of the component in the editor.* @return the number of sub-components or 0.*/@@ -1080,7 +1086,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen//==================================================================================================// End of methods for determining if a type of edit action is allowed-//==================================================================================================+//==================================================================================================/*** Saves the current selection in the structure components viewing area.@@ -1105,7 +1111,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen}// Normally if the user makes a new selection, we want to end any field editing- // that is in progress, but if we are fixing up the selection during a beginEdit+ // that is in progress, but if we are fixing up the selection during a beginEdit// then don't end field editing since we are in a transition state.if (!stillBeginningEdit) {endFieldEditing();diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.javaindex 723575d198..1dd01ba698 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java@@ -246,6 +246,10 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration});}+ protected int[] getSelection() {+ return runSwing(() -> getTable().getSelectedRows());+ }+private String arrayToString(int[] values) {StringBuilder buf = new StringBuilder();for (int value : values) {diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.javaindex 17fb3850ce..6974325e8b 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java@@ -37,7 +37,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {try {DataTypeManager dataTypeManager = cat.getDataTypeManager();if (dt.getDataTypeManager() != dataTypeManager) {- dt = (Structure) dt.clone(dataTypeManager);+ dt = dt.clone(dataTypeManager);}CategoryPath categoryPath = cat.getCategoryPath();if (!dt.getCategoryPath().equals(categoryPath)) {@@ -59,7 +59,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {model = provider.getModel();// model.setLocked(false);});-// assertTrue(!model.isLocked());+// assertFalse(model.isLocked());getActions();}@@ -123,7 +123,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}});waitForSwing();- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));// Apply the changesinvoke(applyAction);@@ -137,7 +137,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {deleteAction.actionPerformed(new ActionContext());// Must be undefined before it can delete.});waitForSwing();- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));// Undo the applyundo(program, false);@@ -147,7 +147,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {pressButton(dialog, "No");dialog.dispose();dialog = null;- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));// Redo the applyredo(program, false);@@ -157,7 +157,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {pressButton(dialog, "No");dialog.dispose();dialog = null;- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));}finally {dialog = null;@@ -208,7 +208,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}});waitForSwing();- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));// Verify the editor provider is displayed.String mySubTitle = getProviderSubTitle(myS1Structure);@@ -224,7 +224,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {assertNull(dialog);// Verify the editor provider is gone.- assertTrue(!isProviderShown(tool.getToolFrame(), "Structure Editor", mySubTitle));+ assertFalse(isProviderShown(tool.getToolFrame(), "Structure Editor", mySubTitle));}finally {dialog = null;@@ -232,7 +232,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}}- // Test add a structure containing inner struct, start to edit inner struct, and then undo the+ // Test add a structure containing inner struct, start to edit inner struct, and then undo the// program so it goes away. This should close the edit session.@Testpublic void testProgramRestoreRemovesEditedDtComp() throws Exception {@@ -279,7 +279,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}}, false);waitForSwing();- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));// Verify the editor provider is displayed.String mySubTitle = getProviderSubTitle(myS2Structure);@@ -295,7 +295,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {assertNull(dialog);// Verify the editor provider is gone.- assertTrue(!isProviderShown(tool.getToolFrame(), "Structure Editor", mySubTitle));+ assertFalse(isProviderShown(tool.getToolFrame(), "Structure Editor", mySubTitle));}finally {dialog = null;@@ -303,7 +303,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}}- // Test add a structure, start to edit a structure that contains it, and then undo the program+ // Test add a structure, start to edit a structure that contains it, and then undo the program// so it goes away. The editor stays since the structure existed previously, but editor reloads.@Testpublic void testProgramRestoreRemovesEditedComponentDtYes() throws Exception {@@ -343,7 +343,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}});waitForSwing();- assertTrue(!emptyStructure.isEquivalent(model.viewComposite));+ assertFalse(emptyStructure.isEquivalent(model.viewComposite));// Verify the editor provider is displayed.String mySubTitle = getProviderSubTitle(emptyStructure);@@ -371,7 +371,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}}- // Test add a structure, start to edit a structure that contains it, and then undo the program+ // Test add a structure, start to edit a structure that contains it, and then undo the program// so it goes away. The editor stays since the structure existed previously, but doesn't reload.@Testpublic void testProgramRestoreRemovesEditedComponentDtNo() throws Exception {@@ -411,7 +411,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}});waitForSwing();- assertTrue(!emptyStructure.isEquivalent(model.viewComposite));+ assertFalse(emptyStructure.isEquivalent(model.viewComposite));// Verify the editor provider is displayed.String mySubTitle = getProviderSubTitle(emptyStructure);@@ -426,7 +426,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {pressButton(dialog, "No");dialog.dispose();dialog = null;- assertTrue(!emptyStructure.isEquivalent(model.viewComposite));+ assertFalse(emptyStructure.isEquivalent(model.viewComposite));// Verify the editor provider is still on screen.assertTrue(@@ -459,7 +459,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}});waitForSwing();- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));// Apply the changesinvoke(applyAction);assertTrue(complexStructure.isEquivalent(model.viewComposite));@@ -491,7 +491,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {runSwing(() -> provider.closeComponent());- assertTrue(!tool.isVisible(provider));+ assertFalse(tool.isVisible(provider));assertTrue(complexStructure.isEquivalent(dt));}@@ -515,7 +515,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {});waitForSwing();DataType newDt = model.viewComposite.clone(null);- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));assertTrue(complexStructure.isEquivalent(oldDt));runSwing(() -> provider.closeComponent(), false);@@ -525,15 +525,15 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {assertNotNull(dialog);pressButton(dialog, "Yes");dialog.dispose();- dialog = null;- assertTrue(!tool.isVisible(provider));++ assertFalse(tool.isVisible(provider));assertTrue(complexStructure.isEquivalent(newDt));- assertTrue(!complexStructure.isEquivalent(oldDt));+ assertFalse(complexStructure.isEquivalent(oldDt));}@Testpublic void testCloseEditorAndNoSave() throws Exception {- Window dialog;+init(complexStructure, pgmTestCat, false);DataType oldDt = model.viewComposite.clone(null);@@ -551,18 +551,10 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}, false);waitForSwing();DataType newDt = model.viewComposite.clone(null);- assertTrue(!complexStructure.isEquivalent(model.viewComposite));-- runSwingLater(() -> provider.closeComponent());- waitForSwing();+ assertFalse(complexStructure.isEquivalent(model.viewComposite));- dialog = waitForWindow("Save Structure Editor Changes?");- assertNotNull(dialog);- pressButton(dialog, "No");- dialog.dispose();- dialog = null;- assertTrue(!tool.isVisible(provider));- assertTrue(!complexStructure.isEquivalent(newDt));+ closeProviderIgnoringChanges();+ assertFalse(complexStructure.isEquivalent(newDt));assertTrue(complexStructure.isEquivalent(oldDt));}@@ -585,7 +577,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {});waitForSwing();DataType newDt = model.viewComposite.clone(null);- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));runSwingLater(() -> provider.closeComponent());waitForSwing();@@ -596,7 +588,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {dialog.dispose();dialog = null;assertTrue(tool.isVisible(provider));- assertTrue(!complexStructure.isEquivalent(model.viewComposite));+ assertFalse(complexStructure.isEquivalent(model.viewComposite));assertTrue(newDt.isEquivalent(model.viewComposite));}@@ -702,7 +694,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {waitForBusyTool(tool);waitForSwing();// Editor should be closed.- assertTrue(!tool.isVisible(provider));+ assertFalse(tool.isVisible(provider));assertTrue(complexStructure.isEquivalent(oldDt));// Re-open the editor@@ -740,7 +732,7 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {waitForBusyTool(tool);waitForSwing();// Editor should be closed.- assertTrue(!tool.isVisible(provider));+ assertFalse(tool.isVisible(provider));assertTrue(complexStructure.isEquivalent(oldDt));// Re-open the editorinit(complexStructure, pgmTestCat, false);@@ -755,4 +747,52 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {assertEquals("325", model.getLengthAsString());}+ @Test+ public void testExternalChangeMaintainsSelection() throws Exception {+ env.showTool();+ runSwing(() -> {+ installProvider(new StructureEditorProvider(plugin, complexStructure, false));+ model = provider.getModel();+ });++ assertNotNull(provider);+ assertTrue(tool.isVisible(provider));+ assertTrue(complexStructure.isEquivalent(model.viewComposite));++ Composite dt = model.viewComposite;++ // set selected row+ int row = 2;+ setSelection(new int[] { row });++ // update data type+ int editRow = 4; // offset 8; 'simpleUnion'+ String newFieldName = "newFieldName";+ tx(program, () -> {+ DataTypeComponent dtc = dt.getComponent(editRow);+ dtc.setFieldName(newFieldName);+ });++ // verify editor is updated+ assertEquals(newFieldName, model.getValueAt(editRow, model.getNameColumn()));++ // verify selection has not changed+ int[] rows = getSelection();+ assertEquals(1, rows.length);+ assertEquals(row, rows[0]);++ closeProviderIgnoringChanges();+ }++ private void closeProviderIgnoringChanges() {++ runSwingLater(() -> provider.closeComponent());++ Window dialog = waitForWindow("Save Structure Editor Changes?");+ assertNotNull(dialog);+ pressButton(dialog, "No");+ dialog.dispose();++ assertFalse(tool.isVisible(provider));+ }}diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Composite.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Composite.javaindex 434372e963..650d66f541 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Composite.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/data/Composite.java@@ -57,7 +57,7 @@ public interface Composite extends DataType {/*** Returns an array of Data Type Components that make up this composite including- * undefined filler components which may be present within a Structure whch has packing disabled.+ * undefined filler components which may be present within a Structure which has packing disabled.* The number of components corresponds to {@link #getNumComponents()}.* @return array all components*/