Search in sources :

Example 1 with UnsavedChangesDialog

use of org.apache.cayenne.modeler.dialog.UnsavedChangesDialog in project cayenne by apache.

the class ProjectAction method checkSaveOnClose.

/**
 * Returns false if cancel closing the window, true otherwise.
 */
public boolean checkSaveOnClose() {
    ProjectController projectController = getProjectController();
    if (projectController != null && projectController.isDirty()) {
        UnsavedChangesDialog dialog = new UnsavedChangesDialog(Application.getFrame());
        dialog.show();
        if (dialog.shouldCancel()) {
            // discard changes and DO NOT close
            return false;
        } else if (dialog.shouldSave()) {
            // save changes and close
            ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "SaveAll");
            Application.getInstance().getActionManager().getAction(SaveAction.class).actionPerformed(e);
            if (projectController.isDirty()) {
                // save was canceled... do not close
                return false;
            }
        }
    }
    return true;
}
Also used : UnsavedChangesDialog(org.apache.cayenne.modeler.dialog.UnsavedChangesDialog) ActionEvent(java.awt.event.ActionEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 UnsavedChangesDialog (org.apache.cayenne.modeler.dialog.UnsavedChangesDialog)1