Skip to content

Commit

Permalink
improve find entry (#1915)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriba authored and koppor committed Sep 5, 2016
1 parent a1bcdc3 commit 5dcc05a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#


### Fixed
- Fixed selecting an entry out of multiple duplicates
- Fixed NullPointerException when opening search result window for an untitled database
- Fixed entry table traversal with Tab (no column traversal thus no double jump)
- Fixed [#1757](https://github.com/JabRef/jabref/issues/1757): Crash after saving illegal argument in entry editor
Expand Down
36 changes: 6 additions & 30 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,7 @@ private void paste() {
selectionListener.editSignalled(firstBE);
}

// If we inserted a duplicate we want to select the duplicate (thus we have to search from the back)
highlightLastEntry(firstBE);
highlightEntry(firstBE);
}
}

Expand Down Expand Up @@ -1046,10 +1045,7 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
} catch (SaveException ex) {
if (ex.specificEntry()) {
// Error occurred during processing of the entry. Highlight it:
final int row = mainTable.findEntry(ex.getEntry());
final int topShow = Math.max(0, row - 3);
mainTable.setRowSelectionInterval(row, row);
mainTable.scrollTo(topShow);
highlightEntry(ex.getEntry());
showEntry(ex.getEntry());
} else {
LOGGER.warn("Could not save", ex);
Expand Down Expand Up @@ -1155,14 +1151,7 @@ public BibEntry newEntry(EntryType type) {
mode = BasePanelMode.WILL_SHOW_EDITOR;
}

int row = mainTable.findEntry(be);
if (row >= 0) {
highlightEntry(be); // Selects the entry. The selection listener will open the editor.
} else {
// The entry is not visible in the table, perhaps due to a filtering search
// or group selection. Show the entry editor anyway:
showEntry(be);
}
highlightEntry(be);

markBaseChanged(); // The database just changed.
new FocusRequester(getEntryEditor(be));
Expand Down Expand Up @@ -1477,11 +1466,7 @@ public void setupMainPanel() {
// otherwise set the bottom component to null.
if (mode == BasePanelMode.SHOWING_PREVIEW) {
mode = BasePanelMode.SHOWING_NOTHING;
int row = mainTable.findEntry(currentPreview.getEntry());
if (row >= 0) {
mainTable.setRowSelectionInterval(row, row);
}

highlightEntry(currentPreview.getEntry());
} else if (mode == BasePanelMode.SHOWING_EDITOR) {
mode = BasePanelMode.SHOWING_NOTHING;
} else {
Expand Down Expand Up @@ -1720,22 +1705,13 @@ public void highlightEntry(final BibEntry bibEntry) {
highlightEntry(mainTable.findEntry(bibEntry));
}

/**
* This method selects the given entry (searches from the back), and scrolls it into view in the table.
* If an entryEditor is shown, it is given focus afterwards.
*/
public void highlightLastEntry(final BibEntry bibEntry) {
highlightEntry(mainTable.findLastEntry(bibEntry));
}

/**
* This method selects the entry on the given position, and scrolls it into view in the table.
* If an entryEditor is shown, it is given focus afterwards.
*/
public void highlightEntry(int pos) {
if (pos >= 0) {
mainTable.clearSelection();
mainTable.addRowSelectionInterval(pos, pos);
if (pos >= 0 && pos < mainTable.getRowCount()) {
mainTable.setRowSelectionInterval(pos, pos);
mainTable.ensureVisible(pos);
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/net/sf/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,14 @@ public void setSelected(int row) {
}

public int findEntry(BibEntry entry) {
return model.getTableRows().indexOf(entry);
}

public int findLastEntry(BibEntry entry) {
return model.getTableRows().lastIndexOf(entry);
EventList<BibEntry> tableRows = model.getTableRows();
for (int row = 0; row < tableRows.size(); row++) {
BibEntry bibEntry = tableRows.get(row);
if (entry == bibEntry) { // NOPMD (equals doesn't recognise duplicates)
return row;
}
}
return -1;
}

/**
Expand Down

0 comments on commit 5dcc05a

Please sign in to comment.