Skip to content

Commit

Permalink
Removed WaitForBackgroundtasksFinishedDialog
Browse files Browse the repository at this point in the history
More in line with the other JabRef dialogs
Addresses #6443 (comment)
  • Loading branch information
btut committed May 11, 2020
1 parent 2c9ccea commit ff9ce00
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 66 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ Optional<ButtonType> showCustomButtonDialogAndWait(Alert.AlertType type, String
*/
<V> Optional<Void> showProgressDialogAndWait(String title, String content, Task<V> task);

/**
* Constructs and shows a dialog showing the progress of running background tasks.
* Clicking cancel will cancel the underlying service and close the dialog.
* The dialog will exit as soon as none of the background tasks are running
*
* @param title title of the dialog
* @param content message to show below the list of background tasks
* @param stateManager The {@link StateManager} which contains the background tasks
* @return
*/
<V> Optional<ButtonType> showBackgroundProgressDialogAndWait(String title, String content, StateManager stateManager);

/**
* Notify the user in an non-blocking way (i.e., in form of toast in a snackbar).
*
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import javafx.beans.binding.Bindings;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.print.PrinterJob;
import javafx.scene.Group;
Expand All @@ -23,16 +25,19 @@
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.util.Duration;

import org.jabref.gui.icon.IconTheme;
import org.jabref.gui.util.BackgroundTask;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.gui.util.FileDialogConfiguration;
import org.jabref.gui.util.ThemeLoader;
Expand All @@ -43,8 +48,10 @@
import com.jfoenix.controls.JFXSnackbar;
import com.jfoenix.controls.JFXSnackbar.SnackbarEvent;
import com.jfoenix.controls.JFXSnackbarLayout;
import org.controlsfx.control.TaskProgressView;
import org.controlsfx.dialog.ExceptionDialog;
import org.controlsfx.dialog.ProgressDialog;
import org.fxmisc.easybind.EasyBind;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -286,6 +293,39 @@ public <V> Optional<Void> showProgressDialogAndWait(String title, String content
return progressDialog.showAndWait();
}

@Override
public <V> Optional<ButtonType> showBackgroundProgressDialogAndWait(String title, String content, StateManager stateManager) {
TaskProgressView taskProgressView = new TaskProgressView();
EasyBind.listBind(taskProgressView.getTasks(), stateManager.getBackgroundTasks());
taskProgressView.setRetainTasks(false);
taskProgressView.setGraphicFactory(BackgroundTask.iconCallback);

Label message = new Label(content);

VBox box = new VBox(taskProgressView, message);

DialogPane contentPane = new DialogPane();
contentPane.setContent(box);

FXDialog alert = new FXDialog(AlertType.WARNING, title);
alert.setDialogPane(contentPane);
alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.CANCEL);
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alert.setResizable(true);
themeLoader.installCss(alert.getDialogPane().getScene(), preferences);

stateManager.anyTaskRunningBinding.addListener((observable, oldValue, newValue) -> {
if (!newValue) {
alert.setResult(ButtonType.YES);
alert.close();
}
});

Dialog<ButtonType> dialog = () -> alert.showAndWait();

return showCustomDialogAndWait(dialog);
}

@Override
public void notify(String message) {
LOGGER.info(message);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,11 @@ public boolean quit() {
the background tasks may make changes themselves that need saving.
*/
if (stateManager.anyTaskRunningBinding.getValue()) {
WaitForBackgroundtasksFinishedDialog waitForBackgroundtasksFinishedDialog = new WaitForBackgroundtasksFinishedDialog(dialogService);
if (!waitForBackgroundtasksFinishedDialog.showAndWait(stateManager, themeLoader, prefs)) {
if (!(dialogService.showBackgroundProgressDialogAndWait(
Localization.lang("Please wait..."),
Localization.lang("Waiting for background tasks to finish. Quit anyway?"),
stateManager
).orElse(ButtonType.CANCEL) == ButtonType.YES)) {
return false;
}
}
Expand Down

This file was deleted.

0 comments on commit ff9ce00

Please sign in to comment.