2525import com .github .introfog .gitwave .model .dto .ParameterDto ;
2626
2727import java .io .File ;
28+ import javafx .concurrent .Task ;
2829import javafx .fxml .FXML ;
2930import javafx .scene .control .Button ;
3031import javafx .scene .control .ButtonType ;
@@ -121,14 +122,8 @@ protected void runCommand() {
121122 }
122123 AppConfig .getInstance ().setLastRunFolder (directoryToRunIn .getAbsolutePath ());
123124
124- new Thread (() -> {
125- // TODO #8 rewrite using javafx.concurrent.Task, because it is a native JavaFx way to do smth in background
126- switchRunButton (true );
127- final File scriptFile = CommandExecutor .searchGitRepositoriesAndCreateScriptFile (directoryToRunIn ,
128- commandTabController .getCommandWithParameters ());
129- switchRunButton (false );
130- CommandExecutor .executeScriptFileWithCommand (scriptFile );
131- }).start ();
125+ Task <Void > runCommandTask = createRunCommandTask (directoryToRunIn );
126+ new Thread (runCommandTask ).start ();
132127 }
133128 }
134129
@@ -156,4 +151,17 @@ private void switchRunButton(boolean inProgress) {
156151 run .setDisable (inProgress );
157152 runProgress .setVisible (inProgress );
158153 }
154+
155+ private Task <Void > createRunCommandTask (File directoryToRunIn ) {
156+ return new Task <Void >() {
157+ @ Override protected Void call () {
158+ switchRunButton (true );
159+ final File scriptFile = CommandExecutor .searchGitRepositoriesAndCreateScriptFile (directoryToRunIn ,
160+ commandTabController .getCommandWithParameters ());
161+ switchRunButton (false );
162+ CommandExecutor .executeScriptFileWithCommand (scriptFile );
163+ return null ;
164+ }
165+ };
166+ }
159167}
0 commit comments