8
8
import edu .wpi .grip .core .events .ProjectSettingsChangedEvent ;
9
9
import edu .wpi .grip .core .events .TimerEvent ;
10
10
import edu .wpi .grip .core .events .UnexpectedThrowableEvent ;
11
+ import edu .wpi .grip .core .events .WarningEvent ;
11
12
import edu .wpi .grip .core .serialization .Project ;
12
13
import edu .wpi .grip .core .settings .AppSettings ;
13
14
import edu .wpi .grip .core .settings .ProjectSettings ;
31
32
import java .util .logging .Logger ;
32
33
33
34
import javafx .application .Platform ;
34
- import javafx .event .ActionEvent ;
35
35
import javafx .fxml .FXML ;
36
36
import javafx .scene .Parent ;
37
37
import javafx .scene .Scene ;
@@ -275,9 +275,9 @@ protected void quit() {
275
275
/**
276
276
* Controls the export button in the main menu. Opens a filechooser with language selection.
277
277
* The user can select the language to export to, save location and file name.
278
- * @param actionEvent Unused event passed by the controller.
279
278
*/
280
- public void generate (ActionEvent actionEvent ) {
279
+ @ FXML
280
+ public void generate () {
281
281
final FileChooser fileChooser = new FileChooser ();
282
282
fileChooser .setTitle ("Export to" );
283
283
fileChooser .getExtensionFilters ().add (new ExtensionFilter (Language .JAVA .name , "*.java" ));
@@ -290,13 +290,15 @@ public void generate(ActionEvent actionEvent) {
290
290
}
291
291
Language lang = Language .get (fileChooser .getSelectedExtensionFilter ().getDescription ());
292
292
Exporter exporter = new Exporter (pipeline .getSteps (), lang , file );
293
- final Set <String > nonExportableSteps = exporter .getNonExportableSteps ();
293
+ final Set <String > nonExportableSteps = exporter .getNonExportableStepNames ();
294
294
if (!nonExportableSteps .isEmpty ()) {
295
- StringBuilder b = new StringBuilder ("The following steps cannot be exported:\n " );
296
- nonExportableSteps .forEach (n -> b .append (" " ).append (n ).append ('\n' ));
297
- Alert alert = new Alert (Alert .AlertType .WARNING );
298
- alert .setContentText (b .toString ());
299
- alert .showAndWait ();
295
+ StringBuilder b = new StringBuilder (
296
+ "The following steps do not support code generation:\n \n "
297
+ );
298
+ nonExportableSteps .stream ()
299
+ .sorted ()
300
+ .forEach (n -> b .append (" - " ).append (n ).append ("\n " ));
301
+ eventBus .post (new WarningEvent ("Cannot generate code" , b .toString ()));
300
302
return ;
301
303
}
302
304
Thread exportRunner = new Thread (exporter );
@@ -325,7 +327,20 @@ protected void deploy() {
325
327
}
326
328
327
329
@ Subscribe
328
- @ SuppressWarnings ( {"PMD.UnusedPrivateMethod" , "PMD.UnusedFormalParameter" })
330
+ public void onWarningEvent (WarningEvent e ) {
331
+ if (Platform .isFxApplicationThread ()) {
332
+ showWarningAlert (e );
333
+ } else {
334
+ Platform .runLater (() -> showWarningAlert (e ));
335
+ }
336
+ }
337
+
338
+ private void showWarningAlert (WarningEvent e ) {
339
+ Alert alert = new WarningAlert (e .getHeader (), e .getBody (), root .getScene ().getWindow ());
340
+ alert .showAndWait ();
341
+ }
342
+
343
+ @ SuppressWarnings ({"PMD.UnusedPrivateMethod" , "PMD.UnusedFormalParameter" })
329
344
private void runStopped (TimerEvent event ) {
330
345
if (event .getTarget () instanceof PipelineRunner ) {
331
346
Platform .runLater (() -> updateElapsedTimeLabel (event .getElapsedTime ()));
0 commit comments