Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow table sorting #37

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/bindiffhelper/BinDiffHelperProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 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.
Expand All @@ -32,12 +32,14 @@
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.Comparator;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.table.TableRowSorter;

import docking.ActionContext;
import docking.DockingWindowManager;
Expand Down Expand Up @@ -384,6 +386,14 @@ protected void doDiffWork() {

if (createTable) {
table = new GTable();

TableRowSorter<ComparisonTableModel> sorter = new TableRowSorter<>(ctm);
table.setRowSorter(sorter);

// Ensure proper sorting for similarity and confidence
sorter.setComparator(6, Comparator.comparingDouble(o -> (Double) o)); // Similarity
sorter.setComparator(7, Comparator.comparingDouble(o -> (Double) o)); // Confidence

scrollPane = new JScrollPane(table);
gui.removeAll();
gui.add(scrollPane, BorderLayout.CENTER);
Expand Down
21 changes: 14 additions & 7 deletions src/main/java/bindiffhelper/ComparisonTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,20 @@ public boolean isCellEditable(int row, int col) {
return false;
}

public Class<?> getColumnClass(int c) {
if (c == 0)
return Boolean.class;
// else if (c == 5)
// return Double.class;

return String.class;
@Override
public Class<?> getColumnClass(int columnIndex) {
return switch (columnIndex) {
case 0 -> Boolean.class; // Checkbox column
case 1 -> String.class; // Address this file (hex string)
case 2 -> String.class; // Name this file
case 3 -> String.class; // Name Database
case 4 -> String.class; // Address other file (hex string)
case 5 -> String.class; // Name other file
case 6 -> Double.class; // Similarity (numeric)
case 7 -> Double.class; // Confidence (numeric)
case 8 -> String.class; // Algorithm
default -> Object.class;
};
}

public void setValueAt(Object value, int row, int col) {
Expand Down