Skip to main content
summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorChristoph Keimel2015-05-22 06:43:54 -0400
committerChristoph Keimel2015-05-22 06:44:10 -0400
commitccce84005ad05b713e3dc6484620ba9affaaf508 (patch)
tree2e87c9b525a5a33b47e2e39ffe164db80baa93c6 /demos
parent8493d985aefd241b4e6135489d18ee1f0e9f5e9c (diff)
downloadorg.eclipse.efxclipse-ccce84005ad05b713e3dc6484620ba9affaaf508.tar.gz
org.eclipse.efxclipse-ccce84005ad05b713e3dc6484620ba9affaaf508.tar.xz
org.eclipse.efxclipse-ccce84005ad05b713e3dc6484620ba9affaaf508.zip
Bug 467993 - [dialogs] Proposal for a TaskProgressDialog
Change-Id: I81631600b97b53c9096bcdee4ef02c0bb819562d Signed-off-by: Christoph Keimel <c.keimel@emsw.de>
Diffstat (limited to 'demos')
-rw-r--r--demos/org.eclipse.fx.ui.controls.sample/.classpath19
-rw-r--r--demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/dialogs/sample/TaskDialogDemo.java121
2 files changed, 131 insertions, 9 deletions
diff --git a/demos/org.eclipse.fx.ui.controls.sample/.classpath b/demos/org.eclipse.fx.ui.controls.sample/.classpath
index 348d252e9..bb25ae154 100644
--- a/demos/org.eclipse.fx.ui.controls.sample/.classpath
+++ b/demos/org.eclipse.fx.ui.controls.sample/.classpath
@@ -1,9 +1,10 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.fx.ui.controls"/>
- <classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
- <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.fx.core"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.fx.ui.controls"/>
+ <classpathentry kind="con" path="org.eclipse.fx.ide.jdt.core.JAVAFX_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.fx.core"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.fx.ui.dialogs"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/dialogs/sample/TaskDialogDemo.java b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/dialogs/sample/TaskDialogDemo.java
new file mode 100644
index 000000000..420dd4c55
--- /dev/null
+++ b/demos/org.eclipse.fx.ui.controls.sample/src/org/eclipse/fx/ui/dialogs/sample/TaskDialogDemo.java
@@ -0,0 +1,121 @@
+package org.eclipse.fx.ui.dialogs.sample;
+
+import java.util.Optional;
+
+import javafx.application.Application;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.IntegerBinding;
+import javafx.beans.property.IntegerProperty;
+import javafx.beans.property.SimpleIntegerProperty;
+import javafx.concurrent.Task;
+import javafx.geometry.Insets;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.scene.control.Alert;
+import javafx.scene.control.Alert.AlertType;
+import javafx.scene.control.Button;
+import javafx.scene.control.ButtonType;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.BorderPane;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+
+import org.eclipse.fx.ui.dialogs.TaskProgressDialog;
+
+public class TaskDialogDemo extends Application {
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+
+ @Override
+ public void start(Stage primaryStage) {
+ primaryStage.setScene(new Scene(createContent(primaryStage), 420, 200));
+ primaryStage.show();
+ }
+
+ private Parent createContent(Stage stage) {
+ CheckBox cbCancelable = new CheckBox("Cancelable?");
+ cbCancelable.setSelected(true);
+
+ TextField stepInput = new TextField();
+ stepInput.setPromptText("Enter a Number 1 - 100 to throw an Exception on that Step");
+ IntegerBinding stepBinding = Bindings.createIntegerBinding(() -> {
+ try {
+ return Integer.parseInt(stepInput.getText());
+ } catch (Exception e) {
+ return 0;
+ }
+ }, stepInput.textProperty());
+
+ Button openDlgBtn = new Button("Start long running task");
+ openDlgBtn.setMaxWidth(Double.MAX_VALUE);
+ openDlgBtn.setOnAction((event) -> {
+ openDialog(stage, cbCancelable.isSelected(), stepBinding.get());
+ });
+
+ VBox box = new VBox(6);
+ box.setPadding(new Insets(24));
+ box.getChildren().addAll(openDlgBtn, cbCancelable, stepInput);
+ return new BorderPane(box);
+ }
+
+ private void openDialog(Stage stage, boolean cancelable, int exceptionStep) {
+ System.out.println("Opening Dialog ...");
+ LongRunningTask task = new LongRunningTask();
+ task.setExceptionStep(exceptionStep);
+
+ TaskProgressDialog<Boolean> dialog = new TaskProgressDialog<Boolean>(stage, task);
+ dialog.setCancelable(cancelable);
+ dialog.setFailedHandler(exception -> {
+ exception.printStackTrace();
+ new Alert(AlertType.ERROR, exception.getMessage(), ButtonType.OK).showAndWait();
+ return false;
+ });
+ Optional<Boolean> result = dialog.showAndWait();
+ System.out.println("Result: " + result);
+ }
+}
+
+class LongRunningTask extends Task<Boolean> {
+ private IntegerProperty exceptionStep = new SimpleIntegerProperty(0);
+
+ @Override
+ protected Boolean call() throws Exception {
+ System.out.println("Starting long running task ...");
+ updateTitle("Long Runnning Task");
+ for (int i = 0; i < 100; i++) {
+ if (isCancelled())
+ return false;
+ if (i > 20) {
+ updateTitle("Long Runnning Task - Rest");
+ updateMessage("Processing Step Nr. "
+ + i
+ + " Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.");
+ } else {
+ updateTitle("Long Runnning Task - Step Nr. " + i);
+ updateMessage("Processing Step Nr. " + i);
+ }
+ if (exceptionStep.getValue() > 0 && i == exceptionStep.getValue()) {
+ throw new Exception("Exception on Step: " + i);
+ }
+ Thread.sleep(100);
+ updateProgress(i + 1, 100);
+ }
+ System.out.println("Finished long running task.");
+ return true;
+ }
+
+ public final IntegerProperty exceptionStepProperty() {
+ return this.exceptionStep;
+ }
+
+ public final int getExceptionStep() {
+ return this.exceptionStepProperty().get();
+ }
+
+ public final void setExceptionStep(final int exceptionStep) {
+ this.exceptionStepProperty().set(exceptionStep);
+ }
+}

Back to the top