Skip to content

Commit 3725eb0

Browse files
committed
Merge branch 'GP-5557_ghidra1_CompositeEditorFixes' into patch
2 parents 5746f93 + 0ef28cb commit 3725eb0

File tree

85 files changed

+698
-628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+698
-628
lines changed

Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/data/DBTraceDataTypeManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -217,8 +217,8 @@ public void flushEvents() {
217217
}
218218

219219
@Override
220-
public void endTransaction(int transactionID, boolean commit) {
221-
trace.endTransaction(transactionID, commit);
220+
public boolean endTransaction(int transactionID, boolean commit) {
221+
return trace.endTransaction(transactionID, commit);
222222
}
223223

224224
@Override

Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,8 @@ public int startTransaction(String description, AbortedTransactionListener liste
11731173
}
11741174

11751175
@Override
1176-
public void endTransaction(int transactionID, boolean commit) {
1177-
trace.endTransaction(transactionID, commit);
1176+
public boolean endTransaction(int transactionID, boolean commit) {
1177+
return trace.endTransaction(transactionID, commit);
11781178
}
11791179

11801180
@Override

Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/program/DBTraceProgramViewRegisters.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -384,8 +384,8 @@ public int startTransaction(String description, AbortedTransactionListener liste
384384
}
385385

386386
@Override
387-
public void endTransaction(int transactionID, boolean commit) {
388-
view.endTransaction(transactionID, commit);
387+
public boolean endTransaction(int transactionID, boolean commit) {
388+
return view.endTransaction(transactionID, commit);
389389
}
390390

391391
@Override

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/AddBitFieldAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AddBitFieldAction extends CompositeEditorTableAction {
2626
"Add a bitfield at the position of a selected component";
2727
private static String[] POPUP_PATH = new String[] { ACTION_NAME };
2828

29-
public AddBitFieldAction(CompositeEditorProvider provider) {
29+
public AddBitFieldAction(CompositeEditorProvider<?, ?> provider) {
3030
super(provider, ACTION_NAME, GROUP_NAME, POPUP_PATH, null, null);
3131
setDescription(DESCRIPTION);
3232
if (!(model instanceof CompEditorModel)) {
@@ -46,9 +46,9 @@ public boolean isEnabledForContext(ActionContext context) {
4646
return false;
4747
}
4848
boolean enabled = true;
49-
CompEditorModel editorModel = (CompEditorModel) model;
49+
CompEditorModel<?> editorModel = (CompEditorModel<?>) model;
5050
// Unions do not support non-packed manipulation of bitfields
51-
if (!(provider instanceof StructureEditorProvider structProvider) ||
51+
if (!(provider instanceof StructureEditorProvider) ||
5252
editorModel.isPackingEnabled() || editorModel.getNumSelectedRows() != 1) {
5353
enabled = false;
5454
}

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ApplyAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class ApplyAction extends CompositeEditorTableAction {
3232
private final static Icon ICON = new GIcon("icon.plugin.composite.editor.apply");
3333
private final static String[] POPUP_PATH = new String[] { "Apply Edits" };
3434

35-
public ApplyAction(CompositeEditorProvider provider) {
35+
public ApplyAction(CompositeEditorProvider<?, ?> provider) {
3636
super(provider, ACTION_NAME, GROUP_NAME, POPUP_PATH, null, ICON);
3737

3838
setDescription("Apply editor changes");

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ArrayAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class ArrayAction extends CompositeEditorTableAction {
3838
private final static KeyStroke KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, 0);
3939
private static String[] POPUP_PATH = new String[] { ACTION_NAME };
4040

41-
public ArrayAction(CompositeEditorProvider provider) {
41+
public ArrayAction(CompositeEditorProvider<?, ?> provider) {
4242
super(provider, ACTION_NAME, GROUP_NAME, POPUP_PATH, null, ICON);
4343
setDescription(DESCRIPTION);
4444
setKeyBindingData(new KeyBindingData(KEY_STROKE));

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/ClearAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ClearAction extends CompositeEditorTableAction {
3333
private final static String[] POPUP_PATH = new String[] { "Clear" };
3434
private final static KeyStroke KEY_STROKE = KeyStroke.getKeyStroke(KeyEvent.VK_C, 0);
3535

36-
public ClearAction(CompositeEditorProvider provider) {
36+
public ClearAction(CompositeEditorProvider<?, ?> provider) {
3737
super(provider, ACTION_NAME, GROUP_NAME, POPUP_PATH, null, ICON);
3838

3939
setDescription("Clear the selected components");

Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/compositeeditor/CompEditorModel.java

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
import ghidra.util.exception.*;
3030
import ghidra.util.task.TaskMonitor;
3131

32-
public abstract class CompEditorModel extends CompositeEditorModel {
32+
public abstract class CompEditorModel<T extends Composite> extends CompositeEditorModel<T> {
3333

3434
private volatile boolean consideringReplacedDataType = false;
3535

3636
/**
3737
* Creates a model for editing a composite data type.
3838
* @param provider the provider that is using this model for editing.
3939
*/
40-
CompEditorModel(CompositeEditorProvider provider) {
40+
CompEditorModel(CompositeEditorProvider<T, ? extends CompEditorModel<T>> provider) {
4141
super(provider);
4242
}
4343

@@ -54,7 +54,7 @@ public boolean hasChanges() {
5454
* @param dataType the composite data type being edited.
5555
*/
5656
@Override
57-
public void load(Composite dataType) {
57+
public void load(T dataType) {
5858
super.load(dataType);
5959
fixSelection();
6060
selectionChanged();
@@ -76,7 +76,7 @@ public boolean apply() throws InvalidDataTypeException {
7676
}
7777

7878
FieldSelection saveSelection = new FieldSelection(selection);
79-
Composite originalDt = getOriginalComposite();
79+
T originalDt = getOriginalComposite();
8080
if (originalDt == null || originalDTM == null) {
8181
throw new IllegalStateException(
8282
"Can't apply edits without a data type or data type manager.");
@@ -118,7 +118,8 @@ public boolean apply() throws InvalidDataTypeException {
118118
load(originalDt);
119119
}
120120
else {
121-
Composite dt = (Composite) originalDTM.resolve(viewComposite, null);
121+
@SuppressWarnings("unchecked")
122+
T dt = (T) originalDTM.resolve(viewComposite, null);
122123
load(dt);
123124
}
124125
return true;
@@ -376,7 +377,6 @@ protected void deleteComponent(int rowIndex) {
376377
int componentOrdinal = convertRowToOrdinal(rowIndex);
377378
delete(componentOrdinal);
378379
fixSelection();
379-
componentEdited();
380380
selectionChanged();
381381
}
382382

@@ -411,8 +411,6 @@ void deleteComponentRange(int startRowIndex, int endRowIndex, TaskMonitor monito
411411
}
412412
viewDTM.withTransaction("Delete Components", () -> viewComposite.delete(ordinals));
413413
fixSelection();
414-
componentEdited();
415-
notifyCompositeChanged();
416414
selectionChanged();
417415
}
418416

@@ -427,12 +425,7 @@ public void deleteSelectedComponents() throws UsrException {
427425

428426
int[] selectedComponents = getSelectedComponentRows();
429427
int firstRowIndex = !selection.isEmpty() ? selectedComponents[0] : getRowCount();
430-
try {
431-
delete(selectedComponents);
432-
}
433-
finally {
434-
componentEdited();
435-
}
428+
delete(selectedComponents);
436429
selection.addRange(firstRowIndex, firstRowIndex + 1);
437430
fixSelection();
438431
selectionChanged();
@@ -532,7 +525,6 @@ public DataTypeComponent insert(int rowIndex, DataType datatype, int length)
532525
}
533526
DataTypeComponent dtc = insert(rowIndex, datatype, length, null, null);
534527
fixSelection();
535-
componentEdited();
536528
selectionChanged();
537529
return dtc;
538530
}
@@ -562,7 +554,6 @@ protected void insertComponentMultiple(int rowIndex, DataType dataType, int dtLe
562554
checkIsAllowableDataType(dataType);
563555
insertMultiple(rowIndex, dataType, dtLen, multiple, monitor);
564556
fixSelection();
565-
componentEdited();
566557
selectionChanged();
567558
}
568559

@@ -601,7 +592,7 @@ public DataTypeComponent add(int rowIndex, DataType dt) throws UsrException {
601592
});
602593

603594
fixSelection();
604-
componentEdited();
595+
// componentEdited();
605596
selectionChanged();
606597
return dtc;
607598
}
@@ -637,7 +628,7 @@ public DataTypeComponent add(int rowIndex, DataType dt, int dtLength) throws Usr
637628
}
638629

639630
fixSelection();
640-
componentEdited();
631+
//componentEdited();
641632
selectionChanged();
642633
return dtc;
643634
}
@@ -753,7 +744,6 @@ public DataTypeComponent replace(int rowIndex, DataType datatype, int length)
753744
replace(rowIndex, datatype, newCompSize, oldDtc.getFieldName(), oldDtc.getComment());
754745

755746
fixSelection();
756-
componentEdited();
757747
selectionChanged();
758748
return dtc;
759749
}
@@ -806,7 +796,6 @@ protected DataTypeComponent replaceComponentRange(int startRowIndex, int endRowI
806796
}
807797
dtc.setComment(oldDtc.getComment());
808798
fixSelection();
809-
componentEdited();
810799
selectionChanged();
811800
return dtc;
812801
}
@@ -994,7 +983,6 @@ public boolean moveUp() throws NoSuchElementException {
994983
int newIndex = startIndex - 1;
995984
moved = shiftComponentsUp(startIndex, endIndex);
996985
if (moved) {
997-
componentEdited();
998986
FieldSelection tmpFieldSelection = new FieldSelection();
999987
tmpFieldSelection.addRange(newIndex, newIndex + numSelected);
1000988
setSelection(tmpFieldSelection);
@@ -1018,7 +1006,6 @@ public boolean moveDown() throws NoSuchElementException {
10181006
int newIndex = startIndex + 1;
10191007
moved = shiftComponentsDown(startIndex, endIndex);
10201008
if (moved) {
1021-
componentEdited();
10221009
FieldSelection tmpFieldSelection = new FieldSelection();
10231010
tmpFieldSelection.addRange(newIndex, newIndex + numSelected);
10241011
setSelection(tmpFieldSelection);
@@ -1038,7 +1025,6 @@ public void duplicateMultiple(int rowIndex, int multiple, TaskMonitor monitor)
10381025
// Adjust the selection since we added some components. Select last component added.
10391026
setSelection(new int[] { rowIndex + multiple });
10401027

1041-
componentEdited();
10421028
lastNumDuplicates = multiple;
10431029
}
10441030

@@ -1143,9 +1129,7 @@ public int getRowCount() {
11431129
public void setValueAt(Object aValue, int rowIndex, int modelColumnIndex) {
11441130
try {
11451131
settingValueAt = true;
1146-
if (fieldEdited(aValue, rowIndex, modelColumnIndex)) {
1147-
componentEdited();
1148-
}
1132+
fieldEdited(aValue, rowIndex, modelColumnIndex);
11491133
}
11501134
finally {
11511135
settingValueAt = false;
@@ -1284,7 +1268,7 @@ public void restored(DataTypeManager dataTypeManager) {
12841268
return;
12851269
}
12861270

1287-
Composite composite = getOriginalComposite();
1271+
T composite = getOriginalComposite();
12881272
boolean reload = true;
12891273
if (hasChanges || !viewComposite.isEquivalent(composite)) {
12901274
hasChanges = true;
@@ -1323,7 +1307,11 @@ public void restored(DataTypeManager dataTypeManager) {
13231307
public void dataTypeRemoved(DataTypeManager dtm, DataTypePath path) {
13241308

13251309
if (dtm != originalDTM) {
1326-
return; // Different DTM than the one for this data type.
1310+
throw new AssertException("Listener only supports original DTM");
1311+
}
1312+
1313+
if (!isLoaded()) {
1314+
return;
13271315
}
13281316

13291317
DataType dataType = viewDTM.getDataType(path.getCategoryPath(), path.getDataTypeName());
@@ -1380,7 +1368,7 @@ public void dataTypeRemoved(DataTypeManager dtm, DataTypePath path) {
13801368
public void dataTypeRenamed(DataTypeManager dtm, DataTypePath oldPath, DataTypePath newPath) {
13811369

13821370
if (dtm != originalDTM) {
1383-
return; // Different DTM than the one for this data type.
1371+
throw new AssertException("Listener only supports original DTM");
13841372
}
13851373

13861374
if (!isLoaded()) {
@@ -1434,7 +1422,11 @@ public void dataTypeRenamed(DataTypeManager dtm, DataTypePath oldPath, DataTypeP
14341422
public void dataTypeMoved(DataTypeManager dtm, DataTypePath oldPath, DataTypePath newPath) {
14351423

14361424
if (dtm != originalDTM) {
1437-
return; // Different DTM than the one for this data type.
1425+
throw new AssertException("Listener only supports original DTM");
1426+
}
1427+
1428+
if (!isLoaded()) {
1429+
return;
14381430
}
14391431

14401432
DataType dt = viewDTM.getDataType(oldPath);
@@ -1468,20 +1460,14 @@ public void dataTypeMoved(DataTypeManager dtm, DataTypePath oldPath, DataTypePat
14681460
public void dataTypeChanged(DataTypeManager dtm, DataTypePath path) {
14691461
try {
14701462

1471-
if (!isLoaded()) {
1472-
return;
1463+
if (dtm != originalDTM) {
1464+
throw new AssertException("Listener only supports original DTM");
14731465
}
14741466

1475-
if (dtm instanceof CompositeViewerDataTypeManager) {
1476-
// required to detect settings changes
1477-
componentEdited();
1467+
if (!isLoaded()) {
14781468
return;
14791469
}
14801470

1481-
if (dtm != originalDTM) {
1482-
return; // Different DTM than the one for this data type.
1483-
}
1484-
14851471
// If we don't currently have any modifications that need applying and
14861472
// the structure in the editor just changed, then show the changed
14871473
// structure.
@@ -1566,7 +1552,7 @@ public void dataTypeReplaced(DataTypeManager dtm, DataTypePath oldPath, DataType
15661552
DataType newDataType) {
15671553

15681554
if (dtm != originalDTM) {
1569-
return; // Different DTM than the one for this data type.
1555+
throw new AssertException("Listener only supports original DTM");
15701556
}
15711557

15721558
if (!isLoaded()) {
@@ -1723,15 +1709,6 @@ public int getLastNumDuplicates() {
17231709
return lastNumDuplicates;
17241710
}
17251711

1726-
/**
1727-
* Called whenever the data structure's modification state changes.
1728-
*/
1729-
void componentEdited() {
1730-
updateAndCheckChangeState(); // Update the composite's change state information.
1731-
fireTableDataChanged();
1732-
componentDataChanged();
1733-
}
1734-
17351712
protected int convertRowToOrdinal(int rowIndex) {
17361713
return rowIndex;
17371714
}

0 commit comments

Comments
 (0)