package envoy.client.helper; import javafx.scene.control.*; import envoy.client.data.Settings; /** * Provides methods that are commonly used for alerts. * * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ public final class AlertHelper { private AlertHelper() {} /** * Asks for a confirmation dialog if {@link Settings#isAskForConfirmation()} returns * {@code true}. Immediately executes the action if no dialog was requested or the dialog was * exited with a confirmation. Does nothing if the dialog was closed without clicking on OK. * * @param alert the (customized) alert to show. Should not be shown already * @param action the action to perform in case of success * @since Envoy Client v0.2-beta */ public static void confirmAction(Alert alert, Runnable action) { alert.setHeaderText(""); if (Settings.getInstance().isAskForConfirmation()) alert.showAndWait().filter(ButtonType.OK::equals).ifPresent(bu -> action.run()); else action.run(); } }