Search in sources :

Example 1 with NULL_RESULT

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()));
}
Also used : Platform(javafx.application.Platform) FileChooser(javafx.stage.FileChooser) Setter(lombok.Setter) SwingCore(eu.ggnet.saft.core.ui.SwingCore) Accessors(lombok.experimental.Accessors) NULL_RESULT(eu.ggnet.saft.core.ui.builder.UiWorkflowBreak.Type.NULL_RESULT) CompletableFuture(java.util.concurrent.CompletableFuture) File(java.io.File) UiCore(eu.ggnet.saft.UiCore) Platform(javafx.application.Platform) FileChooser(javafx.stage.FileChooser) File(java.io.File)

Aggregations

UiCore (eu.ggnet.saft.UiCore)1 SwingCore (eu.ggnet.saft.core.ui.SwingCore)1 NULL_RESULT (eu.ggnet.saft.core.ui.builder.UiWorkflowBreak.Type.NULL_RESULT)1 File (java.io.File)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Platform (javafx.application.Platform)1 FileChooser (javafx.stage.FileChooser)1 Setter (lombok.Setter)1 Accessors (lombok.experimental.Accessors)1