-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Improve library loading UX #7119
Changes from 4 commits
5ec4027
e1af860
5f2d7ea
a1ee474
1ca8616
8c0fd83
f43c2ff
ef088af
77061c8
b7ca2d3
2e71e7a
5783b30
be3c2bf
6c3149c
8b32c09
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 |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import javafx.scene.Node; | ||
import javafx.scene.control.ProgressIndicator; | ||
import javafx.scene.layout.BorderPane; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.Globals; | ||
import org.jabref.gui.JabRefFrame; | ||
|
@@ -30,6 +34,7 @@ | |
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException; | ||
import org.jabref.logic.shared.exception.NotASharedDatabaseException; | ||
import org.jabref.logic.util.StandardFileType; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.preferences.JabRefPreferences; | ||
|
||
import org.slf4j.Logger; | ||
|
@@ -59,8 +64,8 @@ public OpenDatabaseAction(JabRefFrame frame) { | |
/** | ||
* Go through the list of post open actions, and perform those that need to be performed. | ||
* | ||
* @param libraryTab The BasePanel where the database is shown. | ||
* @param result The result of the BIB file parse operation. | ||
* @param libraryTab The BasePanel where the database is shown. | ||
* @param result The result of the BIB file parse operation. | ||
*/ | ||
public static void performPostOpenActions(LibraryTab libraryTab, ParserResult result) { | ||
for (GUIPostOpenAction action : OpenDatabaseAction.POST_OPEN_ACTIONS) { | ||
|
@@ -159,17 +164,18 @@ public void openFiles(List<Path> filesToOpen, boolean raisePanel) { | |
*/ | ||
private void openTheFile(Path file, boolean raisePanel) { | ||
Objects.requireNonNull(file); | ||
if (Files.exists(file)) { | ||
|
||
BackgroundTask.wrap(() -> loadDatabase(file)) | ||
.onSuccess(result -> { | ||
LibraryTab libraryTab = addNewDatabase(result, file, raisePanel); | ||
OpenDatabaseAction.performPostOpenActions(libraryTab, result); | ||
}) | ||
.onFailure(ex -> dialogService.showErrorDialogAndWait(Localization.lang("Connection error"), | ||
ex.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."))) | ||
.executeWith(Globals.TASK_EXECUTOR); | ||
if (!Files.exists(file)) { | ||
return; | ||
} | ||
|
||
BackgroundTask<ParserResult> backgroundTask = BackgroundTask.wrap(() -> loadDatabase(file)); | ||
LibraryTab libraryTab = LibraryTab.createNewEmptyLibraryTab(frame, file); | ||
onDatabaseLoadingStarted(libraryTab, backgroundTask); | ||
|
||
backgroundTask.onSuccess(result -> onDatabaseLoadingSucceed(libraryTab, result)) | ||
.onFailure(ex -> onDatabaseLoadingFailed(libraryTab, ex)) | ||
.executeWith(Globals.TASK_EXECUTOR); | ||
|
||
} | ||
|
||
private ParserResult loadDatabase(Path file) throws Exception { | ||
|
@@ -210,4 +216,35 @@ private LibraryTab addNewDatabase(ParserResult result, final Path file, boolean | |
frame.addTab(libraryTab, raisePanel); | ||
return libraryTab; | ||
} | ||
|
||
/* The layout to display in the tab when it's loading*/ | ||
public Node createLoadingLayout() { | ||
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. I would let the 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. There was a bug when I close a loading tab before it finishes, the tab next to it TableView would shrink but it seems using placeholder fixed it, Thank you |
||
ProgressIndicator progressIndicator = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS); | ||
BorderPane pane = new BorderPane(); | ||
pane.setCenter(progressIndicator); | ||
|
||
return pane; | ||
} | ||
|
||
public void onDatabaseLoadingStarted(LibraryTab libraryTab, BackgroundTask<?> backgroundTask) { | ||
Node loadingLayout = createLoadingLayout(); | ||
libraryTab.setContent(loadingLayout); | ||
libraryTab.setOnCloseRequest(e -> backgroundTask.cancel()); | ||
|
||
frame.addTab(libraryTab, true); | ||
} | ||
|
||
public void onDatabaseLoadingSucceed(LibraryTab libraryTab, ParserResult result) { | ||
BibDatabaseContext context = result.getDatabaseContext(); | ||
libraryTab.feedData(context); | ||
|
||
OpenDatabaseAction.performPostOpenActions(libraryTab, result); | ||
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. I would put this before the |
||
} | ||
|
||
public void onDatabaseLoadingFailed(LibraryTab libraryTab, Exception ex) { | ||
String title = Localization.lang("Connection error"); | ||
String content = String.format("%s\n\n%s", ex.getMessage(), Localization.lang("A local copy will be opened.")); | ||
|
||
dialogService.showErrorDialogAndWait(title, content, ex); | ||
} | ||
} |
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.
I think this should be in the opendatabaseaction class (as it's not really connected to the library tab)
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.
and by this, you mean trackOpenNewDatabase(), right?
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.
yes!