package ie.dcu.apps.ist.actions; import ie.dcu.apps.ist.*; import ie.dcu.apps.ist.dialogs.SaveReminderDialog; import org.eclipse.jface.dialogs.MessageDialog; /** * Close current image annotation file * * @author Justin Preece */ public class CloseAction extends AppAction { public CloseAction(ActionManager m) { super(m); } @Override public void run() { // TODO: add a call to check the confirm close app preference // call Save Reminder dialog SaveReminderDialog dialog = new SaveReminderDialog(window.getShell(),window); SaveReminderDialog.ResultChoice result = dialog.open(); if (result != null) { // check return choice in result here and fire appropriate action: switch (result) { case SAVE: // save now and then close file // trigger Save dialog to save the file ActionManager actions = window.getActions(); if (actions != null) { SaveAction saveAction = actions.get(SaveAction.class); saveAction.runSaveAndClose(); } break; case NOSAVE: // do not save and then close file window.getView().resetView(); // clear current data and work status("Closed"); break; case CANCEL: // cancel the close status("Close cancelled."); break; } } } public static boolean confirmClose(AppWindow window) { boolean confirm = window.getPrefs().get( Boolean.class, AppPrefs.Keys.CONFIRM_CLOSE, true); if (confirm) { return MessageDialog.openConfirm( window.getShell(), "Confirm", "Are you sure you want to close this file?"); } return true; } }