-
-
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
Hide completed background tasks #11821
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: Carl Christian Snethlage <[email protected]>
The diff to the original attempt seems to be: diff --git a/src/main/java/org/jabref/gui/StateManager.java b/src/main/java/org/jabref/gui/StateManager.java
index cf73b00da9..e75ffcdc89 100644
--- a/src/main/java/org/jabref/gui/StateManager.java
+++ b/src/main/java/org/jabref/gui/StateManager.java
@@ -6,6 +6,8 @@ import java.util.Objects;
import java.util.Optional;
import javafx.beans.Observable;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
@@ -65,10 +67,12 @@ public class StateManager {
private final IntegerProperty searchResultSize = new SimpleIntegerProperty(0);
private final IntegerProperty globalSearchResultSize = new SimpleIntegerProperty(0);
private final OptionalObjectProperty<Node> focusOwner = OptionalObjectProperty.empty();
- private final ObservableList<Pair<BackgroundTask<?>, Task<?>>> backgroundTasks = FXCollections.observableArrayList(task -> new Observable[] {task.getValue().progressProperty(), task.getValue().runningProperty()});
- private final EasyBinding<Boolean> anyTaskRunning = EasyBind.reduce(backgroundTasks, tasks -> tasks.map(Pair::getValue).anyMatch(Task::isRunning));
- private final EasyBinding<Boolean> anyTasksThatWillNotBeRecoveredRunning = EasyBind.reduce(backgroundTasks, tasks -> tasks.anyMatch(task -> !task.getKey().willBeRecoveredAutomatically() && task.getValue().isRunning()));
- private final EasyBinding<Double> tasksProgress = EasyBind.reduce(backgroundTasks, tasks -> tasks.map(Pair::getValue).filter(Task::isRunning).mapToDouble(Task::getProgress).average().orElse(1));
+ private final ObservableList<Pair<BackgroundTask<?>, Task<?>>> backgroundTasksPairs = FXCollections.observableArrayList(task -> new Observable[] {task.getValue().progressProperty(), task.getValue().runningProperty()});
+ private final ObservableList<Task<?>> backgroundTasks = EasyBind.map(backgroundTasksPairs, Pair::getValue);
+ private final FilteredList<Task<?>> runningBackgroundTasks = new FilteredList<>(backgroundTasks, Task::isRunning);
+ private final BooleanBinding anyTaskRunning = Bindings.createBooleanBinding(() -> !runningBackgroundTasks.isEmpty(), runningBackgroundTasks);
+ private final EasyBinding<Boolean> anyTasksThatWillNotBeRecoveredRunning = EasyBind.reduce(backgroundTasksPairs, tasks -> tasks.anyMatch(task -> !task.getKey().willBeRecoveredAutomatically() && task.getValue().isRunning()));
+ private final EasyBinding<Double> tasksProgress = EasyBind.reduce(backgroundTasksPairs, tasks -> tasks.map(Pair::getValue).filter(Task::isRunning).mapToDouble(Task::getProgress).average().orElse(1));
private final ObservableMap<String, DialogWindowState> dialogWindowStates = FXCollections.observableHashMap();
private final ObservableList<SidePaneType> visibleSidePanes = FXCollections.observableArrayList();
private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();
@@ -153,16 +157,19 @@ public class StateManager {
return focusOwner.get();
}
+ public ObservableList<Task<?>> getBackgroundTasks() {
+ return backgroundTasks;
+ }
+
public ObservableList<Task<?>> getRunningBackgroundTasks() {
- FilteredList<Pair<BackgroundTask<?>, Task<?>>> pairs = new FilteredList<>(backgroundTasks, task -> task.getValue().isRunning());
- return EasyBind.map(pairs, Pair::getValue);
+ return runningBackgroundTasks;
}
public void addBackgroundTask(BackgroundTask<?> backgroundTask, Task<?> task) {
- this.backgroundTasks.addFirst(new Pair<>(backgroundTask, task));
+ this.backgroundTasksPairs.addFirst(new Pair<>(backgroundTask, task));
}
- public EasyBinding<Boolean> getAnyTaskRunning() {
+ public BooleanBinding getAnyTaskRunning() {
return anyTaskRunning;
}
diff --git a/src/main/java/org/jabref/gui/frame/MainToolBar.java b/src/main/java/org/jabref/gui/frame/MainToolBar.java
index 2f61f953c6..03bbc72e3b 100644
--- a/src/main/java/org/jabref/gui/frame/MainToolBar.java
+++ b/src/main/java/org/jabref/gui/frame/MainToolBar.java
@@ -229,6 +229,7 @@ public class MainToolBar extends ToolBar {
if ((progressViewPopOver != null) && (progressViewPopOver.isShowing())) {
progressViewPopOver.hide();
taskProgressSubscription.unsubscribe();
+ return;
}
TaskProgressView<Task<?>> taskProgressView = new TaskProgressView<>();
diff --git a/src/main/java/org/jabref/gui/util/UiTaskExecutor.java b/src/main/java/org/jabref/gui/util/UiTaskExecutor.java
index 15aeaf0105..43c0fad08e 100644
--- a/src/main/java/org/jabref/gui/util/UiTaskExecutor.java
+++ b/src/main/java/org/jabref/gui/util/UiTaskExecutor.java
@@ -145,7 +145,7 @@ public class UiTaskExecutor implements TaskExecutor {
public void shutdown() {
StateManager stateManager = Injector.instantiateModelOrService(StateManager.class);
if (stateManager != null) {
- stateManager.getRunningBackgroundTasks().forEach(Task::cancel);
+ stateManager.getBackgroundTasks().stream().filter(task -> !task.isDone()).forEach(Task::cancel);
}
executor.shutdownNow();
scheduledExecutor.shutdownNow();
(END)
- private final EasyBinding<Double> tasksProgress = EasyBind.reduce(backgroundTasks, tasks -> tasks.map(Pair::getValue).filter(Task::isRunning).mapToDouble(Task::getProgress).average().orElse(1));
+ private final ObservableList<Pair<BackgroundTask<?>, Task<?>>> backgroundTasksPairs = FXCollections.observableArrayList(task -> new Observable[] {task.getValue().progressProperty(), task.getValue().runningProperty()});
+ private final ObservableList<Task<?>> backgroundTasks = EasyBind.map(backgroundTasksPairs, Pair::getValue);
+ private final FilteredList<Task<?>> runningBackgroundTasks = new FilteredList<>(backgroundTasks, Task::isRunning);
+ private final BooleanBinding anyTaskRunning = Bindings.createBooleanBinding(() -> !runningBackgroundTasks.isEmpty(), runningBackgroundTasks);
+ private final EasyBinding<Boolean> anyTasksThatWillNotBeRecoveredRunning = EasyBind.reduce(backgroundTasksPairs, tasks -> tasks.anyMatch(task -> !task.getKey().willBeRecoveredAutomatically() && task.getValue().isRunning()));
+ private final EasyBinding<Double> tasksProgress = EasyBind.reduce(backgroundTasksPairs, tasks -> tasks.map(Pair::getValue).filter(Task::isRunning).mapToDouble(Task::getProgress).average().orElse(1));
private final ObservableMap<String, DialogWindowState> dialogWindowStates = FXCollections.observableHashMap();
private final ObservableList<SidePaneType> visibleSidePanes = FXCollections.observableArrayList();
private final ObjectProperty<LastAutomaticFieldEditorEdit> lastAutomaticFieldEditorEdit = new SimpleObjectProperty<>();
@@ -153,16 +157,19 @@ public class StateManager {
return focusOwner.get();
}
+ public ObservableList<Task<?>> getBackgroundTasks() {
+ return backgroundTasks;
+ }
+
public ObservableList<Task<?>> getRunningBackgroundTasks() {
- FilteredList<Pair<BackgroundTask<?>, Task<?>>> pairs = new FilteredList<>(backgroundTasks, task -> task.getValue().isRunning());
- return EasyBind.map(pairs, Pair::getValue);
+ return runningBackgroundTasks;
}
public void addBackgroundTask(BackgroundTask<?> backgroundTask, Task<?> task) {
- this.backgroundTasks.addFirst(new Pair<>(backgroundTask, task));
+ this.backgroundTasksPairs.addFirst(new Pair<>(backgroundTask, task));
}
- public EasyBinding<Boolean> getAnyTaskRunning() {
+ public BooleanBinding getAnyTaskRunning() {
return anyTaskRunning;
}
diff --git a/src/main/java/org/jabref/gui/frame/MainToolBar.java b/src/main/java/org/jabref/gui/frame/MainToolBar.java
index 2f61f953c6..03bbc72e3b 100644
--- a/src/main/java/org/jabref/gui/frame/MainToolBar.java
+++ b/src/main/java/org/jabref/gui/frame/MainToolBar.java
@@ -229,6 +229,7 @@ public class MainToolBar extends ToolBar {
if ((progressViewPopOver != null) && (progressViewPopOver.isShowing())) {
progressViewPopOver.hide();
taskProgressSubscription.unsubscribe();
+ return;
}
TaskProgressView<Task<?>> taskProgressView = new TaskProgressView<>();
diff --git a/src/main/java/org/jabref/gui/util/UiTaskExecutor.java b/src/main/java/org/jabref/gui/util/UiTaskExecutor.java
index 15aeaf0105..43c0fad08e 100644
--- a/src/main/java/org/jabref/gui/util/UiTaskExecutor.java
+++ b/src/main/java/org/jabref/gui/util/UiTaskExecutor.java
@@ -145,7 +145,7 @@ public class UiTaskExecutor implements TaskExecutor {
public void shutdown() {
StateManager stateManager = Injector.instantiateModelOrService(StateManager.class);
if (stateManager != null) {
- stateManager.getRunningBackgroundTasks().forEach(Task::cancel);
+ stateManager.getBackgroundTasks().stream().filter(task -> !task.isDone()).forEach(Task::cancel);
}
executor.shutdownNow();
scheduledExecutor.shutdownNow(); |
The build for this PR is no longer available. Please visit https://builds.jabref.org/main/ for the latest build. |
6 tasks
I'm confused now Should we use this PR now or th eother? |
Both. This PR hides completed tasks from the popup, while the other PR
controls when tasks should be shown to the user (i.e., added to the popup).
… Message ID: ***@***.***>
|
calixtus
approved these changes
Sep 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #11574 was reverted in #11818 due to an
IndexOutOfBoundsException
(see: #11574 (comment)).This PR reinstates #11574 with the exception issue fixed.
Closes: #11701
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)