Ghidra is a software reverse engineering (SRE) framework
Changed GTable selectionManager to not restore view posistion if the selection did not change.
ghidravore5692ea4b1163
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.javaindex b538f4e29e..95fe3c29c5 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/BundleStatusComponentProvider.java@@ -28,6 +28,7 @@ import javax.swing.event.TableModelEvent;import docking.action.builder.ActionBuilder;import docking.widgets.filechooser.GhidraFileChooser;import docking.widgets.filechooser.GhidraFileChooserMode;+import docking.widgets.table.GTable;import docking.widgets.table.GTableFilterPanel;import generic.jar.ResourceFile;import generic.util.Path;@@ -55,7 +56,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {static final String PREFERENCE_LAST_SELECTED_BUNDLE = "LastGhidraBundle";private JPanel panel;- private LessFreneticGTable bundleStatusTable;+ private GTable bundleStatusTable;private final BundleStatusTableModel bundleStatusTableModel;private GTableFilterPanel<BundleStatus> filterPanel;@@ -102,7 +103,7 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {private void build() {panel = new JPanel(new BorderLayout(5, 5));- bundleStatusTable = new LessFreneticGTable(bundleStatusTableModel);+ bundleStatusTable = new GTable(bundleStatusTableModel);bundleStatusTable.setName("BUNDLESTATUS_TABLE");bundleStatusTable.setSelectionBackground(new Color(204, 204, 255));bundleStatusTable.setSelectionForeground(Color.BLACK);@@ -415,8 +416,6 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {@Overridepublic void run(TaskMonitor monitor) throws CancelledException {- // suppress RowObjectSelectionManager repairs until after we're done- bundleStatusTable.chill();List<GhidraBundle> bundles = new ArrayList<>();for (BundleStatus status : statuses) {@@ -450,8 +449,6 @@ public class BundleStatusComponentProvider extends ComponentProviderAdapter {if (anybusy) {notifyTableDataChanged();}-- bundleStatusTable.thaw();}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/LessFreneticGTable.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/LessFreneticGTable.javadeleted file mode 100644index dffa31dbdb..0000000000--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/osgi/LessFreneticGTable.java+++ /dev/null@@ -1,73 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.app.plugin.core.osgi;--import javax.swing.JTable;-import javax.swing.event.TableModelEvent;-import javax.swing.table.TableModel;--import docking.widgets.table.*;--/**- * {@link RowObjectSelectionManager} attempts to repair selections in a filtered table- * before and after filter events. The additional selection events, however, cause focus changes we don't want.- *- * <p>if the behavior is a bug in RowObjectSelectionManager, and it's fixed, this- * class can go away and it's use in {@link BundleStatusComponentProvider} replaced with GTable.- */-class LessFreneticGTable extends GTable {- boolean chilled = false;-- private class MySelectionManager<T> extends RowObjectSelectionManager<T> {-- MySelectionManager(JTable table, RowObjectTableModel<T> model) {- super(table, model);- }-- @Override- public void tableChanged(TableModelEvent event) {- if (!chilled) {- super.tableChanged(event);- }- }-- }-- LessFreneticGTable(TableModel model) {- super(model);- }-- /** suppress issuing table change events */- public void chill() {- chilled = true;- }-- /** resume issuing table change events */- public void thaw() {- chilled = false;- notifyTableChanged(new TableModelEvent(getModel()));- }-- @SuppressWarnings("unchecked")- @Override- protected <T> SelectionManager createSelectionManager() {- TableModel model = getModel();- if (model instanceof RowObjectTableModel) {- return new MySelectionManager<T>(this, (RowObjectTableModel<T>) model);- }- return null;- }-}diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/RowObjectSelectionManager.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/RowObjectSelectionManager.javaindex 9392c86719..573bbf3346 100644--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/RowObjectSelectionManager.java+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/table/RowObjectSelectionManager.java@@ -393,21 +393,22 @@ public class RowObjectSelectionManager<T> extends DefaultListSelectionModelreturn; // either no previous selection, or selection has been filtered out}- restoreSelectedRows(selectedViewRows);+ if (restoreSelectedRows(selectedViewRows)) {- // scroll to the beginning of the selection- Rectangle cellRect = table.getCellRect(selectedViewRows[0], 0, true);- if (cellRect != null) {- table.scrollRectToVisible(cellRect);+ // scroll to the beginning of the selection+ Rectangle cellRect = table.getCellRect(selectedViewRows[0], 0, true);+ if (cellRect != null) {+ table.scrollRectToVisible(cellRect);+ }}}- private void restoreSelectedRows(int[] rows) {+ private boolean restoreSelectedRows(int[] rows) {traceRows("restoreSelectedRows(): ", rows);if (ArrayUtilities.isArrayPrimativeEqual(rows, table.getSelectedRows())) {trace("\tselection hasn't changed--nothing to do");// the selection is the same, nothing to change; don't send out excess events- return;+ return false;}trace("\tpreparing to restore selection");@@ -425,6 +426,7 @@ public class RowObjectSelectionManager<T> extends DefaultListSelectionModelrestoringSelection = false;notifyRestoringSelection(false);trace("\tdone restoring selection");+ return true;}private void notifyRestoringSelection(boolean isPreRestore) {