Skip to content

Commit

Permalink
Update database context in state manager after loading (#9450)
Browse files Browse the repository at this point in the history
* Update database context in state manager after loading

Fixes #9440

* rename variables and add conmment
  • Loading branch information
Siedlerchr authored Dec 13, 2022
1 parent a5d65f8 commit 513d3aa
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/main/java/org/jabref/gui/LibraryTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,29 @@ public void onDatabaseLoadingFailed(Exception ex) {
dialogService.showErrorDialogAndWait(title, content, ex);
}

public void feedData(BibDatabaseContext bibDatabaseContext) {
public void feedData(BibDatabaseContext bibDatabaseContextFromParserResult) {
cleanUp();

this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext);
// When 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.
// 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.
stateManager.setActiveDatabase(bibDatabaseContext);
stateManager.setActiveDatabase(bibDatabaseContextFromParserResult);

bibDatabaseContext.getDatabase().registerListener(this);
bibDatabaseContext.getMetaData().registerListener(this);
// 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);

stateManager.getOpenDatabases().add(bibDatabaseContextFromParserResult);

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

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

setupMainPanel();
setupAutoCompletion();
Expand Down

0 comments on commit 513d3aa

Please sign in to comment.