From c2b59aab0b05490fd43749ed109c6a9909bf1eb2 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 5 Jun 2018 21:46:01 +0200 Subject: [PATCH] WIP: Attempt to enable kill button for batch --- .../scijava/ui/swing/script/TextEditor.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/scijava/ui/swing/script/TextEditor.java b/src/main/java/org/scijava/ui/swing/script/TextEditor.java index c2bcf1d1..3db5184e 100644 --- a/src/main/java/org/scijava/ui/swing/script/TextEditor.java +++ b/src/main/java/org/scijava/ui/swing/script/TextEditor.java @@ -1925,12 +1925,25 @@ public void runText(final boolean selectionOnly) { * Run current script with the batch processor */ public void runBatch() { - // get script from current tab - String script = getTab().getEditorPane().getText(); - ScriptInfo scriptInfo = new ScriptInfo(context, "dummy." - + getCurrentLanguage().getExtensions().get(0), - new StringReader(script)); - batchService.run(scriptInfo); + final TextEditorTab tab = getTab(); + tab.prepare(); + final String script = getTab().getEditorPane().getText(); + tab.setExecutor(new Executer(null, null) { + + @Override + public void execute() { + // get script from current tab + ScriptInfo scriptInfo = new ScriptInfo(context, "batch." + + getCurrentLanguage().getExtensions().get(0), + new StringReader(script)); + try { + batchService.run(scriptInfo); + } + catch (final Throwable e) { + handleException(e); + } + } + }); } /** Invoke in the context of the event dispatch thread. */ @@ -2024,7 +2037,7 @@ public void runScript() { final JTextAreaWriter errors = new JTextAreaWriter(errorScreen, log); final File file = getEditorPane().getFile(); - new TextEditor.Executer(output, errors) { + new Executer(output, errors) { @Override public void execute() {