Skip to content
Permalink
Browse files

Merge pull request #1127 from nicolabeghin/master

TaskProgressView - new flag to retain tasks when succeeded, cancelled or failed
  • Loading branch information...
abhinayagarwal committed Jun 6, 2019
2 parents 610f7ad + ee04936 commit 821bbad97a8359908d986433597bf949c59879ee
Showing with 41 additions and 8 deletions.
  1. +41 −8 controlsfx/src/main/java/org/controlsfx/control/TaskProgressView.java
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2014, 2015 ControlsFX
* Copyright (c) 2014, 2019 ControlsFX
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,7 +27,9 @@
package org.controlsfx.control;

import impl.org.controlsfx.skin.TaskProgressViewSkin;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
@@ -62,20 +64,24 @@
*/
public class TaskProgressView<T extends Task<?>> extends ControlsFXControl {

private final BooleanProperty retainTasks = new SimpleBooleanProperty(this, "retainTasks", false);

/**
* Constructs a new task progress view.
*/
public TaskProgressView() {
getStyleClass().add("task-progress-view");

EventHandler<WorkerStateEvent> taskHandler = evt -> {
if (evt.getEventType().equals(
WorkerStateEvent.WORKER_STATE_SUCCEEDED)
|| evt.getEventType().equals(
WorkerStateEvent.WORKER_STATE_CANCELLED)
|| evt.getEventType().equals(
WorkerStateEvent.WORKER_STATE_FAILED)) {
getTasks().remove(evt.getSource());
if (!isRetainTasks()) {
if (evt.getEventType().equals(
WorkerStateEvent.WORKER_STATE_SUCCEEDED)
|| evt.getEventType().equals(
WorkerStateEvent.WORKER_STATE_CANCELLED)
|| evt.getEventType().equals(
WorkerStateEvent.WORKER_STATE_FAILED)) {
getTasks().remove(evt.getSource());
}
}
};

@@ -155,4 +161,31 @@ public void onChanged(Change<? extends Task<?>> c) {
public final void setGraphicFactory(Callback<T, Node> factory) {
graphicFactoryProperty().set(factory);
}

/**
* Checks if tasks will not be removed when succeeded, cancelled or failed.
*
* @return boolean determines if tasks will be retained
*/
public final boolean isRetainTasks() {
return retainTasks.get();
}

/**
* Do not remove tasks when succeeded, cancelled or failed.
*
* @return BooleanProperty the retainTasks property
*/
public final BooleanProperty retainTasksProperty() {
return retainTasks;
}

/**
* Do not remove tasks when succeeded, cancelled or failed.
*
* @param retainTasks determines if tasks will be retained
*/
public final void setRetainTasks(boolean retainTasks) {
this.retainTasks.set(retainTasks);
}
}

0 comments on commit 821bbad

Please sign in to comment.
You can’t perform that action at this time.