Using tasks in numass viewer
This commit is contained in:
parent
cbfbe27958
commit
37477e5f2c
@ -28,8 +28,6 @@ import java.util.concurrent.ExecutionException;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.value.ChangeListener;
|
|
||||||
import javafx.beans.value.ObservableValue;
|
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
@ -54,6 +52,7 @@ import javafx.stage.DirectoryChooser;
|
|||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import javafx.util.Pair;
|
import javafx.util.Pair;
|
||||||
import org.controlsfx.control.StatusBar;
|
import org.controlsfx.control.StatusBar;
|
||||||
|
import org.controlsfx.control.TaskProgressView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FXML Controller class
|
* FXML Controller class
|
||||||
@ -103,7 +102,12 @@ public class MainViewerController implements Initializable, FXTaskManager {
|
|||||||
private Button loadRemoteButton;
|
private Button loadRemoteButton;
|
||||||
@FXML
|
@FXML
|
||||||
private Label storagePathLabel;
|
private Label storagePathLabel;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane taskPane;
|
||||||
|
|
||||||
|
private TaskProgressView progressView;
|
||||||
|
|
||||||
|
// private Popup progressPopup;
|
||||||
/**
|
/**
|
||||||
* Initializes the controller class.
|
* Initializes the controller class.
|
||||||
*
|
*
|
||||||
@ -123,6 +127,9 @@ public class MainViewerController implements Initializable, FXTaskManager {
|
|||||||
consoleButton.setSelected(false);
|
consoleButton.setSelected(false);
|
||||||
loadRemoteButton.setDisable(true);
|
loadRemoteButton.setDisable(true);
|
||||||
mspController.setCallback(this);
|
mspController.setCallback(this);
|
||||||
|
|
||||||
|
progressView = new TaskProgressView();
|
||||||
|
taskPane.getChildren().add(progressView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -152,7 +159,7 @@ public class MainViewerController implements Initializable, FXTaskManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
updateTitle("Load storage ("+uri+")");
|
updateTitle("Load storage (" + uri + ")");
|
||||||
updateProgress(-1, 1);
|
updateProgress(-1, 1);
|
||||||
updateMessage("Building numass storage tree...");
|
updateMessage("Building numass storage tree...");
|
||||||
try {
|
try {
|
||||||
@ -172,28 +179,7 @@ public class MainViewerController implements Initializable, FXTaskManager {
|
|||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void postTask(Task task) {
|
public void postTask(Task task) {
|
||||||
task.setOnRunning((e) -> {
|
Platform.runLater(() -> progressView.getTasks().add(task));
|
||||||
statusBar.setText(task.getTitle() + ": " + task.getMessage());
|
|
||||||
statusBar.setProgress(task.getProgress());
|
|
||||||
});
|
|
||||||
|
|
||||||
task.messageProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
|
|
||||||
statusBar.setText(task.getTitle() + ": " +newValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
task.progressProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
|
|
||||||
statusBar.setProgress(newValue.doubleValue());
|
|
||||||
});
|
|
||||||
|
|
||||||
task.setOnSucceeded((e) -> {
|
|
||||||
statusBar.setText(task.getTitle() + ": Complete");
|
|
||||||
statusBar.setProgress(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
task.setOnFailed((e) -> {
|
|
||||||
statusBar.setText(task.getTitle() + ": Failed");
|
|
||||||
statusBar.setProgress(0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRootStorage(NumassStorage root) {
|
public void setRootStorage(NumassStorage root) {
|
||||||
@ -223,7 +209,7 @@ public class MainViewerController implements Initializable, FXTaskManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
updateTitle("Fill data to UI ("+root.getName()+")");
|
updateTitle("Fill data to UI (" + root.getName() + ")");
|
||||||
this.updateProgress(-1, 1);
|
this.updateProgress(-1, 1);
|
||||||
this.updateMessage("Loading numass storage tree...");
|
this.updateMessage("Loading numass storage tree...");
|
||||||
|
|
||||||
|
@ -72,7 +72,16 @@ limitations under the License.
|
|||||||
</Tab>
|
</Tab>
|
||||||
</tabs>
|
</tabs>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
<TextArea fx:id="consoleArea" editable="false" minHeight="0.0" wrapText="true" />
|
<SplitPane dividerPositions="0.0">
|
||||||
|
<items>
|
||||||
|
<ScrollPane minWidth="300.0" prefWidth="300.0">
|
||||||
|
<content>
|
||||||
|
<AnchorPane fx:id="taskPane" minWidth="300.0" prefWidth="300.0" />
|
||||||
|
</content>
|
||||||
|
</ScrollPane>
|
||||||
|
<TextArea fx:id="consoleArea" editable="false" minHeight="0.0" wrapText="true" />
|
||||||
|
</items>
|
||||||
|
</SplitPane>
|
||||||
</items>
|
</items>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
</center>
|
</center>
|
||||||
|
Loading…
Reference in New Issue
Block a user