summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-05-28 12:00:15 +0300
committerVaadin Code Review <review@vaadin.com>2013-05-29 12:33:17 +0000
commita9afca67ba942afa287be3507eb225e0a7b954e6 (patch)
treed2ddd12b3acc2f83c3361c018717bd557454cec6 /client
parenta3ad62d947c86d3f53f333ca9bc36e4544cd5d46 (diff)
downloadvaadin-framework-a9afca67ba942afa287be3507eb225e0a7b954e6.tar.gz
vaadin-framework-a9afca67ba942afa287be3507eb225e0a7b954e6.zip
Moved Locale data handling to LocaleService (#11378)
The locale data is now tracked per UI instance and no longer sent in every request. Change-Id: I4bebd00327da6f8d812181fd76a85eb6196d0010
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ApplicationConnection.java21
-rw-r--r--client/src/com/vaadin/client/LocaleService.java54
2 files changed, 35 insertions, 40 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java
index 087ee87262..24275dadb9 100644
--- a/client/src/com/vaadin/client/ApplicationConnection.java
+++ b/client/src/com/vaadin/client/ApplicationConnection.java
@@ -1350,16 +1350,6 @@ public class ApplicationConnection {
handleUIDLDuration.logDuration(" * Loading widgets completed",
10);
- Profiler.enter("Handling locales");
- if (json.containsKey("locales")) {
- VConsole.log(" * Handling locales");
- // Store locale data
- JsArray<ValueMap> valueMapArray = json
- .getJSValueMapArray("locales");
- LocaleService.addLocales(valueMapArray);
- }
- Profiler.leave("Handling locales");
-
Profiler.enter("Handling meta information");
ValueMap meta = null;
if (json.containsKey("meta")) {
@@ -1399,6 +1389,17 @@ public class ApplicationConnection {
JsArrayObject<StateChangeEvent> pendingStateChangeEvents = updateConnectorState(
json, createdConnectorIds);
+ /*
+ * Doing this here so that locales are available also to the
+ * connectors which get a state change event before the UI.
+ */
+ Profiler.enter("Handling locales");
+ VConsole.log(" * Handling locales");
+ // Store locale data
+ LocaleService
+ .addLocales(getUIConnector().getState().localeServiceState.localeData);
+ Profiler.leave("Handling locales");
+
// Update hierarchy, do not fire events
ConnectorHierarchyUpdateResult connectorHierarchyUpdateResult = updateConnectorHierarchy(json);
diff --git a/client/src/com/vaadin/client/LocaleService.java b/client/src/com/vaadin/client/LocaleService.java
index 4009c95531..69345d7174 100644
--- a/client/src/com/vaadin/client/LocaleService.java
+++ b/client/src/com/vaadin/client/LocaleService.java
@@ -17,10 +17,12 @@
package com.vaadin.client;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.logging.Logger;
-import com.google.gwt.core.client.JsArray;
+import com.vaadin.shared.ui.ui.UIState.LocaleData;
/**
* Date / time etc. localisation service for all widgets. Caches all loaded
@@ -31,16 +33,17 @@ import com.google.gwt.core.client.JsArray;
*/
public class LocaleService {
- private static Map<String, ValueMap> cache = new HashMap<String, ValueMap>();
- private static String defaultLocale;
+ private static Map<String, LocaleData> cache = new HashMap<String, LocaleData>();
- public static void addLocale(ValueMap valueMap) {
+ private static String defaultLocale;
- final String key = valueMap.getString("name");
+ public static void addLocale(LocaleData localeData) {
+ final String key = localeData.name;
if (cache.containsKey(key)) {
cache.remove(key);
}
- cache.put(key, valueMap);
+ getLogger().fine("Received locale data for " + localeData.name);
+ cache.put(key, localeData);
if (cache.size() == 1) {
setDefaultLocale(key);
}
@@ -61,8 +64,7 @@ public class LocaleService {
public static String[] getMonthNames(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getStringArray("mn");
+ return cache.get(locale).monthNames;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -71,8 +73,7 @@ public class LocaleService {
public static String[] getShortMonthNames(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getStringArray("smn");
+ return cache.get(locale).shortMonthNames;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -81,8 +82,7 @@ public class LocaleService {
public static String[] getDayNames(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getStringArray("dn");
+ return cache.get(locale).dayNames;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -91,8 +91,7 @@ public class LocaleService {
public static String[] getShortDayNames(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getStringArray("sdn");
+ return cache.get(locale).shortDayNames;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -101,8 +100,7 @@ public class LocaleService {
public static int getFirstDayOfWeek(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getInt("fdow");
+ return cache.get(locale).firstDayOfWeek;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -111,8 +109,7 @@ public class LocaleService {
public static String getDateFormat(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getString("df");
+ return cache.get(locale).dateFormat;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -121,8 +118,7 @@ public class LocaleService {
public static boolean isTwelveHourClock(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getBoolean("thc");
+ return cache.get(locale).twelveHourClock;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -131,8 +127,7 @@ public class LocaleService {
public static String getClockDelimiter(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getString("hmd");
+ return cache.get(locale).hourMinuteDelimiter;
} else {
throw new LocaleNotLoadedException(locale);
}
@@ -141,20 +136,19 @@ public class LocaleService {
public static String[] getAmPmStrings(String locale)
throws LocaleNotLoadedException {
if (cache.containsKey(locale)) {
- final ValueMap l = cache.get(locale);
- return l.getStringArray("ampm");
+ return new String[] { cache.get(locale).am, cache.get(locale).pm };
} else {
throw new LocaleNotLoadedException(locale);
}
-
}
- public static void addLocales(JsArray<ValueMap> valueMapArray) {
- for (int i = 0; i < valueMapArray.length(); i++) {
- addLocale(valueMapArray.get(i));
-
+ public static void addLocales(List<LocaleData> localeDatas) {
+ for (LocaleData localeData : localeDatas) {
+ addLocale(localeData);
}
-
}
+ private static Logger getLogger() {
+ return Logger.getLogger(LocaleService.class.getName());
+ }
}