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.
2020-09-23 17:03:32 +02:00
|
|
|
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
|
|
|
|
*/
|
2020-09-26 21:38:31 +02:00
|
|
|
public final class AlertHelper {
|
2020-09-23 17:03:32 +02:00
|
|
|
|
|
|
|
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.setHeight(225);
|
|
|
|
alert.setWidth(400);
|
|
|
|
alert.setHeaderText("");
|
|
|
|
if (Settings.getInstance().isAskForConfirmation()) alert.showAndWait().filter(ButtonType.OK::equals).ifPresent(bu -> action.run());
|
|
|
|
else action.run();
|
|
|
|
}
|
|
|
|
}
|