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 563c02349b..2dcc67dbc2 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 @@ -74,6 +74,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen * * @param dataType the new composite data type. */ + @Override public void load(Composite dataType) { if (dataType == null) { // TODO: Why is this needed? Use case? return; @@ -104,7 +105,8 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen // Listen so we can update editor if name changes for this structure. originalCompositeId = DataTypeManager.NULL_DATATYPE_ID; if (originalDTM.contains(dataType)) { - originalCompositeId = originalDTM.getID(dataType); // Get the id if editing an existing data type. + // Get the id if editing an existing data type. + originalCompositeId = originalDTM.getID(dataType); } originalDTM.addDataTypeManagerListener(this); @@ -117,7 +119,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen editorStateChanged(CompositeEditorModelListener.COMPOSITE_LOADED); } - + /** * Create view composite with the appropriate datatype manager and * changes listener(s) if required. @@ -393,7 +395,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen if (newDt == null) { return; // Was nothing and is nothing. } - + if (DataTypeComponent.usesZeroLengthComponent(newDt)) { newLength = 0; } @@ -401,7 +403,7 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen checkIsAllowableDataType(newDt); newDt = resolveDataType(newDt, viewDTM, DataTypeConflictHandler.DEFAULT_HANDLER); - + if (newLength < 0) { // prefer previous size first int suggestedLength = (previousLength <= 0) ? lastNumBytes : previousLength; @@ -410,7 +412,8 @@ public abstract class CompositeEditorModel extends CompositeViewerModel implemen if (sizedDataType == null) { return; } - newDt = resolveDataType(sizedDataType.getDataType(), viewDTM, DataTypeConflictHandler.DEFAULT_HANDLER); + newDt = resolveDataType(sizedDataType.getDataType(), viewDTM, + DataTypeConflictHandler.DEFAULT_HANDLER); newLength = sizedDataType.getLength(); if (newLength <= 0) { throw new UsrException("Can't currently add this data type."); @@ -430,9 +433,10 @@ 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 resolve. + * 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 diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java index 40acd769c0..ed452f8d53 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeEditorPanel.java @@ -23,6 +23,7 @@ import java.awt.event.*; import java.math.BigInteger; import java.util.Arrays; import java.util.EventObject; +import java.util.List; import javax.swing.*; import javax.swing.border.Border; @@ -42,8 +43,7 @@ import docking.widgets.fieldpanel.support.FieldRange; import docking.widgets.fieldpanel.support.FieldSelection; import docking.widgets.label.GDLabel; import docking.widgets.label.GLabel; -import docking.widgets.table.GTable; -import docking.widgets.table.GTableCellRenderer; +import docking.widgets.table.*; import docking.widgets.textfield.GValidatedTextField; import ghidra.app.services.DataTypeManagerService; import ghidra.app.util.datatype.DataTypeSelectionEditor; @@ -555,6 +555,16 @@ public abstract class CompositeEditorPanel extends JPanel private void createTable() { table = new CompositeTable(model); + + TableColumnModel columnModel = table.getColumnModel(); + if (columnModel instanceof GTableColumnModel) { + GTableColumnModel gColumnModel = (GTableColumnModel) columnModel; + List hiddenColumns = model.getHiddenColumns(); + for (TableColumn column : hiddenColumns) { + gColumnModel.addHiddenColumn(column); + } + } + table.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); table.addMouseListener(new CompositeTableMouseListener()); diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java index 974c79f807..b0cb27cd17 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompositeViewerModel.java @@ -16,11 +16,11 @@ package ghidra.app.plugin.core.compositeeditor; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.function.Consumer; import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumn; import docking.widgets.fieldpanel.support.FieldRange; import docking.widgets.fieldpanel.support.FieldSelection; @@ -34,9 +34,10 @@ import utility.function.Callback; abstract class CompositeViewerModel extends AbstractTableModel implements DataTypeManagerChangeListener { - /** Flag indicating that the model is updating the selection and - * should ignore any attempts to set the selection until it is no - * longer updating. */ + /** + * Flag indicating that the model is updating the selection and should ignore any attempts to + * set the selection until it is no longer updating. + */ protected boolean updatingSelection = false; protected Composite originalComposite; @@ -68,7 +69,7 @@ abstract class CompositeViewerModel extends AbstractTableModel /** Offset of each component field. */ protected int[] columnOffsets = new int[headers.length]; /** Width of each component field. */ - protected int[] columnWidths = { 75, 75, 100, 100, 100, 150 }; // Initial default column widths. + protected int[] columnWidths = { 75, 75, 100, 100, 100, 150 }; // Initial default column widths /** Total component area width. */ protected int width = 0; /** Width of left margin in pixels for the component area. */ @@ -88,10 +89,10 @@ abstract class CompositeViewerModel extends AbstractTableModel } /** - * Returns String.class regardless of columnIndex. + * Returns String.class regardless of columnIndex. * - * @param columnIndex the column being queried - * @return the String.class + * @param columnIndex the column being queried + * @return the String.class */ @Override public Class getColumnClass(int columnIndex) { @@ -125,6 +126,11 @@ abstract class CompositeViewerModel extends AbstractTableModel return COMMENT; } + // subclasses may supply columns + protected List getHiddenColumns() { + return Collections.emptyList(); + } + /** * Terminates listening for category change events within the model. */ @@ -135,19 +141,18 @@ abstract class CompositeViewerModel extends AbstractTableModel } /** - * Returns whether or not the editor has a structure loaded. - * If no structure is loaded then only unload() or dispose() methods - * should be called. - * @return true if an editable structure is currently loaded in the model. + * Returns whether or not the editor has a structure loaded. If no structure is loaded then + * only unload() or dispose() methods should be called. + * + * @return true if an editable structure is currently loaded in the model. */ public boolean isLoaded() { return (viewComposite != null); } /** - * Updates the model to now view the indicated data structure. - * This method should cleanup from a previous load if neccessary - * and must initilize the following model state: + * Updates the model to now view the indicated data structure. This method should cleanup from + * a previous load if necessary and must initialize the following model state: *