in src/main/java/org/apache/cayenne/modeler/layout/MainWindowLayout.java [90:124]
public MainWindowLayout() throws IOException
{
super(new Stage(), "/layouts/MainWindowLayout.fxml");
setMinimumWindowSize(900, 700);
getStage().setOnCloseRequest(event ->
{
LOGGER.debug("Window is closing!");
// ideas for checking if window should save before closing or cancel, etc:
// event.consume(); <- Prevents window from closing
// http://stackoverflow.com/questions/31540500/alert-box-for-when-user-attempts-to-close-application-using-setoncloserequest-in
// http://stackoverflow.com/questions/23160573/javafx-stage-setoncloserequest-without-function
if (cayenneProject.isDirty())
{
final Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Close Window");
alert.setHeaderText("Unsaved Changes");
alert.setContentText("Are you sure you want to close this window and lose your changes?");
final Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK)
{
// ... user chose OK
}
else
{
// ... user chose CANCEL or closed the dialog
event.consume();
}
}
});
}