X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.workbench%2Fsrc%2Forg%2Fsimantics%2Fworkbench%2Finternal%2FApplicationUtil.java;fp=bundles%2Forg.simantics.workbench%2Fsrc%2Forg%2Fsimantics%2Fworkbench%2Finternal%2FApplicationUtil.java;h=372051cf353ae068b2a3e59ed144cb7fc75b7e7d;hp=ae0746ba17b1f9c39a5350a006cefa7ee0a8f14d;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/ApplicationUtil.java b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/ApplicationUtil.java index ae0746ba1..372051cf3 100644 --- a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/ApplicationUtil.java +++ b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/ApplicationUtil.java @@ -1,71 +1,71 @@ -package org.simantics.workbench.internal; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.simantics.db.Session; -import org.simantics.ui.SimanticsUI; -import org.simantics.utils.ui.ErrorLogger; -import org.simantics.utils.ui.dialogs.SafeMessageDialog; - -/** - * @author Tuukka Lehtonen - */ -final class ApplicationUtil { - - /** - * Used to make sure that the user has a choice to save the changes into the - * active database before closing. - */ - public static boolean allowShutdown(AtomicBoolean saveAtExit) { - try { - if (hasUnsavedChanges()) { - String[] buttons = { "&Save", "&Don't save", "&Cancel" }; - int result = SafeMessageDialog.doMessageDialog("Save Resources", null, "Save changes before closing ?", - MessageDialog.QUESTION, buttons, 2); - - switch (result) { - case 0: - saveAtExit.set(true); - break; - case 1: - saveAtExit.set(false); - break; - case 2: - return false; - default: - return false; - } - } - - // If any errors occur during this check, just log them, but allow - // for the program to be closed and make sure nothing is saved, - // since it would probably be corrupt. - } catch (RuntimeException e) { - ErrorLogger.defaultLogError( - "RuntimeException occured while querying database session for unsaved changes.", e); - saveAtExit.set(false); - } catch (Error e) { - ErrorLogger.defaultLogError("Error occured while querying database session for unsaved changes.", e); - saveAtExit.set(false); - } - return true; - } - - public static boolean hasUnsavedChanges() { - Session session = SimanticsUI.peekSession(); - if (session == null) - return false; - - // hasChangesToSave is deprecated -// LifecycleSupport lfs = session.getService(LifecycleSupport.class); -// try { -// return lfs.hasChangesToSave(); -// } catch (DatabaseException e) { -// ErrorLogger.defaultLogError( -// "Problems encountered while checking for unsaved changes, see exception for details.", e); -// } - return false; - } - -} +package org.simantics.workbench.internal; + +import java.util.concurrent.atomic.AtomicBoolean; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.simantics.db.Session; +import org.simantics.ui.SimanticsUI; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.dialogs.SafeMessageDialog; + +/** + * @author Tuukka Lehtonen + */ +final class ApplicationUtil { + + /** + * Used to make sure that the user has a choice to save the changes into the + * active database before closing. + */ + public static boolean allowShutdown(AtomicBoolean saveAtExit) { + try { + if (hasUnsavedChanges()) { + String[] buttons = { "&Save", "&Don't save", "&Cancel" }; + int result = SafeMessageDialog.doMessageDialog("Save Resources", null, "Save changes before closing ?", + MessageDialog.QUESTION, buttons, 2); + + switch (result) { + case 0: + saveAtExit.set(true); + break; + case 1: + saveAtExit.set(false); + break; + case 2: + return false; + default: + return false; + } + } + + // If any errors occur during this check, just log them, but allow + // for the program to be closed and make sure nothing is saved, + // since it would probably be corrupt. + } catch (RuntimeException e) { + ErrorLogger.defaultLogError( + "RuntimeException occured while querying database session for unsaved changes.", e); + saveAtExit.set(false); + } catch (Error e) { + ErrorLogger.defaultLogError("Error occured while querying database session for unsaved changes.", e); + saveAtExit.set(false); + } + return true; + } + + public static boolean hasUnsavedChanges() { + Session session = SimanticsUI.peekSession(); + if (session == null) + return false; + + // hasChangesToSave is deprecated +// LifecycleSupport lfs = session.getService(LifecycleSupport.class); +// try { +// return lfs.hasChangesToSave(); +// } catch (DatabaseException e) { +// ErrorLogger.defaultLogError( +// "Problems encountered while checking for unsaved changes, see exception for details.", e); +// } + return false; + } + +}