-
-
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
Implement task progress indicator (and dialog) in the toolbar #6443
Changes from 1 commit
fdfe074
6fd1811
b883491
255a6e4
38dd89d
1b2aaa6
baf9bd0
40a8feb
cac989b
8f525b8
c877431
1ad9598
cd4e38e
23f8cf0
4628c3d
90ff19e
62d7c14
008d55e
a9f4493
66ac316
e9a7176
d7442cc
5defe3e
fba9c70
6a62e6f
a97af13
3ee4571
44d9ca8
bd2eefd
41efc04
2c9ccea
ff9ce00
d56138b
cf10859
fcb1d0c
396411a
e24c141
478ee05
0557c67
23b7e69
e3ae796
3db3997
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
package org.jabref.gui; | ||
|
||
import java.util.List; | ||
|
||
import javafx.concurrent.Task; | ||
|
||
import org.jabref.logic.l10n.Localization; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Dialog shown when closing of application needs to wait for a save operation to finish. | ||
* Dialog shown when closing of application needs to wait for some background tasks. | ||
*/ | ||
public class WaitForSaveFinishedDialog { | ||
public class WaitForBackgroundtasksFinishedDialog { | ||
|
||
private final DialogService dialogService; | ||
|
||
public WaitForSaveFinishedDialog(DialogService dialogService) { | ||
public WaitForBackgroundtasksFinishedDialog(DialogService dialogService) { | ||
this.dialogService = dialogService; | ||
} | ||
|
||
public void showAndWait(List<BasePanel> basePanels) { | ||
if (basePanels.stream().anyMatch(BasePanel::isSaving)) { | ||
Task<Void> waitForSaveFinished = new Task<Void>() { | ||
public void showAndWait(StateManager stateManager) { | ||
if (stateManager.anyTaskRunningBinding.getValue()) { | ||
Task<Void> waitForBackgroundtasksFinished = new Task<Void>() { | ||
@Override | ||
protected Void call() throws Exception { | ||
while (basePanels.stream().anyMatch(BasePanel::isSaving)) { | ||
System.out.println("THREAD STARTED"); | ||
while (stateManager.anyTaskRunningBinding.getValue()) { | ||
System.out.println("updated value to " + stateManager.tasksProgressBinding.getValue()); | ||
updateProgress(stateManager.tasksProgressBinding.getValue(), 1); | ||
if (isCancelled()) { | ||
return null; | ||
} else { | ||
|
@@ -33,11 +35,20 @@ protected Void call() throws Exception { | |
} | ||
}; | ||
|
||
Thread th = new Thread(waitForBackgroundtasksFinished); | ||
th.setDaemon(true); | ||
th.start(); | ||
|
||
dialogService.showProgressDialogAndWait( | ||
Localization.lang("Please wait..."), | ||
Localization.lang("Waiting for save operation to finish") + "...", | ||
waitForSaveFinished | ||
Localization.lang("Waiting for background tasks to finish") + "...", | ||
waitForBackgroundtasksFinished | ||
); | ||
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. Add a log statement here as well to make sure that the progress dialog does indeed wait? 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 currently have a log message after the loop to see whether the isCancelled property or my tasks-running property caused the stop. I now also put a log message where you suggested, just after the wait. They are exectued in the correct order. So yes, the wait does work, but the task exits too early. 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 now also get a warning about the binding:
I tried to run the task on the Javafx thread by using:
The loop is then run more often (I guess until the download is finished), but the gui is frozen because of the task. 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. The problem was that the extractor I added to the task list in StateManager did not include the isRunning property. It still did not run perfectly and was not pretty, therefore I moved to a custom dialog which works fine. |
||
try { | ||
Thread.sleep(60000); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
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.
Just a wild guess, could it be that actually all tasks are finished, because the
TaskExectutor
is already shutdown?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 added some logs in JabRefMain's stop method, it is run after the dialogue is already gone.