GT-3396 - File Chooser - review fixes - updated file chooser lookup to

deal with mixed sorting
This commit is contained in:
dragonmacher 2019-12-16 15:58:01 -05:00
parent 6918ef7b45
commit 5548904414
6 changed files with 65 additions and 6 deletions

View file

@ -65,6 +65,16 @@ public abstract class AutoLookup {
*/
public abstract boolean isSorted(int column);
/**
* A method that subclasses can override to affect whether this class uses a binary search
* for a particular column
* @param column the column
* @return true if the binary search algorithm will work on the given column
*/
protected boolean canBinarySearchColumn(int column) {
return isSorted(column);
}
/**
* Returns true if the currently sorted column is sorted ascending. This is used in
* conjunction with {@link #isSorted(int)}. If that method returns false, then this method
@ -97,6 +107,7 @@ public abstract class AutoLookup {
*/
public void setColumn(int column) {
this.lookupColumn = column;
lastLookup = null;
}
/**
@ -148,7 +159,7 @@ public abstract class AutoLookup {
}
}
if (isSorted(lookupColumn)) {
if (canBinarySearchColumn(lookupColumn)) {
return autoLookupBinary(text);
}
return autoLookupLinear(text);
@ -295,6 +306,7 @@ public abstract class AutoLookup {
// was fruitless, then so too will be this one, since we use a
// 'starts with' match.
skip = true;
when = lastTime; // don't save time if no match found; trigger a timeout
}
}

View file

@ -29,8 +29,10 @@ import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import docking.event.mouse.GMouseListenerAdapter;
import docking.widgets.AutoLookup;
import docking.widgets.label.GDLabel;
import docking.widgets.list.GList;
import docking.widgets.list.GListAutoLookup;
import ghidra.util.exception.AssertException;
class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryModelIf {
@ -254,6 +256,16 @@ class DirectoryList extends GList<File> implements GhidraFileChooserDirectoryMod
chooser.userSelectedFiles(selectedFiles);
}
@Override
protected AutoLookup createAutoLookup() {
return new GListAutoLookup<>(this) {
@Override
protected boolean canBinarySearchColumn(int column) {
return false;
}
};
}
@Override
public int[] getSelectedRows() {
return getSelectedIndices();

View file

@ -29,6 +29,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.table.TableColumn;
import docking.event.mouse.GMouseListenerAdapter;
import docking.widgets.AutoLookup;
import docking.widgets.GenericDateCellRenderer;
import docking.widgets.table.*;
import utilities.util.FileUtilities;
@ -49,6 +50,7 @@ class DirectoryTable extends GTable implements GhidraFileChooserDirectoryModelIf
private void build() {
setAutoLookupColumn(DirectoryTableModel.FILE_COL);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setShowGrid(false);
@ -137,6 +139,19 @@ class DirectoryTable extends GTable implements GhidraFileChooserDirectoryModelIf
column.setCellRenderer(new GenericDateCellRenderer());
}
@Override
protected AutoLookup createAutoLookup() {
return new GTableAutoLookup(this) {
@Override
protected boolean canBinarySearchColumn(int column) {
if (column == DirectoryTableModel.FILE_COL) {
return false;
}
return super.canBinarySearchColumn(column);
}
};
}
private void maybeSelectItem(MouseEvent e) {
Point point = e.getPoint();
int row = rowAtPoint(point);
@ -275,5 +290,4 @@ class DirectoryTable extends GTable implements GhidraFileChooserDirectoryModelIf
}
}
}

View file

@ -38,7 +38,7 @@ import docking.widgets.GComponent;
*/
public class GList<T> extends JList<T> implements GComponent {
private GListAutoLookup<T> autoLookup = new GListAutoLookup<T>(this);
private AutoLookup autoLookup = createAutoLookup();
/**
* Constructs a <code>GhidraList</code> with an empty model.
@ -91,7 +91,7 @@ public class GList<T> extends JList<T> implements GComponent {
addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
public void keyPressed(KeyEvent e) {
autoLookup.keyTyped(e);
}
});
@ -112,4 +112,13 @@ public class GList<T> extends JList<T> implements GComponent {
// only the object's toString(), which will not always match what the user sees on screen
return -1;
}
/**
* Allows subclasses to change the type of {@link AutoLookup} created by this list
* @return the auto lookup
*/
protected AutoLookup createAutoLookup() {
return new GListAutoLookup<>(this);
}
}

View file

@ -87,7 +87,7 @@ public class GTable extends JTable {
private boolean enableActionKeyBindings;
private KeyListener autoLookupListener;
private GTableAutoLookup autoLookup = new GTableAutoLookup(this);
private AutoLookup autoLookup = createAutoLookup();
/** A list of default renderers created by this table */
protected List<TableCellRenderer> defaultGTableRendererList = new ArrayList<>();
@ -187,6 +187,14 @@ public class GTable extends JTable {
return new GTableColumnModel(this);
}
/**
* Allows subclasses to change the type of {@link AutoLookup} created by this table
* @return the auto lookup
*/
protected AutoLookup createAutoLookup() {
return new GTableAutoLookup(this);
}
@Override
public void setColumnModel(TableColumnModel columnModel) {
super.setColumnModel(columnModel);
@ -281,6 +289,10 @@ public class GTable extends JTable {
autoLookup.setTimeout(timeout);
}
protected AutoLookup getAutoLookup() {
return autoLookup;
}
/**
* Sets the column in which auto-lookup will be enabled.
*

View file

@ -29,7 +29,7 @@ public class GTableAutoLookup extends AutoLookup {
private GTable table;
GTableAutoLookup(GTable table) {
public GTableAutoLookup(GTable table) {
this.table = table;
}