comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java @ 210:c587903f02a4

Implemented the button to toggle the current locale. flys-client/trunk@1644 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 05 Apr 2011 06:25:17 +0000
parents 33e24b33fc38
children b92281182c6b
comparison
equal deleted inserted replaced
209:9c8f450655c7 210:c587903f02a4
1 package de.intevation.flys.client.client.ui; 1 package de.intevation.flys.client.client.ui;
2 2
3 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
4 import com.google.gwt.i18n.client.LocaleInfo;
5 import com.google.gwt.user.client.Window;
4 6
5 import com.smartgwt.client.types.Alignment; 7 import com.smartgwt.client.types.Alignment;
6 import com.smartgwt.client.widgets.Label; 8 import com.smartgwt.client.widgets.Label;
7 import com.smartgwt.client.widgets.events.ClickEvent; 9 import com.smartgwt.client.widgets.events.ClickEvent;
8 import com.smartgwt.client.widgets.events.ClickHandler; 10 import com.smartgwt.client.widgets.events.ClickHandler;
85 } 87 }
86 }); 88 });
87 89
88 language.addClickHandler(new ClickHandler() { 90 language.addClickHandler(new ClickHandler() {
89 public void onClick(ClickEvent event) { 91 public void onClick(ClickEvent event) {
90 GWT.log("Clicked 'language' button."); 92 LocaleInfo info = LocaleInfo.getCurrentLocale();
91 GWT.log("IMPLEMENT the 'switch language' function."); 93 String currentLocale = info.getLocaleName();
94 String newLocale = currentLocale.equals("de") ? "en" : "de";
95
96 // XXX Maybe we should inform the user about fact, that we will
97 // loose the work of the current session.
98 switchLanguage(currentLocale, newLocale);
92 } 99 }
93 }); 100 });
94 101
95 info.addClickHandler(new ClickHandler() { 102 info.addClickHandler(new ClickHandler() {
96 public void onClick(ClickEvent event) { 103 public void onClick(ClickEvent event) {
196 * Create a new project by calling FLYS.newProject(). 203 * Create a new project by calling FLYS.newProject().
197 */ 204 */
198 protected void createNewProject() { 205 protected void createNewProject() {
199 flys.newProject(); 206 flys.newProject();
200 } 207 }
208
209
210 /**
211 * This method triggers the language switch between the <i>currentLocale</i>
212 * and the <i>newLocale</i>. The switch is done by replacing a "locale="
213 * parameter in the url of the application. We could use the GWT UrlBuilder
214 * class to create a new URL, but - in my eyes - this class is a bit
215 * inconsistens in its implementation.
216 *
217 * @param currentLocale The current locale string (e.g. "en").
218 * @param newLocale The new locale string (e.g. "de").
219 */
220 protected void switchLanguage(String currentLocale, String newLocale) {
221 String newLocation = Window.Location.getHref();
222
223 if (newLocation.indexOf("&locale=") >= 0) {
224 String replace = currentLocale.equals("de")
225 ? "&locale=de"
226 : "&locale=en";
227
228 String replaceWith = newLocale.equals("de")
229 ? "&locale=de"
230 : "&locale=en";
231
232 newLocation = newLocation.replace(replace, replaceWith);
233 }
234 else if (newLocation.indexOf("?locale=") >= 0) {
235 String replace = currentLocale.equals("de")
236 ? "?locale=de"
237 : "?locale=en";
238
239 String replaceWith = currentLocale.equals("de")
240 ? "?locale=de"
241 : "?locale=en";
242
243 newLocation = newLocation.replace(replace, replaceWith);
244 }
245 else {
246 newLocation += newLocation.indexOf("?") >= 0
247 ? "&locale=" + newLocale
248 : "?locale=" + newLocale;
249 }
250
251 Window.open(newLocation, "_self", "");
252 }
201 } 253 }
202 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 254 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org