Skip to content

Commit

Permalink
Add some comments and try to improve variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
koppor committed Jan 11, 2024
1 parent 5dbc76e commit 9e42be7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
23 changes: 11 additions & 12 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,12 @@ private void setDataLoadingTask(BackgroundTask<ParserResult> dataLoadingTask) {
}

/**
* The layout to display in the tab when it's loading
* The layout to display in the tab when it is loading
*/
private Node createLoadingAnimationLayout() {
ProgressIndicator progressIndicator = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS);
BorderPane pane = new BorderPane();
pane.setCenter(progressIndicator);

return pane;
}

Expand All @@ -241,7 +240,7 @@ private void onDatabaseLoadingSucceed(ParserResult result) {
BibDatabaseContext context = result.getDatabaseContext();
OpenDatabaseAction.performPostOpenActions(result, dialogService);

feedData(context);
setDatabaseContext(context);

if (preferencesService.getFilePreferences().shouldFulltextIndexLinkedFiles()) {
try {
Expand All @@ -261,30 +260,30 @@ private void onDatabaseLoadingFailed(Exception ex) {
dialogService.showErrorDialogAndWait(title, content, ex);
}

private void feedData(BibDatabaseContext bibDatabaseContextFromParserResult) {
private void setDatabaseContext(BibDatabaseContext bibDatabaseContext) {
if (this.getTabPane().getSelectionModel().selectedItemProperty().get().equals(this)) {
// If you open an existing library, a library tab with a loading animation is added immediately.
// At that point, the library tab is given a temporary bibDatabaseContext with no entries.
// At that point, the library tab is given a temporary (TODO null?) bibDatabaseContext with no entries.
// This line is necessary because, while there is already a binding that updates the active database when a new tab is added,
// it doesn't handle the case when a library is loaded asynchronously.
// See org.jabref.gui.LibraryTab.createLibraryTab for the asynchronous loading.
stateManager.setActiveDatabase(bibDatabaseContextFromParserResult);
stateManager.setActiveDatabase(bibDatabaseContext);
}

// Remove existing dummy BibDatabaseContext and add correct BibDatabaseContext from ParserResult to trigger changes in the openDatabases list in the stateManager
Optional<BibDatabaseContext> foundExistingBibDatabase = stateManager.getOpenDatabases().stream().filter(databaseContext -> databaseContext.equals(this.bibDatabaseContext)).findFirst();
foundExistingBibDatabase.ifPresent(databaseContext -> stateManager.getOpenDatabases().remove(databaseContext));

this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContextFromParserResult);
this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);

stateManager.getOpenDatabases().add(bibDatabaseContextFromParserResult);
stateManager.getOpenDatabases().add(bibDatabaseContext);

bibDatabaseContextFromParserResult.getDatabase().registerListener(this);
bibDatabaseContextFromParserResult.getMetaData().registerListener(this);
bibDatabaseContext.getDatabase().registerListener(this);
bibDatabaseContext.getMetaData().registerListener(this);

this.tableModel = new MainTableDataModel(getBibDatabaseContext(), preferencesService, stateManager);
citationStyleCache = new CitationStyleCache(bibDatabaseContextFromParserResult);
annotationCache = new FileAnnotationCache(bibDatabaseContextFromParserResult, preferencesService.getFilePreferences());
citationStyleCache = new CitationStyleCache(bibDatabaseContext);
annotationCache = new FileAnnotationCache(bibDatabaseContext, preferencesService.getFilePreferences());

setupMainPanel();
setupAutoCompletion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static void shutdown(BibDatabaseContext bibDatabaseContext, Path backupDi
* Checks whether a backup file exists for the given database file. If it exists, it is checked whether it is
* newer and different from the original.
*
* In case a discarded file is present, the method also returns <code>false</code>, See also {@link #discardBackup()}.
* In case a discarded file is present, the method also returns <code>false</code>, See also {@link #discardBackup(Path)}.
*
* @param originalPath Path to the file a backup should be checked for. Example: jabref.bib.
*
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,6 @@ public MainTableDataModel getTableModel() {
return model;
}

public BibEntry getEntryAt(int row) {
return model.getEntriesFilteredAndSorted().get(row).getEntry();
}

public List<BibEntry> getSelectedEntries() {
return getSelectionModel()
.getSelectedItems()
Expand All @@ -491,11 +487,4 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
.filter(viewModel -> viewModel.getEntry().equals(entry))
.findFirst();
}

public static List<MainTableColumnModel> toColumnModels(List<TableColumn<BibEntryTableViewModel, ?>> columns) {
return columns.stream()
.filter(col -> col instanceof MainTableColumn<?>)
.map(column -> ((MainTableColumn<?>) column).getModel())
.collect(Collectors.toList());
}
}

0 comments on commit 9e42be7

Please sign in to comment.