-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Chronological navigation in libraries #13863
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
Changes from all commits
1d75410
df50edc
b042e38
589bdd8
a9c95eb
8304feb
a8f57d6
0559d11
e33973a
fbb37fa
d890eea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package org.jabref.gui; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| import org.jabref.model.entry.BibEntry; | ||
|
|
||
| /** | ||
| * Manages the navigation history of viewed entries using two stacks. | ||
| * This class encapsulates the logic of moving back and forward by maintaining a "back" stack for past entries | ||
| * and a "forward" stack for future entries. | ||
| */ | ||
| public class NavigationHistory { | ||
| private final List<BibEntry> previousEntries = new ArrayList<>(); | ||
| private final List<BibEntry> nextEntries = new ArrayList<>(); | ||
| private BibEntry currentEntry; | ||
|
|
||
| /** | ||
| * Sets a new entry as the current one, clearing the forward history. | ||
| * The previously current entry is moved to the back stack. | ||
| * | ||
| * @param entry The BibEntry to add to the history. | ||
| */ | ||
| public void add(BibEntry entry) { | ||
| if (Objects.equals(currentEntry, entry)) { | ||
| return; | ||
| } | ||
|
|
||
| // a new selection invalidates the forward history | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment merely restates what the code does (clearing nextEntries). It doesn't provide additional information about why this is necessary. |
||
| nextEntries.clear(); | ||
|
|
||
| if (currentEntry != null) { | ||
| previousEntries.add(currentEntry); | ||
| } | ||
|
Comment on lines
+34
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Null check for currentEntry indicates possible null state handling. Methods should use Optional instead of null for better type safety and clarity. |
||
| currentEntry = entry; | ||
| } | ||
|
|
||
| /** | ||
| * Moves to the previous entry in the history. | ||
| * The current entry is pushed to the forward stack, and the last entry from the back stack becomes current. | ||
| * | ||
| * @return An Optional containing the previous BibEntry, or an empty Optional if there's no history to go back to. | ||
| */ | ||
| public Optional<BibEntry> back() { | ||
| if (canGoBack()) { | ||
| nextEntries.add(currentEntry); | ||
| currentEntry = previousEntries.removeLast(); | ||
| return Optional.of(currentEntry); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| /** | ||
| * Moves to the next entry in the history. | ||
| * The current entry is pushed to the back stack, and the last entry from the forward stack becomes current. | ||
| * | ||
| * @return An Optional containing the next BibEntry, or an empty Optional if there is no "forward" history. | ||
| */ | ||
| public Optional<BibEntry> forward() { | ||
| if (canGoForward()) { | ||
| previousEntries.add(currentEntry); | ||
| currentEntry = nextEntries.removeLast(); | ||
| return Optional.of(currentEntry); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| public boolean canGoBack() { | ||
| return !previousEntries.isEmpty(); | ||
| } | ||
|
|
||
| public boolean canGoForward() { | ||
| return !nextEntries.isEmpty(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using plain ArrayList instead of JavaFX ObservableList prevents UI from automatically updating when the collection changes. This impacts reactive UI updates.