From 9d6ebbaa7da6bec42bdcc873f5c3002cff8da50c Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Fri, 7 May 2010 12:34:17 +0000 Subject: [PATCH] minor: use GWT handler to show confirmation message on exit SVN: 15847 --- .../client/web/client/application/Client.java | 2 +- .../menu/user/action/LogoutCallback.java | 6 +-- .../web/client/application/util/GWTUtils.java | 38 ++++++++++++++----- .../systemsx/cisd/openbis/public/index.html | 15 +------- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java index 9888e7b0f6c..8eaa9a147df 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Client.java @@ -283,7 +283,7 @@ public class Client implements EntryPoint, ValueChangeHandler<String> viewContext.initDisplaySettingsManager(); dispatcher.dispatch(AppEvents.INIT); afterInitAction.execute(); - GWTUtils.setAllowConfirmOnExit(true); + GWTUtils.setConfirmExitMessage(); } } } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/menu/user/action/LogoutCallback.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/menu/user/action/LogoutCallback.java index 56615094b8c..d42aae839cc 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/menu/user/action/LogoutCallback.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/menu/user/action/LogoutCallback.java @@ -26,19 +26,19 @@ final class LogoutCallback extends AbstractAsyncCallback<Void> LogoutCallback(IViewContext<ICommonClientServiceAsync> viewContext) { super(viewContext); - System.out.println("CREATE "+this); + System.out.println("CREATE " + this); } @Override protected void finalize() throws Throwable { - System.out.println("FINALIZE "+this); + System.out.println("FINALIZE " + this); } @Override public final void process(final Void result) { viewContext.getPageController().reload(true); - GWTUtils.setAllowConfirmOnExit(false); + GWTUtils.removeConfirmExitMessage(); } } \ No newline at end of file diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java index 526cd185570..92341ddd47b 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/util/GWTUtils.java @@ -29,6 +29,9 @@ import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig; import com.extjs.gxt.ui.client.widget.treegrid.TreeGrid; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.DeferredCommand; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.Window.ClosingEvent; +import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.ListBox; import ch.systemsx.cisd.openbis.generic.client.web.client.application.model.ModelDataPropertyNames; @@ -268,6 +271,32 @@ public final class GWTUtils "$", "-DOLLAR-"); } + // confirm on exit message + + private final static String CONFIRM_EXIT_MSG = + "WARNING: By doing this you will in fact leave openBIS!"; + + public final static void setConfirmExitMessage() + { + setConfirmExitMessage(CONFIRM_EXIT_MSG); + } + + public final static void removeConfirmExitMessage() + { + setConfirmExitMessage(null); + } + + private final static void setConfirmExitMessage(final String msgOrNull) + { + Window.addWindowClosingHandler(new ClosingHandler() + { + public void onWindowClosing(ClosingEvent event) + { + event.setMessage(msgOrNull); + } + }); + } + // // native JavaScript // @@ -284,15 +313,6 @@ public final class GWTUtils return search.indexOf("?") == 0 ? search.substring(1) : search; }-*/; - /** - * Depending on specified <var>allowConfirmOnExit</var> when user tries to exit application - * confirmation dialog will or will not appear. - */ - public final static native void setAllowConfirmOnExit(boolean allowConfirmOnExit) - /*-{ - $wnd.allowConfirmOnExit = allowConfirmOnExit; - }-*/; - /** * Tooltip template displayed when mouse is over drop down list. */ diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html b/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html index edd85dd665d..dfd1d9129fa 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html +++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/index.html @@ -6,23 +6,12 @@ <link rel="shortcut icon" href="images/favicon.ico" /> <link rel="icon" type="image/png" href="images/favicon.png" /> <link rel="stylesheet" type="text/css" href="resources/css/gxt-all.css" /> + <!-- // This script loads your compiled module. If you add any GWT meta tags, they must be added before this line. --> <script language="javascript" - src="ch.systemsx.cisd.openbis.OpenBIS.nocache.js"></script> -<script language="JavaScript"> - // confirmation on exit depends on whether user is logged in - var allowConfirmOnExit = false; - window.onbeforeunload = confirmExit; - function confirmExit() - { - if (allowConfirmOnExit) { - return "WARNING: By doing this you will in fact leave openBIS!"; - } - } -</script> - + src="ch.systemsx.cisd.openbis.OpenBIS.nocache.js"></script> </head> <!-- // The body can have arbitrary html, or you can leave the body empty if you want to create a completely dynamic ui. -- GitLab