<inherits name="com.vaadin.Vaadin" />
+ <!-- Elemental is used for handling Json only -->
+ <inherits name="elemental.Json" />
+
<entry-point class="com.vaadin.client.ApplicationConfiguration" />
<generate-with
<inherits name="com.google.gwt.http.HTTP" />
- <inherits name="elemental.Json" />
-
<inherits name="com.google.gwt.logging.Logging" />
<set-property name="gwt.logging.enabled" value="TRUE" />
JavaScriptObject jso = states
.getJavaScriptObject(connectorId);
- JsonObject stateJson = WidgetUtil.jso2json(jso);
+ JsonObject stateJson = Util.jso2json(jso);
if (connector instanceof HasJavaScriptConnectorHelper) {
((HasJavaScriptConnectorHelper) connector)
VConsole.log(" * Performing server to client RPC calls");
- JsonArray rpcCalls = WidgetUtil.jso2json(json
+ JsonArray rpcCalls = Util.jso2json(json
.getJavaScriptObject("rpc"));
int rpcLength = rpcCalls.length();
iface = findWildcardInterface(method);
}
- JsonArray argumentsArray = WidgetUtil.jso2json(arguments);
+ JsonArray argumentsArray = Util.jso2json(arguments);
Object[] parameters = new Object[arguments.length()];
for (int i = 0; i < parameters.length; i++) {
parameters[i] = argumentsArray.get(i);
}-*/;
public Object[] decodeRpcParameters(JsonArray parametersJson) {
- return new Object[] { WidgetUtil.json2jso(parametersJson) };
+ return new Object[] { Util.json2jso(parametersJson) };
}
public void setTag(int tag) {
if ("com.vaadin.ui.JavaScript$JavaScriptCallbackRpc".equals(iface)
&& "call".equals(method)) {
String callbackName = parametersJson.getString(0);
- JavaScriptObject arguments = WidgetUtil.json2jso(parametersJson
- .get(1));
+ JavaScriptObject arguments = Util.json2jso(parametersJson.get(1));
invokeCallback(getConnectorWrapper(), callbackName, arguments);
} else {
- JavaScriptObject arguments = WidgetUtil.json2jso(parametersJson);
+ JavaScriptObject arguments = Util.json2jso(parametersJson);
invokeJsRpc(rpcMap, iface, method, arguments);
// Also invoke wildcard interface
invokeJsRpc(rpcMap, "", method, arguments);
import java.util.Iterator;
import java.util.List;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.KeyEvent;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.util.SharedUtil;
+import elemental.js.json.JsJsonValue;
+import elemental.json.JsonValue;
+
public class Util {
/**
WidgetUtil.setSelectionRange(elem, pos, length, direction);
}
+ /**
+ * Converts a native {@link JavaScriptObject} into a {@link JsonValue}. This
+ * is a no-op in GWT code compiled to javascript, but needs some special
+ * handling to work when run in JVM.
+ *
+ * @param jso
+ * the java script object to represent as json
+ * @return the json representation
+ */
+ public static <T extends JsonValue> T jso2json(JavaScriptObject jso) {
+ if (GWT.isProdMode()) {
+ return (T) jso.<JsJsonValue> cast();
+ } else {
+ return elemental.json.Json.instance().parse(stringify(jso));
+ }
+ }
+
+ /**
+ * Converts a {@link JsonValue} into a native {@link JavaScriptObject}. This
+ * is a no-op in GWT code compiled to javascript, but needs some special
+ * handling to work when run in JVM.
+ *
+ * @param jsonValue
+ * the json value
+ * @return a native javascript object representation of the json value
+ */
+ public static JavaScriptObject json2jso(JsonValue jsonValue) {
+ if (GWT.isProdMode()) {
+ return ((JavaScriptObject) jsonValue.toNative()).cast();
+ } else {
+ return parse(jsonValue.toJson());
+ }
+ }
+
+ /**
+ * Convert a {@link JavaScriptObject} into a string representation.
+ *
+ * @param json
+ * a JavaScript object to be converted to a string
+ * @return JSON in string representation
+ */
+ private native static String stringify(JavaScriptObject json)
+ /*-{
+ return JSON.stringify(json);
+ }-*/;
+
+ /**
+ * Parse a string containing JSON into a {@link JavaScriptObject}.
+ *
+ * @param <T>
+ * the overlay type to expect from the parse
+ * @param jsonAsString
+ * @return a JavaScript object constructed from the parse
+ */
+ public native static <T extends JavaScriptObject> T parse(
+ String jsonAsString)
+ /*-{
+ return JSON.parse(jsonAsString);
+ }-*/;
+
}
} else {
setText("Unknown connector (" + connectorId + ")");
}
- dir((JsonObject) WidgetUtil.jso2json(stateChanges), this);
+ dir((JsonObject) Util.jso2json(stateChanges), this);
}
@Override
import java.util.Map;
import java.util.logging.Logger;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.shared.util.SharedUtil;
-import elemental.js.json.JsJsonValue;
-import elemental.json.JsonValue;
-
/**
* Utility methods which are related to client side code only
*/
}
}-*/;
- /**
- * Converts a native {@link JavaScriptObject} into a {@link JsonValue}. This
- * is a no-op in GWT code compiled to javascript, but needs some special
- * handling to work when run in JVM.
- *
- * @param jso
- * the java script object to represent as json
- * @return the json representation
- */
- public static <T extends JsonValue> T jso2json(JavaScriptObject jso) {
- if (GWT.isProdMode()) {
- return (T) jso.<JsJsonValue> cast();
- } else {
- return elemental.json.Json.instance().parse(stringify(jso));
- }
- }
-
- /**
- * Converts a {@link JsonValue} into a native {@link JavaScriptObject}. This
- * is a no-op in GWT code compiled to javascript, but needs some special
- * handling to work when run in JVM.
- *
- * @param jsonValue
- * the json value
- * @return a native javascript object representation of the json value
- */
- public static JavaScriptObject json2jso(JsonValue jsonValue) {
- if (GWT.isProdMode()) {
- return ((JavaScriptObject) jsonValue.toNative()).cast();
- } else {
- return parse(jsonValue.toJson());
- }
- }
-
- /**
- * Convert a {@link JavaScriptObject} into a string representation.
- *
- * @param json
- * a JavaScript object to be converted to a string
- * @return JSON in string representation
- */
- private native static String stringify(JavaScriptObject json)
- /*-{
- return JSON.stringify(json);
- }-*/;
-
- /**
- * Parse a string containing JSON into a {@link JavaScriptObject}.
- *
- * @param <T>
- * the overlay type to expect from the parse
- * @param jsonAsString
- * @return a JavaScript object constructed from the parse
- */
- public native static <T extends JavaScriptObject> T parse(
- String jsonAsString)
- /*-{
- return JSON.parse(jsonAsString);
- }-*/;
-
/**
* The allowed value inaccuracy when comparing two double-typed pixel
* values.
import com.vaadin.client.JsArrayObject;
import com.vaadin.client.Profiler;
import com.vaadin.client.ServerConnector;
-import com.vaadin.client.WidgetUtil;
+import com.vaadin.client.Util;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
import com.vaadin.client.metadata.NoDataException;
import com.vaadin.client.metadata.Property;
import com.vaadin.client.ui.AbstractConnector;
+
import elemental.json.JsonObject;
public class StateChangeEvent extends
return true;
} else if (stateJson != null) {
// Check whether it's in the json object
- return isInJson(property, WidgetUtil.json2jso(stateJson));
+ return isInJson(property, Util.json2jso(stateJson));
} else {
// Legacy cases
if (changedProperties != null) {
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.vaadin.client.ServerConnector;
-import com.vaadin.client.WidgetUtil;
+import com.vaadin.client.Util;
import com.vaadin.client.communication.JavaScriptMethodInvocation;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.extensions.AbstractExtensionConnector;
}-*/;
public void sendRpc(String name, JsArray<JavaScriptObject> arguments) {
- Object[] parameters = new Object[] { name,
- WidgetUtil.jso2json(arguments) };
+ Object[] parameters = new Object[] { name, Util.jso2json(arguments) };
/*
* Must invoke manually as the RPC interface can't be used in GWT