Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3352 - Structure Editor - 'Delete Selected Components' put into a task to not lock-up the UI

dragonmacher291e61b0c6f6
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.java
index 1adb158953..da96dea155 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
@@ -257,15 +257,6 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
}
- /**
- * Validates that the data type indicated by the string can be set as the data type
- * at the indicated row index. If the named data type can be various sizes, this
- * method will prompt the user.
- * @param rowIndex the row index
- * @param dtString the string representing the data type.
- * @return a valid data type instance or null if at blank line with no data type name.
- * @throws UsrException indicating that the data type is not valid.
- */
@Override
public DataTypeInstance validateComponentDataType(int rowIndex, String dtString)
throws UsrException {
@@ -348,19 +339,28 @@ 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.
+ * @param rows array with each row (component) index to delete
+ * @param monitor the task monitor
+ * @throws CancelledException if cancelled
*/
- private void delete(int[] rows) {
+ private void delete(int[] rows, TaskMonitor monitor) throws CancelledException {
+
+ int n = rows.length;
+ monitor.initialize(n);
int[] selectedRows = getSelectedRows();
Arrays.sort(rows);
for (int i = rows.length - 1; i >= 0; i--) {
+ monitor.checkCanceled();
+ monitor.setMessage("Deleting " + (n - i + 1) + " of " + n);
int rowIndex = rows[i];
int componentOrdinal = convertRowToOrdinal(rowIndex);
doDelete(componentOrdinal);
+ monitor.incrementProgress(1);
}
// Not sure if this is the right behavior. Assuming the deleted rows were selected,
@@ -430,17 +430,22 @@ public abstract class CompEditorModel extends CompositeEditorModel {
}
@Override
- public void deleteSelectedComponents() throws UsrException {
+ public void deleteSelectedComponents(TaskMonitor monitor) throws UsrException {
if (!isDeleteAllowed()) {
throw new UsrException("Deleting is not allowed.");
}
if (isEditingField()) {
endFieldEditing();
}
+
int[] selectedComponents = getSelectedComponentRows();
int firstRowIndex = !selection.isEmpty() ? selectedComponents[0] : getRowCount();
- delete(selectedComponents);
- componentEdited();
+ try {
+ delete(selectedComponents, monitor);
+ }
+ finally {
+ componentEdited();
+ }
selection.addRange(firstRowIndex, firstRowIndex + 1);
fixSelection();
selectionChanged();
diff --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.java
index 368a61232f..5e817b55f4 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
@@ -35,6 +35,7 @@ import ghidra.program.model.data.*;
import ghidra.program.model.data.Enum;
import ghidra.util.*;
import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
/**
* Model for editing a composite data type. Specific composite data type editors
@@ -157,16 +158,15 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
}
/**
- * Gets the data type of the appropriate size to be placed at the
- * indicated component index.
+ * Gets the data type of the appropriate size to be placed at the indicated component index
*
- * @param rowIndex index of the row (component).
- * @param datatype the data type to be placed at the row index.
+ * @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
- * added at the indicated index.
+ * added at the indicated index
+ * @throws CancelledException if cancelled
*/
-
protected DataTypeInstance getDropDataType(int rowIndex, DataType dt)
throws InvalidDataTypeException, CancelledException {
@@ -240,7 +240,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 mColumn 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.
*/
@@ -274,9 +274,10 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
}
}
- // **********************************************************************
- // * METHODS FOR CHANGING THE COMPOSITE
- // **********************************************************************
+//==================================================================================================
+// METHODS FOR CHANGING THE COMPOSITE
+//==================================================================================================
+
/**
* Called whenever the edit state of the data structure changes.
*
@@ -347,9 +348,6 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
editorStateChanged(type);
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#setComponentDataType(int, java.lang.Object)
- */
@Override
public void setComponentDataType(int rowIndex, Object dataTypeObject) throws UsrException {
DataType previousDt = null;
@@ -431,11 +429,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
return resolveDtm.resolve(dt, conflictHandler);
}
- /**
- *
- * @param rows
- * @throws UsrException if clearing isn't allowed.
- */
+ @SuppressWarnings("unused") // the exception is thrown by subclasses1d
protected void clearComponents(int[] rows) throws UsrException {
for (int i = rows.length - 1; i >= 0; i--) {
clearComponent(rows[i]);
@@ -510,11 +504,6 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
return false;
}
- /**
- * Transform the specified component row into a flexible array if permitted
- * @param rowIndex existing component row index
- * @throws UsrException
- */
protected void convertToFlexibleArray(int rowIndex) throws UsrException {
throw new UsrException("Flexible array not permitted");
}
@@ -557,13 +546,8 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
clearComponents(getSelectedComponentRows());
}
- /**
- * Delete the selected components.
- *
- * @throws UsrException if the data type isn't allowed to be deleted.
- */
@Override
- public void deleteSelectedComponents() throws UsrException {
+ public void deleteSelectedComponents(TaskMonitor monitor) throws UsrException {
if (!isDeleteAllowed()) {
throw new UsrException("Deleting is not allowed.");
}
@@ -583,9 +567,12 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
* an offline data type manager instance. In other words, changes to the data type
* being edited don't directly affect the original data type manager is unaffected
* until editor changes are applied.
- * <br> If this returns false, then the editor directly affects the original
+ *
+ * <p>If this returns false, then the editor directly affects the original
* data type manager. For example, as data types are added to the composite data type,
* they are also added to the original data type manager if not already there.
+ *
+ * @return true if editing offline
*/
public boolean isOffline() {
return offline;
@@ -622,11 +609,6 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
return hadChanges;
}
- /**
- * @param currentViewComposite
- * @param oldComposite
- * @return
- */
private boolean hasCompPathNameChanges(Composite currentViewComposite, Composite oldComposite) {
// Check component data type pathnames.
DataTypeComponent[] comps = currentViewComposite.getComponents();
@@ -651,16 +633,15 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
componentDataChanged();
}
- // **********************************************************************
- // * METHODS FOR THE FIELD EDITING
- // **********************************************************************
- /**
- * Change the edit state to indicate editing the specified field.
- */
+//==================================================================================================
+// METHODS FOR THE FIELD EDITING
+//==================================================================================================
+
@Override
public boolean beginEditingField(int rowIndex, int columnIndex) {
- if (isEditingField())
+ if (isEditingField()) {
return false;
+ }
try {
stillBeginningEdit = true; // We want to know we are still beginning an edit when we fix the selection.
editingField = true;
@@ -674,32 +655,21 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
return true;
}
- /**
- * Change the edit state to indicate no longer editing a field.
- */
@Override
public boolean endEditingField() {
- if (!isEditingField())
+ if (!isEditingField()) {
return false;
+ }
editingField = false;
notifyEditingChanged();
return true;
}
- /**
- * Returns whether the user is currently editing a field's value.
- */
@Override
public boolean isEditingField() {
return !settingValueAt && editingField;
}
- /**
- * Gets the column number of the first editable field found for the indicated row.
- *
- * @param rowIndex the index number of the row
- * @return the number of the editable column or -1 if no fields are editable.
- */
@Override
public int getFirstEditableColumn(int rowIndex) {
int numFields = this.getColumnCount();
@@ -720,9 +690,6 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
}
}
- /**
- * @param cycleGroup
- */
@Override
public void cycleDataType(CycleGroup cycleGroup) {
@@ -761,6 +728,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
*
* @param cycleGroup the cycle group of data types to choose from.
* @return the next data type or null
+ * @throws UsrException if more than 1 row is selected
*/
protected DataType getNextCycleDataType(CycleGroup cycleGroup) throws UsrException {
@@ -823,11 +791,11 @@ 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 this returns true, it still doesn't mean
- * the data type will fit where inserted or replaced
- *
- * @return true if it is valid.
+ * 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
+ * @param dynamicSizingAllowed true signals to allow dynamic types
* @throws InvalidDataTypeException if the structure being edited is part
* of the data type being inserted or doesn't have a valid size.
*/
@@ -852,57 +820,36 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
}
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isAddAllowed(int, ghidra.program.model.data.DataType)
- */
@Override
public boolean isAddAllowed(int currentIndex, DataType datatype) {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isArrayAllowed()
- */
@Override
public boolean isArrayAllowed() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isClearAllowed()
- */
@Override
public boolean isClearAllowed() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isCycleAllowed(ghidra.program.model.data.CycleGroup)
- */
@Override
public boolean isCycleAllowed(CycleGroup cycleGroup) {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isDeleteAllowed()
- */
@Override
public boolean isDeleteAllowed() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isDuplicateAllowed()
- */
@Override
public boolean isDuplicateAllowed() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isEditComponentAllowed()
- */
@Override
public boolean isEditComponentAllowed() {
if (this.getNumSelectedComponentRows() != 1) {
@@ -920,49 +867,31 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
((baseDt instanceof Structure) || baseDt instanceof Union || baseDt instanceof Enum));
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isEditFieldAllowed(int, int)
- */
@Override
public boolean isEditFieldAllowed(int rowIndex, int columnIndex) {
return !isEditingField();
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isInsertAllowed(int, ghidra.program.model.data.DataType)
- */
@Override
public boolean isInsertAllowed(int rowIndex, DataType datatype) {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isMoveDownAllowed()
- */
@Override
public boolean isMoveDownAllowed() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isMoveUpAllowed()
- */
@Override
public boolean isMoveUpAllowed() {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isReplaceAllowed(int, ghidra.program.model.data.DataType)
- */
@Override
public boolean isReplaceAllowed(int rowIndex, DataType dataType) {
return false;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#isUnpackageAllowed()
- */
@Override
public boolean isUnpackageAllowed() {
return false;
@@ -1033,61 +962,49 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
return 0;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#getLastNumBytes()
- */
@Override
public int getLastNumBytes() {
return lastNumBytes;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#getLastNumDuplicates()
- */
@Override
public int getLastNumDuplicates() {
return lastNumDuplicates;
}
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.EditorModel#getLastNumElements()
- */
@Override
public int getLastNumElements() {
return lastNumElements;
}
/**
- * Sets the last number of bytes the user entered for a data type.
- * @param numBytes the last number of bytes entered.
+ * Sets the last number of bytes the user entered for a data type
+ * @param numBytes the last number of bytes entered
*/
public void setLastNumBytes(int numBytes) {
lastNumBytes = numBytes;
}
/**
- * Sets the last number of bytes the user entered for a data type.
- * @param numBytes the last number of bytes entered.
+ * Sets the last number of bytes the user entered for a data type
+ * @param numDuplicates the last number of bytes entered
*/
public void setLastNumDuplicates(int numDuplicates) {
lastNumDuplicates = numDuplicates;
}
/**
- * Sets the last number of bytes the user entered for a data type.
- * @param numBytes the last number of bytes entered.
+ * Sets the last number of bytes the user entered for a data type
+ * @param numElements the last number of bytes entered
*/
public void setLastNumElements(int numElements) {
lastNumElements = numElements;
}
- // *************************************************************
- // End of methods for determining if a type of edit action is allowed.
- // *************************************************************
+//==================================================================================================
+// End of methods for determining if a type of edit action is allowed
+//==================================================================================================
- /* (non-Javadoc)
- * @see ghidra.app.plugin.compositeeditor.CompositeViewerModel#getOriginalComposite()
- */
@Override
protected Composite getOriginalComposite() {
if (!offline) {
@@ -1108,10 +1025,10 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
}
FieldSelection tmpSelection = new FieldSelection();
int numComponents = getNumComponents();
- for (int i = 0; i < rows.length; i++) {
+ for (int row2 : rows) {
// Only add valid component rows (i.e. don't include blank last line)
- if (rows[i] < numComponents) {
- tmpSelection.addRange(rows[i], rows[i] + 1);
+ if (row2 < numComponents) {
+ tmpSelection.addRange(row2, row2 + 1);
}
}
if (this.selection.equals(tmpSelection)) {
@@ -1155,22 +1072,22 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
selectionChanged();
}
- /**
- * @param rowIndex the component index
- * @param offset
- */
- @SuppressWarnings("unused")
+ @SuppressWarnings("unused") // the exception is thrown by subclasses1
public void validateComponentOffset(int rowIndex, String offset) throws UsrException {
// If the offset actually needs validating then override this method.
}
/**
- * @param rowIndex the index of the row
- * @param dtString
- * @return
+ * Validates that the data type indicated by the string can be set as the data type
+ * at the indicated row index. If the named data type can be various sizes, this
+ * method will prompt the user.
+ * @param rowIndex the row index
+ * @param dtString the string representing the data type.
+ * @return a valid data type instance or null if at blank line with no data type name.
+ * @throws UsrException indicating that the data type is not valid.
*/
public DataTypeInstance validateComponentDataType(int rowIndex, String dtString)
- throws CancelledException, UsrException {
+ throws UsrException {
DataType dt = null;
String dtName = "";
dtString = DataTypeHelper.stripWhiteSpace(dtString);
@@ -1215,13 +1132,9 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen
return DataTypeInstance.getDataTypeInstance(newDt, newLength);
}
- /**
- * @param rowIndex the component index
- * @param string
- */
- @SuppressWarnings("unused")
+ @SuppressWarnings("unused") // the exception is thrown by subclasses
public void validateComponentName(int rowIndex, String name) throws UsrException {
- // If the name actually needs validating then overide this method.
+ // If the name actually needs validating then override this method.
}
private void checkName(String name) throws DuplicateNameException {
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CreateInternalStructureAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CreateInternalStructureAction.java
index 5eba7855c8..0fce8f5c94 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CreateInternalStructureAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CreateInternalStructureAction.java
@@ -20,8 +20,11 @@ import java.util.Arrays;
import javax.swing.ImageIcon;
import docking.ActionContext;
-import ghidra.util.SystemUtilities;
+import ghidra.util.Swing;
+import ghidra.util.exception.CancelledException;
import ghidra.util.exception.UsrException;
+import ghidra.util.task.TaskLauncher;
+import ghidra.util.task.TaskMonitor;
import resources.ResourceManager;
/**
@@ -52,20 +55,17 @@ public class CreateInternalStructureAction extends CompositeEditorTableAction {
boolean contiguousComponentSelection = model.isContiguousComponentSelection();
if (hasComponentSelection && contiguousComponentSelection &&
(selectedComponentRows.length > 0)) {
+
Arrays.sort(selectedComponentRows);
int numComponents = model.getNumComponents();
int maxRow = selectedComponentRows[selectedComponentRows.length - 1];
if (maxRow < numComponents) {
- try {
- ((StructureEditorModel) model).createInternalStructure();
- }
- catch (UsrException e1) {
- model.setStatus(e1.getMessage(), true);
- }
+ TaskLauncher.launchModal(getName(), this::doCreate);
}
}
+
requestTableFocus();
- SystemUtilities.runSwingLater(() -> {
+ Swing.runLater(() -> {
provider.toFront();
provider.requestFocus();
provider.editorPanel.requestFocus();
@@ -73,6 +73,18 @@ public class CreateInternalStructureAction extends CompositeEditorTableAction {
});
}
+ private void doCreate(TaskMonitor monitor) {
+ try {
+ ((StructureEditorModel) model).createInternalStructure(monitor);
+ }
+ catch (CancelledException e) {
+ // user cancelled
+ }
+ catch (UsrException e) {
+ model.setStatus(e.getMessage(), true);
+ }
+ }
+
@Override
public void adjustEnablement() {
setEnabled(isCreateInternalStructureAllowed());
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DeleteAction.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DeleteAction.java
index 6d3d66ecbd..d8aa270d8f 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DeleteAction.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/DeleteAction.java
@@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
- * REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,60 +15,56 @@
*/
package ghidra.app.plugin.core.compositeeditor;
-import ghidra.util.Msg;
-import ghidra.util.exception.UsrException;
-
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
import javax.swing.KeyStroke;
-import resources.ResourceManager;
import docking.ActionContext;
-import docking.action.*;
-
+import docking.action.KeyBindingData;
+import ghidra.util.exception.CancelledException;
+import ghidra.util.exception.UsrException;
+import ghidra.util.task.TaskLauncher;
+import ghidra.util.task.TaskMonitor;
+import resources.ResourceManager;
public class DeleteAction extends CompositeEditorTableAction {
private final static String GROUP_NAME = COMPONENT_ACTION_GROUP;
private final static ImageIcon DELETE_ICON =
ResourceManager.loadImage("images/edit-delete.png");
- private final static String[] popupPath = new String[] { "Delete" };
+ private final static String[] popupPath = new String[] { "Delete" };
private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
- /**
- *
- * @param owner
- */
public DeleteAction(CompositeEditorProvider provider) {
- super(provider, EDIT_ACTION_PREFIX + "Delete Components", GROUP_NAME,
- popupPath, null, DELETE_ICON);
-
- setKeyBindingData( new KeyBindingData( keyStroke ) );
+ super(provider, EDIT_ACTION_PREFIX + "Delete Components", GROUP_NAME, popupPath, null,
+ DELETE_ICON);
+
+ setKeyBindingData(new KeyBindingData(keyStroke));
setDescription("Delete the selected components");
adjustEnablement();
}
-
- /* (non-Javadoc)
- * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
- */
- @Override
- public void actionPerformed(ActionContext context) {
+
+ @Override
+ public void actionPerformed(ActionContext context) {
+ TaskLauncher.launchModal(getName(), this::doDelete);
+ requestTableFocus();
+ }
+
+ private void doDelete(TaskMonitor monitor) {
try {
- model.deleteSelectedComponents();
- } catch (OutOfMemoryError memExc) {
- Msg.showError(this, null, "Out of Memory", "Couldn't delete components. Out of memory.", memExc);
- } catch (UsrException ue) {
- model.setStatus(ue.getMessage());
+ model.deleteSelectedComponents(monitor);
}
- requestTableFocus();
- }
-
- /* (non-Javadoc)
- * @see ghidra.app.plugin.datamanager.editor.CompositeEditorAction#adjustEnablement()
- */
- @Override
- public void adjustEnablement() {
- setEnabled(model.isDeleteAllowed());
- }
+ catch (CancelledException e) {
+ // user cancelled
+ }
+ catch (UsrException e) {
+ model.setStatus(e.getMessage(), true);
+ }
+ }
+
+ @Override
+ public void adjustEnablement() {
+ setEnabled(model.isDeleteAllowed());
+ }
}
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java
index d5f1db6bbb..ce3456616a 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/EditorModel.java
@@ -331,9 +331,10 @@ public interface EditorModel {
/**
* Delete the selected components.
*
+ * @param monitor the task monitor
* @throws UsrException if the data type isn't allowed to be deleted.
*/
- public void deleteSelectedComponents() throws UsrException;
+ public void deleteSelectedComponents(TaskMonitor monitor) throws UsrException;
/**
* Creates multiple duplicates of the indicated component.
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java
index ecdb9fe90d..0f22fa8e79 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/StructureEditorModel.java
@@ -627,13 +627,14 @@ class StructureEditorModel extends CompEditorModel {
}
@Override
- public void deleteSelectedComponents() throws UsrException {
+ public void deleteSelectedComponents(TaskMonitor monitor) throws UsrException {
if (!isDeleteAllowed()) {
throw new UsrException("Deleting is not allowed.");
}
if (isEditingField()) {
endFieldEditing();
}
+
int rowIndex = selection.getFieldRange(0).getStart().getIndex().intValue();
DataTypeComponent dtc = getComponent(rowIndex);
if (dtc.isFlexibleArrayComponent()) {
@@ -645,7 +646,7 @@ class StructureEditorModel extends CompEditorModel {
selectionChanged();
return;
}
- super.deleteSelectedComponents();
+ super.deleteSelectedComponents(monitor);
}
@Override
@@ -1210,7 +1211,7 @@ class StructureEditorModel extends CompEditorModel {
return !viewComposite.isInternallyAligned();
}
- public void createInternalStructure()
+ public void createInternalStructure(TaskMonitor monitor)
throws InvalidDataTypeException, DataTypeConflictException, UsrException {
if (selection.getNumRanges() != 1) {
@@ -1230,6 +1231,7 @@ class StructureEditorModel extends CompEditorModel {
return;
}
}
+
if (isEditingField()) {
endFieldEditing();
}
@@ -1295,7 +1297,7 @@ class StructureEditorModel extends CompEditorModel {
}
DataType addedDataType = createDataTypeInOriginalDTM(structureDataType);
if (viewComposite.isInternallyAligned()) {
- deleteSelectedComponents();
+ deleteSelectedComponents(monitor);
insert(minRow, addedDataType, addedDataType.getLength());
}
else {
@@ -1313,7 +1315,7 @@ class StructureEditorModel extends CompEditorModel {
}
}
clearSelectedComponents();
- insertMultiple(minRow, DataType.DEFAULT, 1, adjustmentBytes, TaskMonitor.DUMMY);
+ insertMultiple(minRow, DataType.DEFAULT, 1, adjustmentBytes, monitor);
replace(minRow, addedDataType, addedDataType.getLength());
}
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
index 4c3b28b7d5..4ecc69eae1 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions2Test.java
@@ -291,10 +291,11 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
invoke(createInternalStructureAction);
// Specify name for structure.
- JDialog inputDialog = waitForJDialog(null, "Specify the Structure's Name", 2000);
+ JDialog inputDialog = waitForJDialog("Specify the Structure's Name");
assertNotNull(inputDialog);
pressButtonByText(inputDialog, "OK");
- waitForSwing();
+
+ waitForTasks();
assertEquals(5, getModel().getNumComponents());
Structure internalStruct = (Structure) getDataType(1);
@@ -315,7 +316,7 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
/**
* Edit an existing structure and create a structure from a selection,
* but cancel out of name dialog.
- * @throws Exception
+ * @throws Exception it the test throws an exception
*/
@Test
public void testExistingDtEditInternalStructureOnSelectionCancelOnName() throws Exception {
@@ -333,7 +334,7 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
invoke(createInternalStructureAction);
// Specify name for structure.
- JDialog inputDialog = waitForJDialog(null, "Specify the Structure's Name", 2000);
+ JDialog inputDialog = waitForJDialog("Specify the Structure's Name");
assertNotNull(inputDialog);
pressButtonByText(inputDialog, "Cancel");
waitForSwing();
@@ -349,7 +350,7 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
/**
* Edit an existing structure and create a structure from a selection. Use the default name.
- * @throws Exception
+ * @throws Exception if the test throws an exception
*/
@Test
public void testExistingDtEditInternalStructureOnSelectionDefaultName() throws Exception {
@@ -367,10 +368,11 @@ public class StructureEditorLockedActions2Test extends AbstractStructureEditorLo
invoke(createInternalStructureAction);
// Specify name for structure.
- JDialog inputDialog = waitForJDialog(null, "Specify the Structure's Name", 2000);
+ JDialog inputDialog = waitForJDialog("Specify the Structure's Name");
assertNotNull(inputDialog);
pressButtonByText(inputDialog, "OK");
- waitForSwing();
+
+ waitForTasks();
assertEquals(6, getModel().getNumComponents());
Structure internalStruct = (Structure) getDataType(1);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions3Test.java
index 1df96249f2..804272686b 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions3Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorLockedActions3Test.java
@@ -32,7 +32,7 @@ public class StructureEditorLockedActions3Test extends AbstractStructureEditorLo
/**
* Edit an existing structure and create a structure from a selection. Use the conflicting
* names followed by a good non-default name.
- * @throws Exception
+ * @throws Exception if the test throws an exception
*/
@Test
public void testExistingDtEditInternalStructureOnSelectionVariousNames() throws Exception {
@@ -58,6 +58,7 @@ public class StructureEditorLockedActions3Test extends AbstractStructureEditorLo
triggerText(textField, "simpleStructure");
pressButtonByText(inputDialog, "OK");
waitForSwing();
+
assertEquals("The name cannot match the external structure name.",
getStatusText(inputDialog));
assertTrue(inputDialog.isShowing());
@@ -72,7 +73,7 @@ public class StructureEditorLockedActions3Test extends AbstractStructureEditorLo
pressButtonByText(inputDialog, "OK");
assertEquals(" ", getStatusText(inputDialog));
assertFalse(inputDialog.isShowing());
- waitForSwing();
+ waitForTasks();
assertEquals(6, getModel().getNumComponents());
Structure internalStruct = (Structure) getDataType(1);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
index 6a3438b8d5..fcdc33323c 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorUnlockedActions4Test.java
@@ -27,6 +27,7 @@ import docking.widgets.dialogs.NumberInputDialog;
import ghidra.program.model.data.*;
import ghidra.util.InvalidNameException;
import ghidra.util.exception.*;
+import ghidra.util.task.TaskMonitor;
public class StructureEditorUnlockedActions4Test
extends AbstractStructureEditorUnlockedActionsTest {
@@ -253,7 +254,7 @@ public class StructureEditorUnlockedActions4Test
runSwing(() -> {
try {
model.clearSelectedComponents();
- model.deleteSelectedComponents();
+ model.deleteSelectedComponents(TaskMonitor.DUMMY);
}
catch (UsrException e) {
failWithException("Unexpected error", e);
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
index 5b1d4d4a81..f8b6ae5cb2 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorActions1Test.java
@@ -27,6 +27,7 @@ import org.junit.Test;
import docking.widgets.dialogs.NumberInputDialog;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Composite.AlignmentType;
+import ghidra.util.task.TaskMonitor;
public class UnionEditorActions1Test extends AbstractUnionEditorTest {
@@ -76,7 +77,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
assertEquals(simpleUnion.getNumComponents(), model.getNumComponents());
assertEquals(simpleUnion.getNumComponents() + 1, model.getRowCount());
assertEquals(simpleUnion.getLength(), model.getLength());
- assertTrue(!model.hasChanges());// no Changes yet
+ assertFalse(model.hasChanges());// no Changes yet
assertTrue(model.isValidName());// name should be valid
assertEquals(simpleUnion.getDescription(), model.getDescription());
assertEquals(0, model.getNumSelectedComponentRows());
@@ -242,7 +243,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
int num = model.getNumComponents();
setSelection(new int[] { 3 });
- assertTrue(!getDataType(3).isEquivalent(dt));
+ assertFalse(getDataType(3).isEquivalent(dt));
invoke(fav);
assertEquals(num, model.getNumComponents());
assertTrue(getDataType(3).isEquivalent(dt));
@@ -412,7 +413,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
assertEquals(getDataType(1), dt1);
assertEquals(getDataType(2), dt2);
assertEquals(getDataType(3), dt3);
- assertTrue(!"".equals(model.getStatus()));
+ assertFalse("".equals(model.getStatus()));
}
@Test
@@ -426,7 +427,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
String simpleTitle = getProviderSubTitle(simpleStructure);
assertTrue("Couldn't find editor = " + complexTitle,
isProviderShown(tool.getToolFrame(), "Union Editor", complexTitle));
- assertTrue(!isProviderShown(tool.getToolFrame(), "Structure Editor", simpleTitle));
+ assertFalse(isProviderShown(tool.getToolFrame(), "Structure Editor", simpleTitle));
invoke(editComponentAction);
assertEquals("", model.getStatus());
assertTrue("Couldn't find editor = " + complexTitle,
@@ -438,7 +439,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
@Test
public void testEditFieldOnBlankLine() throws Exception {
init(emptyUnion, pgmRootCat, false);
- assertTrue(!model.isEditingField());
+ assertFalse(model.isEditingField());
triggerActionKey(getTable(), editFieldAction);
assertTrue(model.isEditingField());
@@ -453,7 +454,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
init(complexUnion, pgmTestCat, false);
setSelection(new int[] { 3 });
- assertTrue(!model.isEditingField());
+ assertFalse(model.isEditingField());
invoke(editFieldAction);
assertTrue(model.isEditingField());
assertEquals(3, model.getRow());
@@ -484,7 +485,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
invoke(showComponentPathAction);
assertEquals("simpleStructure is in category \"" + pgmBbCat.getCategoryPathName() + "\".",
model.getStatus());
- assertTrue(!listener.getBeep());
+ assertFalse(listener.getBeep());
}
@Test
@@ -511,7 +512,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
assertEquals(getDataType(4), dt3);
assertEquals(getDataType(5), dt4);
assertEquals(getDataType(6), dt5);
- assertTrue(!model.isMoveDownAllowed());
+ assertFalse(model.isMoveDownAllowed());
}
@Test
@@ -550,7 +551,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
assertEquals(getDataType(4), dt1);
assertEquals(getDataType(5), dt5);
assertEquals(getDataType(6), dt6);
- assertTrue(!model.isMoveUpAllowed());
+ assertFalse(model.isMoveUpAllowed());
}
@Test
@@ -599,6 +600,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
int len = model.getLength();
setSelection(new int[] { 3 });// simpleUnion == 8 bytes
invoke(deleteAction);
+ waitForTasks();
assertEquals(model.getLength(), len);
assertEquals(1, model.getNumSelectedComponentRows());
assertTrue(Arrays.equals(new int[] { 3 }, model.getSelectedComponentRows()));
@@ -610,6 +612,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
setSelection(new int[] { 12 });// simpleStructure[3] == 87 bytes
invoke(deleteAction);
+ waitForTasks();
assertEquals(56, model.getLength());// simpleStructure*[7] == 56 bytes
assertEquals(1, model.getNumSelectedComponentRows());
assertTrue(Arrays.equals(new int[] { 12 }, model.getSelectedComponentRows()));
@@ -625,6 +628,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
int len = model.getLength();
setSelection(new int[] { 4, 5, 6, 7, 8, 9 });
invoke(deleteAction);
+ waitForTasks();
assertEquals(num - 6, model.getNumComponents());
assertEquals(len, model.getLength());
assertEquals(getDataType(3), dt3);
@@ -644,6 +648,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
int len = model.getLength();
setSelection(new int[] { 4, 5, 6, 7, 8, 9, 19, 20 });
invoke(deleteAction);
+ waitForTasks();
assertEquals(num - 8, model.getNumComponents());
assertEquals(len, model.getLength());
assertEquals(getDataType(3), dt3);
@@ -664,7 +669,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
// Cancel the array dialog
invoke(arrayAction);
- dialog = env.waitForDialogComponent(NumberInputDialog.class, 1000);
+ dialog = waitForDialogComponent(NumberInputDialog.class);
assertNotNull(dialog);
cancelInput(dialog);
dialog = null;
@@ -738,7 +743,6 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
assertTrue(((Pointer) getDataType(1)).getDataType().isEquivalent(StringDataType.dataType));
assertEquals(4, getDataType(1).getLength());
assertEquals(4, model.getComponent(1).getLength());
-
}
@Test
@@ -757,44 +761,15 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
assertEquals(4, model.getComponent(5).getLength());
}
-// @Test
-// public void testCreatePointerOnArray() throws Exception {
-// init(complexUnion, pgmTestCat, false);
-// int num = model.getNumComponents();
-//
-// setSelection(new int[] { 10 });
-// DataType dt10 = getDataType(10);
-// invoke(pointerAction);
-// assertEquals(num, model.getNumComponents());
-// assertEquals("byte[7] *", getDataType(10).getDisplayName());
-// assertTrue(((Pointer) getDataType(10)).getDataType().isEquivalent(dt10));
-// assertEquals(4, getDataType(10).getLength());
-// assertEquals(4, model.getComponent(10).getLength());
-// }
-
-// @Test
-// public void testCreatePointerOnTypedef() throws Exception {
-// init(complexUnion, pgmTestCat, false);
-// int num = model.getNumComponents();
-//
-// setSelection(new int[] { 15 });
-// DataType dt15 = getDataType(15);
-// invoke(pointerAction);
-// assertEquals(num, model.getNumComponents());
-// assertEquals("simpleStructureTypedef *", getDataType(15).getDisplayName());
-// assertTrue(((Pointer) getDataType(15)).getDataType().isEquivalent(dt15));
-// assertEquals(4, model.getComponent(15).getLength());
-// }
-
@Test
public void testApplyComponentChange() throws Exception {
init(complexUnion, pgmTestCat, false);
setSelection(new int[] { 3, 4 });
- model.deleteSelectedComponents();
+ model.deleteSelectedComponents(TaskMonitor.DUMMY);
DataType viewCopy = model.viewComposite.clone(null);
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
assertTrue(viewCopy.isEquivalent(model.viewComposite));
invoke(applyAction);
assertTrue(viewCopy.isEquivalent(complexUnion));
@@ -834,7 +809,7 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
triggerText(nameField, "#/$");
DataType viewCopy = model.viewComposite.clone(null);
- assertTrue(!model.isValidName());
+ assertFalse(model.isValidName());
assertEquals("complexUnion#/$", nameField.getText());
assertEquals("complexUnion#/$", model.getCompositeName());
assertEquals("complexUnion", complexUnion.getName());
@@ -875,18 +850,16 @@ public class UnionEditorActions1Test extends AbstractUnionEditorTest {
setSelection(new int[] { 0, 1, 2, 3, 4, 5, 6 });
invoke(deleteAction);
+ waitForTasks();
DataType viewCopy = model.viewComposite.clone(null);
- assertTrue(!simpleUnion.isEquivalent(model.viewComposite));
+ assertFalse(simpleUnion.isEquivalent(model.viewComposite));
assertTrue(viewCopy.isEquivalent(model.viewComposite));
assertEquals(0, model.getNumComponents());
assertEquals(model.getStatus(), "");
invoke(applyAction);
assertTrue(simpleUnion.isEquivalent(model.viewComposite));
assertTrue(viewCopy.isEquivalent(model.viewComposite));
-// assertEquals(
-// "/aa/bb/simpleUnion is contained in /testCat/complexStructure and can't be changed to a zero size data type.",
-// model.getStatus());
}
@Test
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java
index b01a1718a5..c74796ed28 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java
@@ -19,14 +19,13 @@ import static org.junit.Assert.*;
import java.awt.Window;
-import javax.swing.SwingUtilities;
-
import org.junit.Assert;
import org.junit.Test;
import docking.ActionContext;
import ghidra.framework.options.Options;
import ghidra.program.model.data.*;
+import ghidra.util.Swing;
import ghidra.util.exception.UsrException;
public class UnionEditorProviderTest extends AbstractUnionEditorTest {
@@ -87,10 +86,8 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
program.addListener(restoreListener);
// Change the union.
- SwingUtilities.invokeLater(() -> {
- getTable().requestFocus();
- model.setSelection(new int[] { 4, 5 });
- deleteAction.actionPerformed(new ActionContext());
+ Swing.runLater(() -> {
+ delete(4, 5);
try {
model.add(new WordDataType());
}
@@ -98,41 +95,42 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
Assert.fail(e.getMessage());
}
});
- waitForSwing();
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+
+ waitForTasks();
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
// Apply the changes
invoke(applyAction);
assertTrue(complexUnion.isEquivalent(model.viewComposite));
// Change the union again.
- SwingUtilities.invokeLater(() -> {
- getTable().requestFocus();
- model.setSelection(new int[] { 1 });
- deleteAction.actionPerformed(new ActionContext());
+ Swing.runLater(() -> {
+ delete(1);
});
waitForSwing();
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
// Undo the apply
undo(program, false);
+
// Verify the Reload Union Editor? dialog is displayed.
- dialog = env.waitForWindow("Reload Union Editor?", 4000);
+ dialog = waitForWindow("Reload Union Editor?");
assertNotNull(dialog);
pressButton(dialog, "No");
dialog.dispose();
dialog = null;
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
// Redo the apply
redo(program, false);
+
// Verify the Reload Union Editor? dialog is displayed.
- dialog = env.waitForWindow("Reload Union Editor?", 4000);
+ dialog = waitForWindow("Reload Union Editor?");
assertNotNull(dialog);
pressButton(dialog, "No");
dialog.dispose();
dialog = null;
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
}
finally {
dialog = null;
@@ -150,10 +148,8 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
program.addListener(restoreListener);
// Change the union.
- SwingUtilities.invokeLater(() -> {
- getTable().requestFocus();
- model.setSelection(new int[] { 4, 5 });
- deleteAction.actionPerformed(new ActionContext());
+ Swing.runLater(() -> {
+ delete(4, 5);
try {
model.add(new WordDataType());
}
@@ -161,14 +157,18 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
Assert.fail(e.getMessage());
}
});
- waitForSwing();
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+
+ waitForTasks();
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
+
// Apply the changes
invoke(applyAction);
assertTrue(complexUnion.isEquivalent(model.viewComposite));
+
// Undo the apply
undo(program);
assertTrue(complexUnion.isEquivalent(model.viewComposite));
+
// Redo the apply
redo(program);
assertTrue(complexUnion.isEquivalent(model.viewComposite));
@@ -191,7 +191,7 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
runSwing(() -> provider.closeComponent());
waitForSwing();
- assertTrue(!tool.isVisible(provider));
+ assertFalse(tool.isVisible(provider));
assertTrue(complexUnion.isEquivalent(dt));
}
@@ -202,10 +202,8 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
DataType oldDt = model.viewComposite.clone(null);
// Change the union.
- SwingUtilities.invokeLater(() -> {
- getTable().requestFocus();
- model.setSelection(new int[] { 4, 5 });
- deleteAction.actionPerformed(new ActionContext());
+ Swing.runLater(() -> {
+ delete(4, 5);
try {
model.add(new WordDataType());
}
@@ -213,23 +211,24 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
Assert.fail(e.getMessage());
}
});
- waitForSwing();
+
+ waitForTasks();
DataType newDt = model.viewComposite.clone(null);
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
assertTrue(complexUnion.isEquivalent(oldDt));
- SwingUtilities.invokeLater(() -> provider.closeComponent());
+ Swing.runLater(() -> provider.closeComponent());
waitForSwing();
- dialog = env.waitForWindow("Save Union Editor Changes?", 1000);
+ dialog = waitForWindow("Save Union Editor Changes?");
assertNotNull(dialog);
pressButton(dialog, "Yes");
dialog.dispose();
dialog = null;
provider = null;
- assertTrue(!tool.isVisible(provider));
+ assertFalse(tool.isVisible(provider));
assertTrue(complexUnion.isEquivalent(newDt));
- assertTrue(!complexUnion.isEquivalent(oldDt));
+ assertFalse(complexUnion.isEquivalent(oldDt));
}
@Test
@@ -239,10 +238,8 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
DataType oldDt = model.viewComposite.clone(null);
// Change the union.
- SwingUtilities.invokeLater(() -> {
- getTable().requestFocus();
- model.setSelection(new int[] { 4, 5 });
- deleteAction.actionPerformed(new ActionContext());
+ Swing.runLater(() -> {
+ delete(4, 5);
try {
model.add(new WordDataType());
}
@@ -250,22 +247,24 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
Assert.fail(e.getMessage());
}
});
- waitForSwing();
+
+ waitForTasks();
+
DataType newDt = model.viewComposite.clone(null);
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
assertTrue(complexUnion.isEquivalent(oldDt));
- SwingUtilities.invokeLater(() -> provider.closeComponent());
+ Swing.runLater(() -> provider.closeComponent());
waitForSwing();
- dialog = env.waitForWindow("Save Union Editor Changes?", 1000);
+ dialog = waitForWindow("Save Union Editor Changes?");
assertNotNull(dialog);
pressButton(dialog, "Yes");
dialog.dispose();
dialog = null;
- assertTrue(!tool.isVisible(provider));
+ assertFalse(tool.isVisible(provider));
assertTrue(complexUnion.isEquivalent(newDt));
- assertTrue(!complexUnion.isEquivalent(oldDt));
+ assertFalse(complexUnion.isEquivalent(oldDt));
}
@Test
@@ -274,10 +273,8 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
init(complexUnion, pgmTestCat, false);
// Change the union.
- SwingUtilities.invokeLater(() -> {
- getTable().requestFocus();
- model.setSelection(new int[] { 4, 5 });
- deleteAction.actionPerformed(new ActionContext());
+ Swing.runLater(() -> {
+ delete(4, 5);
try {
model.add(new WordDataType());
}
@@ -285,20 +282,21 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
Assert.fail(e.getMessage());
}
});
- waitForSwing();
+
+ waitForTasks();
DataType newDt = model.viewComposite.clone(null);
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
- SwingUtilities.invokeLater(() -> provider.closeComponent());
+ Swing.runLater(() -> provider.closeComponent());
waitForSwing();
- dialog = env.waitForWindow("Save Union Editor Changes?", 1000);
+ dialog = waitForWindow("Save Union Editor Changes?");
assertNotNull(dialog);
pressButton(dialog, "Cancel");
dialog.dispose();
dialog = null;
assertTrue(tool.isVisible(provider));
- assertTrue(!complexUnion.isEquivalent(model.viewComposite));
+ assertFalse(complexUnion.isEquivalent(model.viewComposite));
assertTrue(newDt.isEquivalent(model.viewComposite));
}
@@ -330,10 +328,10 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
assertEquals("87", model.getLengthAsString());
// Close the editor
- SwingUtilities.invokeLater(() -> provider.closeComponent());
+ Swing.runLater(() -> provider.closeComponent());
waitForSwing();
// Editor should be closed.
- assertTrue(!tool.isVisible(provider));
+ assertFalse(tool.isVisible(provider));
assertTrue(complexUnion.isEquivalent(oldDt));
// Re-open the editor
init(complexUnion, pgmTestCat, true);
@@ -358,11 +356,12 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
assertEquals("0x57", model.getLengthAsString());
// Close the editor
- SwingUtilities.invokeLater(() -> provider.closeComponent());
+ Swing.runLater(() -> provider.closeComponent());
waitForSwing();
// Editor should be closed.
- assertTrue(!tool.isVisible(provider));
+ assertFalse(tool.isVisible(provider));
assertTrue(complexUnion.isEquivalent(oldDt));
+
// Re-open the editor
init(complexUnion, pgmTestCat, false);
@@ -375,4 +374,10 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {
assertEquals("87", model.getLengthAsString());
}
+ private void delete(int... rows) {
+
+ getTable().requestFocus();
+ model.setSelection(rows);
+ deleteAction.actionPerformed(new ActionContext());
+ }
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/ZeroSizeUnionTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/ZeroSizeUnionTest.java
index ff09755c46..15c8e66b58 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/ZeroSizeUnionTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/ZeroSizeUnionTest.java
@@ -25,7 +25,7 @@ import ghidra.program.model.data.Composite.AlignmentType;
public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
@Test
- public void testCreateEmptyUnion() throws Exception {
+ public void testCreateEmptyUnion() throws Exception {
init(emptyUnion, pgmRootCat, false);
assertNull(pgmRootCat.getDataType(emptyUnion.getName()));
@@ -71,7 +71,7 @@ public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
}
@Test
- public void testCanZeroDataTypeIfComponent() throws Exception {
+ public void testCanZeroDataTypeIfComponent() throws Exception {
init(simpleUnion, pgmBbCat, false);
DataType dt = pgmBbCat.getDataType(simpleUnion.getName());
@@ -146,7 +146,7 @@ public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
}
@Test
- public void testCanZeroDataTypeIfPointerComponent() throws Exception {
+ public void testCanZeroDataTypeIfPointerComponent() throws Exception {
Union innerUnionImpl = new UnionDataType("innerUnion");
innerUnionImpl.add(DataType.DEFAULT);// component 0
@@ -245,7 +245,7 @@ public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
}
@Test
- public void testCannotZeroDataTypeIfNonPointerComponent() throws Exception {
+ public void testCannotZeroDataTypeIfNonPointerComponent() throws Exception {
Union innerUnionImpl = new UnionDataType("innerUnion");
innerUnionImpl.add(DataType.DEFAULT);// component 0
@@ -346,7 +346,7 @@ public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
}
@Test
- public void testCannotZeroDataTypeIfInTypedef() throws Exception {
+ public void testCannotZeroDataTypeIfInTypedef() throws Exception {
Union innerUnionImpl = new UnionDataType("innerUnion");
innerUnionImpl.add(DataType.DEFAULT);// component 0
@@ -442,7 +442,7 @@ public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
}
@Test
- public void testCannotZeroDataTypeIfInArray() throws Exception {
+ public void testCannotZeroDataTypeIfInArray() throws Exception {
Union innerUnionImpl = new UnionDataType("innerUnion");
innerUnionImpl.add(DataType.DEFAULT);// component 0
@@ -541,6 +541,7 @@ public class ZeroSizeUnionTest extends AbstractUnionEditorTest {
while (model.getLength() > 0) {
model.setSelection(new int[] { 0 });
invoke(deleteAction);
+ waitForTasks();
}
}
}
diff --git a/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java b/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java
index 61b0740ef8..6cdc2894eb 100644
--- a/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java
+++ b/Ghidra/Framework/Generic/src/main/java/generic/test/AbstractGenericTest.java
@@ -15,7 +15,7 @@
*/
package generic.test;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.*;
import java.awt.*;
import java.awt.event.*;
@@ -446,6 +446,8 @@ public abstract class AbstractGenericTest extends AbstractGTest {
// TODO deprecate this; at time of writing there are 1174 references; wait until it is
// a more reasonable number
+ //
+ // Update: 744 references at 12/1/19
public static void waitForPostedSwingRunnables() {
waitForSwing();
}
@@ -1288,7 +1290,7 @@ public abstract class AbstractGenericTest extends AbstractGTest {
}
public static void clickTableCell(final JTable table, final int row, final int col,
- int clickCount) throws Exception {
+ int clickCount) {
runSwing(() -> table.setRowSelectionInterval(row, row));
waitForSwing();
Rectangle rect = table.getCellRect(row, col, true);
@@ -1303,10 +1305,8 @@ public abstract class AbstractGenericTest extends AbstractGTest {
* @param list the list to select from
* @param row the initial index
* @param count the number of rows to select
- * @throws Exception if there's a problem simulating the click
*/
- public static void clickListRange(final JList list, final int row, int count)
- throws Exception {
+ public static void clickListRange(final JList<?> list, final int row, int count) {
waitForSwing();
for (int i = row; i < row + count; i++) {
Rectangle rect = list.getCellBounds(i, i);
@@ -1315,7 +1315,7 @@ public abstract class AbstractGenericTest extends AbstractGTest {
}
waitForSwing();
}
-
+
/**
* Clicks a range of items in a table (simulates holding SHIFT and selecting
* each item in the range)
@@ -1323,10 +1323,8 @@ public abstract class AbstractGenericTest extends AbstractGTest {
* @param table the table to select
* @param row the starting row index
* @param count the number of rows to select
- * @throws Exception
*/
- public static void clickTableRange(final JTable table, final int row, int count)
- throws Exception {
+ public static void clickTableRange(final JTable table, final int row, int count) {
waitForSwing();
for (int i = row; i < row + count; i++) {
Rectangle rect = table.getCellRect(i, 0, true);