From 214230bb5453b7e6c30373c83d434d7e6327f7cb Mon Sep 17 00:00:00 2001
From: Jan Kozusznik <jan@kozusznik.cz>
Date: Tue, 23 Jan 2018 11:42:58 +0100
Subject: [PATCH] support for cancel

---
 .../java/cz/it4i/fiji/haas/ui/ProgressDialog.java   | 13 ++++++++++---
 .../commands/ManageSPIMBenchmark.java               |  2 +-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java
index 6b7b453d..93ad84c8 100644
--- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java
+++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/ui/ProgressDialog.java
@@ -49,10 +49,14 @@ public class ProgressDialog extends JDialog implements Progress {
 	public ProgressDialog(final Window owner) {
 		this(owner, null);
 	}
+	
+	public ProgressDialog(Window owner, String title) {
+		this(owner, title, null);
+	}
 
-	public ProgressDialog(final Window owner, final String title) {
+	public ProgressDialog(final Window owner, final String title, Runnable cancelableAction) {
 		super(owner, title);
-
+		boolean canCancel = cancelableAction != null;
 		final Container root = getContentPane();
 		root.setLayout(new BoxLayout(root, BoxLayout.Y_AXIS));
 		progress = new JProgressBar();
@@ -77,9 +81,12 @@ public class ProgressDialog extends JDialog implements Progress {
 			public void actionPerformed(final ActionEvent e) {
 				canceled = true;
 				ProgressDialog.this.dispose();
+				cancelableAction.run();
 			}
 		});
-		// buttons.add(cancel);
+		if(canCancel) {
+			buttons.add(cancel);
+		}
 		buttons.setMaximumSize(buttons.getMinimumSize());
 		root.add(buttons);
 
diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java
index 7dd54e7f..9f4ee840 100644
--- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java
+++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java
@@ -86,7 +86,7 @@ public class ManageSPIMBenchmark implements Command {
 		final ImageJ ij = new ImageJ();
 		ij.launch(args);
 
-		ij.command().run(ManageSPIMBenchmark.class, true);
+		//ij.command().run(ManageSPIMBenchmark.class, true);
 	}
 
 }
-- 
GitLab