Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java @ 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 | 0ba7c43e7b62 |
comparison
equal
deleted
inserted
replaced
211:b92281182c6b | 212:e3ea3c74b7f5 |
---|---|
3 import com.google.gwt.core.client.GWT; | 3 import com.google.gwt.core.client.GWT; |
4 import com.google.gwt.i18n.client.LocaleInfo; | 4 import com.google.gwt.i18n.client.LocaleInfo; |
5 import com.google.gwt.user.client.Window; | 5 import com.google.gwt.user.client.Window; |
6 | 6 |
7 import com.smartgwt.client.types.Alignment; | 7 import com.smartgwt.client.types.Alignment; |
8 import com.smartgwt.client.util.BooleanCallback; | |
9 import com.smartgwt.client.util.SC; | |
8 import com.smartgwt.client.widgets.Label; | 10 import com.smartgwt.client.widgets.Label; |
9 import com.smartgwt.client.widgets.events.ClickEvent; | 11 import com.smartgwt.client.widgets.events.ClickEvent; |
10 import com.smartgwt.client.widgets.events.ClickHandler; | 12 import com.smartgwt.client.widgets.events.ClickHandler; |
11 import com.smartgwt.client.widgets.layout.HLayout; | 13 import com.smartgwt.client.widgets.layout.HLayout; |
12 | 14 |
87 } | 89 } |
88 }); | 90 }); |
89 | 91 |
90 language.addClickHandler(new ClickHandler() { | 92 language.addClickHandler(new ClickHandler() { |
91 public void onClick(ClickEvent event) { | 93 public void onClick(ClickEvent event) { |
92 LocaleInfo info = LocaleInfo.getCurrentLocale(); | 94 LocaleInfo info = LocaleInfo.getCurrentLocale(); |
93 String currentLocale = info.getLocaleName(); | 95 final String currentLocale = info.getLocaleName(); |
94 String newLocale = currentLocale.equals("de") ? "en" : "de"; | 96 final String newLocale = currentLocale.equals("de") |
95 | 97 ? "en" |
96 // XXX Maybe we should inform the user about fact, that we will | 98 : "de"; |
97 // loose the work of the current session. | 99 |
98 switchLanguage(currentLocale, newLocale); | 100 SC.confirm(messages.warning(), messages.warning_language(), |
101 new BooleanCallback() { | |
102 public void execute(Boolean value) { | |
103 if (value) { | |
104 switchLanguage(currentLocale, newLocale); | |
105 } | |
106 } | |
107 }); | |
99 } | 108 } |
100 }); | 109 }); |
101 | 110 |
102 info.addClickHandler(new ClickHandler() { | 111 info.addClickHandler(new ClickHandler() { |
103 public void onClick(ClickEvent event) { | 112 public void onClick(ClickEvent event) { |
218 * @param newLocale The new locale string (e.g. "de"). | 227 * @param newLocale The new locale string (e.g. "de"). |
219 */ | 228 */ |
220 protected void switchLanguage(String currentLocale, String newLocale) { | 229 protected void switchLanguage(String currentLocale, String newLocale) { |
221 String newLocation = Window.Location.getHref(); | 230 String newLocation = Window.Location.getHref(); |
222 | 231 |
232 String oldLocation = newLocation; | |
233 | |
234 if (newLocation.endsWith("/")) { | |
235 newLocation = newLocation.substring(0, newLocation.length()-1); | |
236 } | |
237 | |
238 String replace = null; | |
239 String replaceWith = null; | |
240 | |
223 if (newLocation.indexOf("&locale=") >= 0) { | 241 if (newLocation.indexOf("&locale=") >= 0) { |
224 String replace = currentLocale.equals("de") | 242 replace = currentLocale.equals("de") |
225 ? "&locale=de" | 243 ? "&locale=de" |
226 : "&locale=en"; | 244 : "&locale=en"; |
227 | 245 |
228 String replaceWith = newLocale.equals("de") | 246 replaceWith = "&locale=" + newLocale; |
229 ? "&locale=de" | |
230 : "&locale=en"; | |
231 | |
232 newLocation = newLocation.replace(replace, replaceWith); | |
233 } | 247 } |
234 else if (newLocation.indexOf("?locale=") >= 0) { | 248 else if (newLocation.indexOf("?locale=") >= 0) { |
235 String replace = currentLocale.equals("de") | 249 replace = currentLocale.equals("de") |
236 ? "?locale=de" | 250 ? "?locale=de" |
237 : "?locale=en"; | 251 : "?locale=en"; |
238 | 252 |
239 String replaceWith = currentLocale.equals("de") | 253 replaceWith = "?locale=" + newLocale; |
240 ? "?locale=de" | |
241 : "?locale=en"; | |
242 | |
243 newLocation = newLocation.replace(replace, replaceWith); | |
244 } | 254 } |
245 else { | 255 else { |
246 newLocation += newLocation.indexOf("?") >= 0 | 256 newLocation += newLocation.indexOf("?") >= 0 |
247 ? "&locale=" + newLocale | 257 ? "&locale=" + newLocale |
248 : "?locale=" + newLocale; | 258 : "?locale=" + newLocale; |
249 } | 259 } |
250 | 260 |
261 if (replace != null && replaceWith != null) { | |
262 newLocation = newLocation.replace(replace, replaceWith); | |
263 } | |
264 | |
251 Window.open(newLocation, "_self", ""); | 265 Window.open(newLocation, "_self", ""); |
252 } | 266 } |
253 } | 267 } |
254 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 268 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |