Skip to content
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

Refine loading code #674

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 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,26 @@ 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.
// 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);
LOGGER.debug("This case should not happen.");
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());
}
}
Loading