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