I have a JavaFX application that opens multiple windows. The data within a window is recorded to a database whenever the focus is lost from that window. When a user wants to close a window, an event handler should be fired that requests the tuple be deleted from the database. I only want this to occur when the user actively clicks the x in the top right of the window and not when the application is quit outright (e.g. if the program is quit from an OS start bar or equivalent) or halted in some other fashion.
the close event handler stub looks similar to the below:
foo.setOnCloseRequest(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent event)
{
try
{
barController.exec(Action.DELETE, item);
} catch (Exception e)
{
e.printStackTrace();
}
}
});
The trouble is, when I halt the program from the bar in Ubuntu (for example), this event is still being called for each window; and each time the tested event is WindowEvent.WINDOW_CLOSE_REQUEST
whether the user or the application closed the window.
Simply put: is there some kind of way to delineate "onUserCloseWindow" from "onCloseApplication"?