Added auto-key-generation task to task-progress#7797
Conversation
Auto-key-generation tasks are now shown in the list of background tasks, together with a progress representing entries done / entries. Fixes koppor/jabref#7267
To simplify thread synchronization, the background task is now wrapped in an anonymous class, just as in https://github.com/JabRef/jabref/blob/fa8cc829727ffddd97a9056fd466e7098577f4d7/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
tobiasdiez
left a comment
There was a problem hiding this comment.
A few more remarks concerning the admittedly strange JavaFX conventions around concurrency.
| if (isCanceled) { | ||
| return null; | ||
| } | ||
| showToUser(true); |
There was a problem hiding this comment.
There is this golden rule of concurrency in JavaFX, that you shouldn't update any UI-facing properties in background tasks (or only using updateProgress and updateMessage), see for example https://docs.oracle.com/javafx/2/api/javafx/concurrent/Task.html.
Thus, setting title and message should happen in the constructor and not in the call method.
| titleProperty().set(Localization.lang("Autogenerate citation keys")); | ||
| messageProperty().set(entries.size() + " " + Localization.lang("entries")); | ||
|
|
||
| DefaultTaskExecutor.runInJavaFXThread(() -> { |
There was a problem hiding this comment.
The runInJavaFXThread shouldn't be necessary as this is handled by updateProgress.
There was a problem hiding this comment.
I wondered about that, but it is done in ImportHandler as well. Shall I remove it there as well (in an additional PR)?
There was a problem hiding this comment.
For some reason it is not working in this context, see https://github.com/JabRef/jabref/pull/7209/files#r551271470. Maybe @Siedlerchr still remembers where the problem was.
There was a problem hiding this comment.
The relevant code is
jabref/src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java
Lines 146 to 155 in fa8cc82
There was a problem hiding this comment.
The progress updating is not happening in the fx thread by the BackgroundTask. This will leead to an exception.
There was a problem hiding this comment.
So shall we explicitly make updating the progress variable run on the fx thread in updateProgress?
`
protected void updateProgress(BackgroundProgress newProgress) {
DefaultTaskExecutor.runInJavaFXThread(() -> {
progress.setValue(newProgress);
});
}
`
There was a problem hiding this comment.
Ideally yes it would happend in the BackgroundTask itself, but I am unsure if this has any side effects on existing tasks
There was a problem hiding this comment.
would nesting DefaultTaskExecutor.runInJavaFXThread() be problematic (in addition to being ugly)?
I don't think there are many tasks that use updateProgress right now, let me investigate.
There was a problem hiding this comment.
As far as I (and Intellij) can tell, updateProgress is only used by GenerateCitationKeyAction, FileDownloadTask and ImportHandler.
FileDownloadTask uses EasyBind to update the progress. Does EasyBind already take care of running on the JavaFX thread?
There was a problem hiding this comment.
I'm not sure... then using setValue on progress still leads to the same problems (i.e. you cannot bind something to the progress property). Personally, I would leave the whole what happens on which thread hidden as long as possible, i.e. only the DefaultTaskExecutor cares about these things when converting a background task to a JavaFX task.
I guess these problems we are discussing can be easily fixed by not using the progress/message properties of the background task anywhere outside of the task itself. So here for the citation generation there shouldn't be any problem.
UI-facing properties are done on correct task now, and onSuccess is used.
|
From my point of view this looks now good |
Some languages place the number after the word 'counter', this would result in an ugly message for those languages.
|
Don't forge the l10n (see failing unit test) %0\ entries=%0 entries |
* upstream/main: Added auto-key-generation task to task-progress (JabRef#7797) cleanup temporary files, use prefix "jabref-" (JabRef#7811) Add easier how-to for checklist (JabRef#7813) Fix annotation + package of ACMPortalParserTest (JabRef#7812) Implemented a select all button for the library import function (issue JabRef#7786) (JabRef#7808) Fix for issue 4682 : Restructuring the side pane structure having additional functionality and merging the remove group menus (JabRef#7714)
Auto-key-generation tasks are now shown in the list of background tasks,
together with a progress representing entries done / entries.
Fixes #7267
CHANGELOG.mddescribed in a way that is understandable for the average user (if applicable)