GP-3967 - Fixed bug in structure table searching that prevented the searching of all columns; updated the search to also check the default name

This commit is contained in:
dragonmacher 2023-10-31 15:01:41 -04:00
parent 1bac23c59c
commit d2d3969464
2 changed files with 39 additions and 14 deletions

View file

@ -128,7 +128,12 @@
Alternatively, the down <IMG src="images/go-down.tango.16.png" alt=""> and up <IMG src= Alternatively, the down <IMG src="images/go-down.tango.16.png" alt=""> and up <IMG src=
"images/go-up.tango.16.png" alt=""> arrows next to the search field can be used to search "images/go-up.tango.16.png" alt=""> arrows next to the search field can be used to search
forwards and backwards respectively. Searches are not case sensitive.</P> forwards and backwards respectively. Searches are not case sensitive.</P>
<P><IMG src="help/shared/tip.png" alt="" border="0">The default name of each structure field
will also be examined when searching, even though they are not visible in the UI.</P>
</BLOCKQUOTE> </BLOCKQUOTE>
<H2><A name="Structure_Editor_Name"></A>Changing the Name</H2> <H2><A name="Structure_Editor_Name"></A>Changing the Name</H2>

View file

@ -1031,9 +1031,6 @@ public abstract class CompositeEditorPanel extends JPanel
} }
} }
/* (non-Javadoc)
* @see ghidra.app.plugin.datamanager.editor.CompositeEditorModelListener#endFieldEditing()
*/
@Override @Override
public void endFieldEditing() { public void endFieldEditing() {
stopCellEditing(); stopCellEditing();
@ -1042,9 +1039,6 @@ public abstract class CompositeEditorPanel extends JPanel
} }
} }
/* (non-Javadoc)
* @see ghidra.app.plugin.compositeeditor.CompositeModelStatusListener#statusChanged(java.lang.String, boolean)
*/
@Override @Override
public void statusChanged(String message, boolean beep) { public void statusChanged(String message, boolean beep) {
if ((message == null) || (message.length() == 0)) { if ((message == null) || (message.length() == 0)) {
@ -1068,8 +1062,10 @@ public abstract class CompositeEditorPanel extends JPanel
} }
private Integer findForward(String searchText) { private Integer findForward(String text) {
int colCount = model.getColumnCount();
String searchText = text.toLowerCase();
int colCount = table.getColumnCount();
int currentRow = Math.max(0, model.getRow()); int currentRow = Math.max(0, model.getRow());
// search remaining lines // search remaining lines
@ -1081,7 +1077,7 @@ public abstract class CompositeEditorPanel extends JPanel
} }
} }
} }
// wrap search search rows from beginning // wrap search - search rows from beginning
for (int row = 0; row < currentRow; row++) { for (int row = 0; row < currentRow; row++) {
for (int col = 0; col < colCount; col++) { for (int col = 0; col < colCount; col++) {
if (matchesSearch(searchText, row, col)) { if (matchesSearch(searchText, row, col)) {
@ -1094,7 +1090,9 @@ public abstract class CompositeEditorPanel extends JPanel
return null; return null;
} }
private Integer findBackward(String searchText) { private Integer findBackward(String text) {
String searchText = text.toLowerCase();
int colCount = model.getColumnCount(); int colCount = model.getColumnCount();
int currentRow = Math.max(0, model.getRow()); int currentRow = Math.max(0, model.getRow());
@ -1106,7 +1104,7 @@ public abstract class CompositeEditorPanel extends JPanel
} }
} }
} }
//wrap search - search from last row to current row // wrap search - search from last row to current row
for (int row = model.getRowCount() - 1; row >= currentRow; row--) { for (int row = model.getRowCount() - 1; row >= currentRow; row--) {
for (int col = colCount - 1; col >= 0; col--) { for (int col = colCount - 1; col >= 0; col--) {
if (matchesSearch(searchText, row, col)) { if (matchesSearch(searchText, row, col)) {
@ -1120,13 +1118,35 @@ public abstract class CompositeEditorPanel extends JPanel
} }
private boolean matchesSearch(String searchText, int row, int col) { private boolean matchesSearch(String searchText, int row, int col) {
Object valueAt = model.getValueAt(row, col); int modelCol = table.convertColumnIndexToModel(col);
Object valueAt = model.getValueAt(row, modelCol);
if (valueAt == null) { if (valueAt == null) {
return false; return false;
} }
String value = getString(valueAt);
return value.toLowerCase().contains(searchText); String value = getString(valueAt).toLowerCase();
if (modelCol == model.getNameColumn()) {
return nameMatchesSearch(searchText, row, value);
}
return value.contains(searchText);
}
private boolean nameMatchesSearch(String searchText, int row, String value) {
if (value.contains(searchText)) {
return true;
}
// see if the default name is a match
DataTypeComponent dtc = model.getComponent(row);
if (dtc != null) {
// this allows this to match a search even though it is not seen in the UI
String defaultName = dtc.getDefaultFieldName().toLowerCase();
return defaultName.contains(searchText);
}
return false;
} }
private String getString(Object object) { private String getString(Object object) {