Skip to content

Commit

Permalink
No more shown finished background tasks (#11574)
Browse files Browse the repository at this point in the history
* Reformat code comments

* Finished tasks have 100% completeness

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>

* Remove finished tasks

* Restructure if/then to avoid unnecessary creation of TaskProgressView

* Remove subscription on hide

* Try to show running tasks only

* At shutdown at end, also do not show tasks

* Add CHANGELOG.md entry

---------

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
  • Loading branch information
koppor and calixtus committed Aug 4, 2024
1 parent 0068406 commit 2c8fc01
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- The Pubmed/Medline Plain importer now imports the PMID field as well [#11488](https://github.com/JabRef/jabref/issues/11488)
- The 'Check for updates' menu bar button is now always enabled. [#11485](https://github.com/JabRef/jabref/pull/11485)
- JabRef respects the [configuration for storing files relative to the .bib file](https://docs.jabref.org/finding-sorting-and-cleaning-entries/filelinks#directories-for-files) in more cases. [#11492](https://github.com/JabRef/jabref/pull/11492)
- JabRef does not show finished background tasks in the status bar popup. [#11574](https://github.com/JabRef/jabref/pull/11574)
- We enhanced the indexing speed. [#11502](https://github.com/JabRef/jabref/pull/11502)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public <V> void showProgressDialogAndWait(String title, String content, Task<V>
@Override
public <V> Optional<ButtonType> showBackgroundProgressDialogAndWait(String title, String content, StateManager stateManager) {
TaskProgressView<Task<?>> taskProgressView = new TaskProgressView<>();
EasyBind.bindContent(taskProgressView.getTasks(), stateManager.getBackgroundTasks());
EasyBind.bindContent(taskProgressView.getTasks(), stateManager.getRunningBackgroundTasks());
taskProgressView.setRetainTasks(false);
taskProgressView.setGraphicFactory(BackgroundTask::getIcon);

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.ObservableMap;
import javafx.collections.transformation.FilteredList;
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.util.Pair;
Expand Down Expand Up @@ -185,8 +186,9 @@ public Optional<Node> getFocusOwner() {
return focusOwner.get();
}

public ObservableList<Task<?>> getBackgroundTasks() {
return EasyBind.map(backgroundTasks, Pair::getValue);
public ObservableList<Task<?>> getRunningBackgroundTasks() {
FilteredList<Pair<BackgroundTask<?>, Task<?>>> pairs = new FilteredList<>(backgroundTasks, task -> task.getValue().isRunning());
return EasyBind.map(pairs, Pair::getValue);
}

public void addBackgroundTask(BackgroundTask<?> backgroundTask, Task<?> task) {
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/org/jabref/gui/frame/MainToolBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.jabref.preferences.PreferencesService;

import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.Subscription;
import org.controlsfx.control.PopOver;
import org.controlsfx.control.TaskProgressView;

Expand All @@ -63,6 +64,7 @@ public class MainToolBar extends ToolBar {

private PopOver entryFromIdPopOver;
private PopOver progressViewPopOver;
private Subscription taskProgressSubscription;

public MainToolBar(LibraryTabContainer tabContainer,
PushToApplicationCommand pushToApplicationCommand,
Expand Down Expand Up @@ -201,15 +203,11 @@ Group createTaskIndicator() {
}
});

/*
The label of the indicator cannot be removed with styling. Therefore,
hide it and clip it to a square of (width x width) each time width is updated.
*/
// The label of the indicator cannot be removed with styling. Therefore,
// hide it and clip it to a square of (width x width) each time width is updated.
indicator.widthProperty().addListener((observable, oldValue, newValue) -> {
/*
The indeterminate spinner is wider than the determinate spinner.
We must make sure they are the same width for the clipping to result in a square of the same size always.
*/
// The indeterminate spinner is wider than the determinate spinner.
// We must make sure they are the same width for the clipping to result in a square of the same size always.
if (!indicator.isIndeterminate()) {
indicator.setPrefWidth(newValue.doubleValue());
}
Expand All @@ -220,23 +218,24 @@ hide it and clip it to a square of (width x width) each time width is updated.
});

indicator.setOnMouseClicked(event -> {
if ((progressViewPopOver != null) && (progressViewPopOver.isShowing())) {
progressViewPopOver.hide();
taskProgressSubscription.unsubscribe();
}

TaskProgressView<Task<?>> taskProgressView = new TaskProgressView<>();
EasyBind.bindContent(taskProgressView.getTasks(), stateManager.getBackgroundTasks());
taskProgressView.setRetainTasks(true);
taskProgressSubscription = EasyBind.bindContent(taskProgressView.getTasks(), stateManager.getRunningBackgroundTasks());
taskProgressView.setRetainTasks(false);
taskProgressView.setGraphicFactory(BackgroundTask::getIcon);

if (progressViewPopOver == null) {
progressViewPopOver = new PopOver(taskProgressView);
progressViewPopOver.setTitle(Localization.lang("Background Tasks"));
progressViewPopOver.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP);
progressViewPopOver.setContentNode(taskProgressView);
progressViewPopOver.show(indicator);
} else if (progressViewPopOver.isShowing()) {
progressViewPopOver.hide();
} else {
progressViewPopOver.setContentNode(taskProgressView);
progressViewPopOver.show(indicator);
}

progressViewPopOver.setContentNode(taskProgressView);
progressViewPopOver.show(indicator);
});

return new Group(indicator);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/org/jabref/gui/util/UiTaskExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public <V> Future<?> schedule(BackgroundTask<V> task, long delay, TimeUnit unit)
public void shutdown() {
StateManager stateManager = Injector.instantiateModelOrService(StateManager.class);
if (stateManager != null) {
stateManager.getBackgroundTasks().stream().filter(task -> !task.isDone()).forEach(Task::cancel);
stateManager.getRunningBackgroundTasks().stream().forEach(Task::cancel);
}
executor.shutdownNow();
scheduledExecutor.shutdownNow();
Expand Down Expand Up @@ -175,9 +175,14 @@ public V call() throws Exception {
javaTask.setOnRunning(event -> onRunning.run());
}
Consumer<V> onSuccess = task.getOnSuccess();
if (onSuccess != null) {
javaTask.setOnSucceeded(event -> onSuccess.accept(javaTask.getValue()));
}
javaTask.setOnSucceeded(event -> {
// Set to 100% completed on completion
task.updateProgress(1, 1);

if (onSuccess != null) {
onSuccess.accept(javaTask.getValue());
}
});
Consumer<Exception> onException = task.getOnException();
if (onException != null) {
javaTask.setOnFailed(event -> onException.accept(convertToException(javaTask.getException())));
Expand Down

0 comments on commit 2c8fc01

Please sign in to comment.