changeset 212:e3ea3c74b7f5

Fixed the function to toggle the language and added a warning dialog that informs the user about the creation of a new session. flys-client/trunk@1652 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 07 Apr 2011 10:33:48 +0000
parents b92281182c6b
children 7ea004d0ffbc
files flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java
diffstat 6 files changed, 56 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/flys-client/ChangeLog	Tue Apr 05 08:13:48 2011 +0000
+++ b/flys-client/ChangeLog	Thu Apr 07 10:33:48 2011 +0000
@@ -1,3 +1,17 @@
+2011-04-07  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.properties,
+	  src/main/java/de/intevation/flys/client/client/FLYSConstants.java:
+	  Added new strings for a warning dialog that is opened when the user
+	  start changing the current language.
+
+	* src/main/java/de/intevation/flys/client/client/ui/MainMenu.java: Fixed
+	  the function to toggle the language and added a warning dialog that
+	  informs the user about the creation of a new session when the language
+	  is changed.
+
 2011-04-05  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties,
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Tue Apr 05 08:13:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.java	Thu Apr 07 10:33:48 2011 +0000
@@ -26,6 +26,10 @@
 
     String info();
 
+    String warning();
+
+    String warning_language();
+
     String no_projects();
 
     String load_projects();
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Tue Apr 05 08:13:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants.properties	Thu Apr 07 10:33:48 2011 +0000
@@ -7,6 +7,8 @@
 manage_projects = Manage Projects
 switch_language = German
 info = Info
+warning = Attention
+warning_language = You go to start a new session when you choose the language.
 no_projects = No existing calculations found.
 load_projects = Load calculations...
 date_format = yyyy-MM-dd
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Tue Apr 05 08:13:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_de.properties	Thu Apr 07 10:33:48 2011 +0000
@@ -7,6 +7,8 @@
 manage_projects = Projekte verwalten
 switch_language = Englisch
 info = Info
+warning = Achtung
+warning_language = Das \u00c4ndern der Sprache \u00f6ffnet eine neue Sitzung.
 no_projects = Keine alten Berechnungen gefunden.
 load_projects = Lade Berechnungen...
 date_format = dd.MM.yyyy
--- a/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Tue Apr 05 08:13:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/FLYSConstants_en.properties	Thu Apr 07 10:33:48 2011 +0000
@@ -7,6 +7,8 @@
 manage_projects = Manage Projects
 switch_language = German
 info = Info
+warning = Attention
+warning_language = You go to start a new session when you choose the language.
 no_projects = No existing calculations found.
 load_projects = Load calculations...
 date_format = yyyy-MM-dd
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Tue Apr 05 08:13:48 2011 +0000
+++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java	Thu Apr 07 10:33:48 2011 +0000
@@ -5,6 +5,8 @@
 import com.google.gwt.user.client.Window;
 
 import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.util.BooleanCallback;
+import com.smartgwt.client.util.SC;
 import com.smartgwt.client.widgets.Label;
 import com.smartgwt.client.widgets.events.ClickEvent;
 import com.smartgwt.client.widgets.events.ClickHandler;
@@ -89,13 +91,20 @@
 
         language.addClickHandler(new ClickHandler() {
             public void onClick(ClickEvent event) {
-                LocaleInfo info      = LocaleInfo.getCurrentLocale();
-                String currentLocale = info.getLocaleName();
-                String newLocale     = currentLocale.equals("de") ? "en" : "de";
+                LocaleInfo info            = LocaleInfo.getCurrentLocale();
+                final String currentLocale = info.getLocaleName();
+                final String newLocale     = currentLocale.equals("de")
+                    ? "en"
+                    : "de";
 
-                // XXX  Maybe we should inform the user about fact, that we will
-                // loose the work of the current session.
-                switchLanguage(currentLocale, newLocale);
+                SC.confirm(messages.warning(), messages.warning_language(),
+                    new BooleanCallback() {
+                        public void execute(Boolean value) {
+                            if (value) {
+                                switchLanguage(currentLocale, newLocale);
+                            }
+                        }
+                    });
             }
         });
 
@@ -220,27 +229,28 @@
     protected void switchLanguage(String currentLocale, String newLocale) {
         String newLocation = Window.Location.getHref();
 
+        String oldLocation = newLocation;
+
+        if (newLocation.endsWith("/")) {
+            newLocation = newLocation.substring(0, newLocation.length()-1);
+        }
+
+        String replace     = null;
+        String replaceWith = null;
+
         if (newLocation.indexOf("&locale=") >= 0) {
-            String replace = currentLocale.equals("de")
-                ? "&locale=de"
-                : "&locale=en";
-
-            String replaceWith = newLocale.equals("de")
+            replace = currentLocale.equals("de")
                 ? "&locale=de"
                 : "&locale=en";
 
-            newLocation = newLocation.replace(replace, replaceWith);
+            replaceWith = "&locale=" + newLocale;
         }
         else if (newLocation.indexOf("?locale=") >= 0) {
-            String replace = currentLocale.equals("de")
+            replace = currentLocale.equals("de")
                 ? "?locale=de"
                 : "?locale=en";
 
-            String replaceWith = currentLocale.equals("de")
-                ? "?locale=de"
-                : "?locale=en";
-
-            newLocation = newLocation.replace(replace, replaceWith);
+            replaceWith = "?locale=" + newLocale;
         }
         else {
             newLocation += newLocation.indexOf("?") >= 0
@@ -248,6 +258,10 @@
                 : "?locale=" + newLocale;
         }
 
+        if (replace != null && replaceWith != null) {
+            newLocation = newLocation.replace(replace, replaceWith);
+        }
+
         Window.open(newLocation, "_self", "");
     }
 }

http://dive4elements.wald.intevation.org