This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/client/src/main/java/envoy/client/helper/AlertHelper.java

34 lines
1021 B
Java

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. <strong>Should not be shown already</strong>
* @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();
}
}