Skip to content

Commit

Permalink
Changed callback to method in BackgroundTask
Browse files Browse the repository at this point in the history
Addresses #6443 (comment)
  • Loading branch information
btut committed May 11, 2020
1 parent fcb1d0c commit 396411a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
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 @@ -296,7 +296,7 @@ public <V> Optional<ButtonType> showBackgroundProgressDialogAndWait(String title
TaskProgressView taskProgressView = new TaskProgressView();
EasyBind.listBind(taskProgressView.getTasks(), stateManager.getBackgroundTasks());
taskProgressView.setRetainTasks(false);
taskProgressView.setGraphicFactory(BackgroundTask.iconCallback);
taskProgressView.setGraphicFactory(BackgroundTask::getIcon);

Label message = new Label(content);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ hide it and clip it to a square of (width x width) each time width is updated.
TaskProgressView taskProgressView = new TaskProgressView();
EasyBind.listBind(taskProgressView.getTasks(), stateManager.getBackgroundTasks());
taskProgressView.setRetainTasks(true);
taskProgressView.setGraphicFactory(BackgroundTask.iconCallback);
taskProgressView.setGraphicFactory(BackgroundTask::getIcon);

PopOver progressViewPopOver = new PopOver(taskProgressView);
progressViewPopOver.setTitle(Localization.lang("Background Tasks"));
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/org/jabref/gui/util/BackgroundTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import javafx.beans.property.StringProperty;
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.util.Callback;

import org.jabref.gui.icon.IconTheme;
import org.jabref.logic.l10n.Localization;
Expand All @@ -38,14 +37,6 @@ public abstract class BackgroundTask<V> {
Localization.lang("Downloading"), IconTheme.JabRefIcons.DOWNLOAD.getGraphicNode()
);

public static Callback<Task<?>, Node> iconCallback = task -> {
if (BackgroundTask.iconMap.containsKey(task.getTitle())) {
return BackgroundTask.iconMap.get(task.getTitle());
} else {
return null;
}
};

private Runnable onRunning;
private Consumer<V> onSuccess;
private Consumer<Exception> onException;
Expand Down Expand Up @@ -266,6 +257,13 @@ public BackgroundTask<V> withInitialMessage(String message) {
return this;
}

public static Node getIcon(Object task) {
if (task instanceof Task) {
return BackgroundTask.iconMap.getOrDefault(((Task<?>) task).getTitle(), null);
}
return null;
}

static class BackgroundProgress {

private final double workDone;
Expand Down

0 comments on commit 396411a

Please sign in to comment.