1 package org.simantics.workbench.internal;
\r
3 import java.util.concurrent.atomic.AtomicBoolean;
\r
5 import org.eclipse.jface.dialogs.MessageDialog;
\r
6 import org.simantics.db.Session;
\r
7 import org.simantics.ui.SimanticsUI;
\r
8 import org.simantics.utils.ui.ErrorLogger;
\r
9 import org.simantics.utils.ui.dialogs.SafeMessageDialog;
\r
12 * @author Tuukka Lehtonen
\r
14 final class ApplicationUtil {
\r
17 * Used to make sure that the user has a choice to save the changes into the
\r
18 * active database before closing.
\r
20 public static boolean allowShutdown(AtomicBoolean saveAtExit) {
\r
22 if (hasUnsavedChanges()) {
\r
23 String[] buttons = { "&Save", "&Don't save", "&Cancel" };
\r
24 int result = SafeMessageDialog.doMessageDialog("Save Resources", null, "Save changes before closing ?",
\r
25 MessageDialog.QUESTION, buttons, 2);
\r
29 saveAtExit.set(true);
\r
32 saveAtExit.set(false);
\r
41 // If any errors occur during this check, just log them, but allow
\r
42 // for the program to be closed and make sure nothing is saved,
\r
43 // since it would probably be corrupt.
\r
44 } catch (RuntimeException e) {
\r
45 ErrorLogger.defaultLogError(
\r
46 "RuntimeException occured while querying database session for unsaved changes.", e);
\r
47 saveAtExit.set(false);
\r
49 ErrorLogger.defaultLogError("Error occured while querying database session for unsaved changes.", e);
\r
50 saveAtExit.set(false);
\r
55 public static boolean hasUnsavedChanges() {
\r
56 Session session = SimanticsUI.peekSession();
\r
57 if (session == null)
\r
60 // hasChangesToSave is deprecated
\r
61 // LifecycleSupport lfs = session.getService(LifecycleSupport.class);
\r
63 // return lfs.hasChangesToSave();
\r
64 // } catch (DatabaseException e) {
\r
65 // ErrorLogger.defaultLogError(
\r
66 // "Problems encountered while checking for unsaved changes, see exception for details.", e);
\r