use of eu.ggnet.saft.core.ui.builder.UiWorkflowBreak.Type.NULL_RESULT in project dwoss by gg-net.
the class FileChooserBuilder method open.
/**
* Opens a file chooser and returns the selected file or empty.
*
* @return the selected file or empty.
*/
// TODO: This is the only time we us a javafx component in all modes. It should be considered, that in the swing mode, the JFileChoser should be used.
public Result<File> open() {
SwingCore.ensurePlatformIsRunning();
return new Result<>(CompletableFuture.supplyAsync(() -> {
FileChooser fileChooser = new FileChooser();
if (title == null)
fileChooser.setTitle("Open File");
else
fileChooser.setTitle(title);
File result = fileChooser.showOpenDialog(null);
if (result == null)
throw new UiWorkflowBreak(NULL_RESULT);
return result;
}, Platform::runLater).thenApplyAsync(r -> r, // the last Apply is for the thread change only
UiCore.getExecutor()));
}
Aggregations