states.getJavaScriptObject(connectorId));
Object state = JsonDecoder.convertValue(
- stateDataAndType, connectorMap);
+ stateDataAndType, connectorMap,
+ ApplicationConnection.this);
paintable.setState((SharedState) state);
}
Object[] parameters = new Object[parametersJson.size()];
for (int j = 0; j < parametersJson.size(); ++j) {
parameters[j] = JsonDecoder.convertValue(
- (JSONArray) parametersJson.get(j), getConnectorMap());
+ (JSONArray) parametersJson.get(j), getConnectorMap(), this);
}
return new MethodInvocation(connectorId, interfaceName, methodName,
parameters);
for (int i = 0; i < invocation.getParameters().length; ++i) {
// TODO non-static encoder? type registration?
paramJson.set(i, JsonEncoder.encode(
- invocation.getParameters()[i], getConnectorMap()));
+ invocation.getParameters()[i], getConnectorMap(),
+ this));
}
invocationJson.set(3, paramJson);
reqJson.set(reqJson.size(), invocationJson);
package com.vaadin.terminal.gwt.client;
import com.vaadin.terminal.gwt.client.communication.SharedState;
+import com.vaadin.terminal.gwt.client.communication.URLReference;
import com.vaadin.ui.Component;
/**
// string!
private String caption = null;
private boolean visible = true;
+ private URLReference icon = null;
/**
* Returns the component height as set by the server.
this.visible = visible;
}
+ public URLReference getIcon() {
+ return icon;
+ }
+
+ public void setIcon(URLReference icon) {
+ this.icon = icon;
+ }
+
}
}
setStyleName(style);
- boolean hasIcon = uidl
- .hasAttribute(AbstractComponentConnector.ATTRIBUTE_ICON);
+ boolean hasIcon = owner.getState().getIcon() != null;
boolean showRequired = uidl
.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED);
boolean showError = uidl
// Icon forces the caption to be above the component
placedAfterComponent = false;
- icon.setUri(uidl
- .getStringAttribute(AbstractComponentConnector.ATTRIBUTE_ICON));
+ icon.setUri(owner.getState().getIcon().getURL());
} else if (icon != null) {
// Remove existing
@Deprecated
public boolean updateCaptionWithoutOwner(UIDL uidl, String caption,
- boolean disabled, boolean hasDescription) {
+ boolean disabled, boolean hasDescription, String iconURL) {
// TODO temporary method, needed because some tabsheet and accordion
// internal captions do not have an owner or shared state. Simplified to
// only support those cases
removeStyleDependentName("hasdescription");
}
}
- boolean hasIcon = uidl
- .hasAttribute(AbstractComponentConnector.ATTRIBUTE_ICON);
+ boolean hasIcon = iconURL != null;
boolean showError = uidl
.hasAttribute(AbstractComponentConnector.ATTRIBUTE_ERROR)
&& !uidl.getBooleanAttribute(AbstractComponentConnector.ATTRIBUTE_HIDEERRORS);
// Icon forces the caption to be above the component
placedAfterComponent = false;
- icon.setUri(uidl
- .getStringAttribute(AbstractComponentConnector.ATTRIBUTE_ICON));
+ icon.setUri(iconURL);
} else if (icon != null) {
// Remove existing
if (uidl.hasAttribute(AbstractComponentConnector.ATTRIBUTE_ERROR)) {
return true;
}
- if (uidl.hasAttribute(AbstractComponentConnector.ATTRIBUTE_ICON)) {
+ if (state.getIcon() != null) {
return true;
}
if (uidl.hasAttribute(AbstractComponentConnector.ATTRIBUTE_REQUIRED)) {
package com.vaadin.terminal.gwt.client.communication;
import com.google.gwt.json.client.JSONObject;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.server.JsonCodec;
*
* @since 7.0
*/
-public interface JSONSerializer {
+public interface JSONSerializer<T> {
/**
* Creates and deserializes an object received from the server. Must be
* references to paintables
* @return A deserialized object
*/
- Object deserialize(JSONObject jsonValue, ConnectorMap idMapper);
+ T deserialize(JSONObject jsonValue, ConnectorMap idMapper,
+ ApplicationConnection connection);
/**
* Serialize the given object into JSON. Must be compatible with
* references to paintables
* @return A JSON serialized version of the object
*/
- JSONObject serialize(Object value, ConnectorMap idMapper);
+ JSONObject serialize(T value, ConnectorMap idMapper,
+ ApplicationConnection connection);
}
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.terminal.gwt.client.ConnectorMap;
* JSON array with two elements
* @param idMapper
* mapper between connector ID and {@link Connector} objects
+ * @param connection
+ * reference to the current ApplicationConnection
* @return converted value (does not contain JSON types)
*/
- public static Object convertValue(JSONArray jsonArray, ConnectorMap idMapper) {
+ public static Object convertValue(JSONArray jsonArray,
+ ConnectorMap idMapper, ApplicationConnection connection) {
String type = ((JSONString) jsonArray.get(0)).stringValue();
- return convertValue(type, jsonArray.get(1), idMapper);
+ return convertValue(type, jsonArray.get(1), idMapper, connection);
}
private static Object convertValue(String variableType, Object value,
- ConnectorMap idMapper) {
+ ConnectorMap idMapper, ApplicationConnection connection) {
Object val = null;
// TODO type checks etc.
if (JsonEncoder.VTYPE_UNDEFINED.equals(variableType)) {
val = null;
} else if (JsonEncoder.VTYPE_ARRAY.equals(variableType)) {
- val = convertArray((JSONArray) value, idMapper);
+ val = convertArray((JSONArray) value, idMapper, connection);
} else if (JsonEncoder.VTYPE_MAP.equals(variableType)) {
- val = convertMap((JSONObject) value, idMapper);
+ val = convertMap((JSONObject) value, idMapper, connection);
} else if (JsonEncoder.VTYPE_STRINGARRAY.equals(variableType)) {
val = convertStringArray((JSONArray) value);
} else if (JsonEncoder.VTYPE_STRING.equals(variableType)) {
JSONSerializer serializer = serializerMap
.getSerializer(variableType);
// TODO handle case with no serializer found
- Object object = serializer
- .deserialize((JSONObject) value, idMapper);
+ Object object = serializer.deserialize((JSONObject) value,
+ idMapper, connection);
return object;
}
}
private static Map<String, Object> convertMap(JSONObject jsonMap,
- ConnectorMap idMapper) {
+ ConnectorMap idMapper, ApplicationConnection connection) {
HashMap<String, Object> map = new HashMap<String, Object>();
Iterator<String> it = jsonMap.keySet().iterator();
while (it.hasNext()) {
String key = it.next();
- map.put(key, convertValue((JSONArray) jsonMap.get(key), idMapper));
+ map.put(key,
+ convertValue((JSONArray) jsonMap.get(key), idMapper,
+ connection));
}
return map;
}
}
private static Object[] convertArray(JSONArray jsonArray,
- ConnectorMap idMapper) {
+ ConnectorMap idMapper, ApplicationConnection connection) {
List<Object> tokens = new ArrayList<Object>();
for (int i = 0; i < jsonArray.size(); ++i) {
// each entry always has two elements: type and value
JSONArray entryArray = (JSONArray) jsonArray.get(i);
- tokens.add(convertValue(entryArray, idMapper));
+ tokens.add(convertValue(entryArray, idMapper, connection));
}
return tokens.toArray(new Object[tokens.size()]);
}
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.terminal.gwt.client.ConnectorMap;
* value to convert
* @param connectorMap
* mapper from connectors to connector IDs
+ * @param connection
* @return JSON representation of the value
*/
- public static JSONValue encode(Object value, ConnectorMap connectorMap) {
+ public static JSONValue encode(Object value, ConnectorMap connectorMap,
+ ApplicationConnection connection) {
if (null == value) {
// TODO as undefined type?
return combineTypeAndValue(VTYPE_UNDEFINED, JSONNull.getInstance());
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < array.length; ++i) {
// TODO handle object graph loops?
- jsonArray.set(i, encode(array[i], connectorMap));
+ jsonArray.set(i, encode(array[i], connectorMap, connection));
}
return combineTypeAndValue(VTYPE_ARRAY, jsonArray);
} else if (value instanceof Map) {
for (String mapKey : map.keySet()) {
// TODO handle object graph loops?
Object mapValue = map.get(mapKey);
- jsonMap.put(mapKey, encode(mapValue, connectorMap));
+ jsonMap.put(mapKey, encode(mapValue, connectorMap, connection));
}
return combineTypeAndValue(VTYPE_MAP, jsonMap);
} else if (value instanceof Connector) {
// TODO handle case with no serializer found
return combineTypeAndValue(type,
- serializer.serialize(value, connectorMap));
+ serializer.serialize(value, connectorMap, connection));
}
}
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.communication;
+
+import com.vaadin.Application;
+import com.vaadin.terminal.ApplicationResource;
+import com.vaadin.terminal.ExternalResource;
+import com.vaadin.terminal.Resource;
+import com.vaadin.terminal.ThemeResource;
+
+public class ResourceReference extends URLReference {
+
+ private Resource resource;
+
+ public ResourceReference(Resource resource) {
+ this.resource = resource;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ @Override
+ public String getURL() {
+ if (resource instanceof ExternalResource) {
+ return ((ExternalResource) resource).getURL();
+ } else if (resource instanceof ApplicationResource) {
+ final ApplicationResource r = (ApplicationResource) resource;
+ final Application a = r.getApplication();
+ if (a == null) {
+ throw new RuntimeException(
+ "An ApplicationResource ("
+ + r.getClass().getName()
+ + " must be attached to an application when it is sent to the client.");
+ }
+ final String uri = a.getRelativeLocation(r);
+ return uri;
+ } else if (resource instanceof ThemeResource) {
+ final String uri = "theme://"
+ + ((ThemeResource) resource).getResourceId();
+ return uri;
+ } else {
+ throw new RuntimeException(getClass().getSimpleName()
+ + " does not support resources of type: "
+ + resource.getClass().getName());
+ }
+
+ }
+}
--- /dev/null
+package com.vaadin.terminal.gwt.client.communication;
+
+public class URLReference {
+
+ private String URL;
+
+ /**
+ * Returns the URL that this object refers to.
+ * <p>
+ * Note that the URL can use special protocols like theme://
+ *
+ * @return The URL for this reference or null if unknown.
+ */
+ public String getURL() {
+ return URL;
+ }
+
+ /**
+ * Sets the URL that this object refers to
+ *
+ * @param URL
+ */
+ public void setURL(String URL) {
+ this.URL = URL;
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.vaadin.terminal.gwt.client.communication;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.json.client.JSONArray;
+import com.google.gwt.json.client.JSONObject;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ConnectorMap;
+
+public class URLReference_Serializer implements JSONSerializer<URLReference> {
+
+ public URLReference deserialize(JSONObject jsonValue,
+ ConnectorMap idMapper, ApplicationConnection connection) {
+ URLReference reference = GWT.create(URLReference.class);
+ JSONArray jsonURL = (JSONArray) jsonValue.get("URL");
+ String URL = (String) JsonDecoder.convertValue(jsonURL, idMapper,
+ connection);
+ reference.setURL(connection.translateVaadinUri(URL));
+ return reference;
+ }
+
+ public JSONObject serialize(URLReference value, ConnectorMap idMapper,
+ ApplicationConnection connection) {
+ JSONObject json = new JSONObject();
+ json.put("URL",
+ JsonEncoder.encode(value.getURL(), idMapper, connection));
+ return json;
+ }
+
+}
// constants, which may refer to these.
// Not all references to the string literals have been converted to use
// these!
- public static final String ATTRIBUTE_ICON = "icon";
public static final String ATTRIBUTE_REQUIRED = "required";
public static final String ATTRIBUTE_ERROR = "error";
public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
getWidget().errorIndicatorElement = null;
}
- if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
+ if (getState().getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
getWidget().wrapper.insertBefore(getWidget().icon.getElement(),
getWidget().captionElement);
}
- getWidget().icon.setUri(uidl.getStringAttribute(ATTRIBUTE_ICON));
+ getWidget().icon.setUri(getState().getIcon().getURL());
} else {
if (getWidget().icon != null) {
getWidget().wrapper.removeChild(getWidget().icon.getElement());
getWidget().setEnabled(false);
}
- if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
+ if (getState().getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
DOM.insertChild(getWidget().getElement(),
getWidget().icon.sinkEvents(VTooltip.TOOLTIP_EVENTS);
getWidget().icon.sinkEvents(Event.ONCLICK);
}
- getWidget().icon.setUri(uidl.getStringAttribute(ATTRIBUTE_ICON));
+ getWidget().icon.setUri(getState().getIcon().getURL());
} else if (getWidget().icon != null) {
// detach icon
DOM.removeChild(getWidget().getElement(),
} else {
getWidget().caption.setInnerText("");
}
- if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
+ if (getState().getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
getWidget().legend.insertFirst(getWidget().icon.getElement());
}
- getWidget().icon.setUri(uidl.getStringAttribute(ATTRIBUTE_ICON));
+ getWidget().icon.setUri(getState().getIcon().getURL());
legendEmpty = false;
} else {
if (getWidget().icon != null) {
"none");
}
- if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
+ if (getState().getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
getWidget().anchor.insertBefore(getWidget().icon.getElement(),
getWidget().captionElement);
}
- getWidget().icon.setUri(uidl.getStringAttribute(ATTRIBUTE_ICON));
+ getWidget().icon.setUri(getState().getIcon().getURL());
}
}
public void init() {
super.init();
- ButtonServerRpc rpcProxy = GWT
- .create(ButtonServerRpc.class);
+ ButtonServerRpc rpcProxy = GWT.create(ButtonServerRpc.class);
getWidget().buttonRpcProxy = initRPC(rpcProxy);
}
getWidget().errorIndicatorElement = null;
}
- if (uidl.hasAttribute(ATTRIBUTE_ICON)) {
+ if (getState().getIcon() != null) {
if (getWidget().icon == null) {
getWidget().icon = new Icon(client);
getWidget().getElement().insertBefore(
getWidget().icon.getElement(),
getWidget().captionElement);
}
- getWidget().icon.setUri(uidl.getStringAttribute(ATTRIBUTE_ICON));
+ getWidget().icon.setUri(getState().getIcon().getURL());
} else {
if (getWidget().icon != null) {
getWidget().getElement().removeChild(
getWidget().client = client;
getWidget().id = uidl.getId();
- getWidget().setIconUri(uidl, client);
+ if (getState().getIcon() != null) {
+ getWidget().setIconUri(getState().getIcon().getURL(), client);
+ } else {
+ getWidget().setIconUri(null, client);
+ }
getWidget().handleError(uidl);
public static final String ATTRIBUTE_TAB_DISABLED = "disabled";
public static final String ATTRIBUTE_TAB_DESCRIPTION = "description";
public static final String ATTRIBUTE_TAB_CAPTION = "caption";
+ public static final String ATTRIBUTE_TAB_ICON = "icon";
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
public static final String ATTRIBUTE_NODE_STYLE = "style";
public static final String ATTRIBUTE_NODE_CAPTION = "caption";
- public static final String ATTRIBUTE_NODE_ICON = AbstractComponentConnector.ATTRIBUTE_ICON;
+ public static final String ATTRIBUTE_NODE_ICON = "icon";
public static final String ATTRIBUTE_ACTION_CAPTION = "caption";
- public static final String ATTRIBUTE_ACTION_ICON = AbstractComponentConnector.ATTRIBUTE_ICON;
+ public static final String ATTRIBUTE_ACTION_ICON = ATTRIBUTE_NODE_ICON;
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
uidl,
uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_CAPTION),
uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DISABLED),
- uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION));
+ uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION),
+ uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ICON));
}
public int getWidgetWidth() {
boolean isEmpty = true;
- if (uidl.hasAttribute(AbstractComponentConnector.ATTRIBUTE_ICON)) {
+ if (state.getIcon() != null) {
if (icon == null) {
icon = new Icon(client);
DOM.insertChild(getElement(), icon.getElement(), 0);
}
- icon.setUri(uidl
- .getStringAttribute(AbstractComponentConnector.ATTRIBUTE_ICON));
+ icon.setUri(state.getIcon().getURL());
isEmpty = false;
} else {
if (icon != null) {
public static final String ATTRIBUTE_CHECKED = "checked";
public static final String ATTRIBUTE_ITEM_DESCRIPTION = "description";
- public static final String ATTRIBUTE_ITEM_ICON = AbstractComponentConnector.ATTRIBUTE_ICON;
+ public static final String ATTRIBUTE_ITEM_ICON = "icon";
public static final String ATTRIBUTE_ITEM_DISABLED = "disabled";
public static final String ATTRIBUTE_ITEM_STYLE = "style";
public static final String ATTRIBUTE_NOTIFICATION_STYLE = "style";
public static final String ATTRIBUTE_NOTIFICATION_CAPTION = "caption";
public static final String ATTRIBUTE_NOTIFICATION_MESSAGE = "message";
- public static final String ATTRIBUTE_NOTIFICATION_ICON = AbstractComponentConnector.ATTRIBUTE_ICON;
+ public static final String ATTRIBUTE_NOTIFICATION_ICON = "icon";
public static final String ATTRIBUTE_NOTIFICATION_POSITION = "position";
public static final String ATTRIBUTE_NOTIFICATION_DELAY = "delay";
}
}
- void setIconUri(UIDL uidl, ApplicationConnection client) {
- final String iconUri = uidl
- .hasAttribute(AbstractComponentConnector.ATTRIBUTE_ICON) ? uidl
- .getStringAttribute(AbstractComponentConnector.ATTRIBUTE_ICON)
- : null;
+ void setIconUri(String iconUri, ApplicationConnection client) {
if (iconUri == null) {
if (icon != null) {
DOM.removeChild(captionNode, icon.getElement());
uidl,
uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_CAPTION),
uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DISABLED),
- uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION));
+ uidl.hasAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_DESCRIPTION),
+ uidl.getStringAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ICON));
setClosable(uidl.hasAttribute("closable"));
// Caption must be set before required header size is measured. If
// the caption attribute is missing the caption should be cleared.
- getWidget()
- .setCaption(
- getState().getCaption(),
- uidl.getStringAttribute(AbstractComponentConnector.ATTRIBUTE_ICON));
+ String iconURL = null;
+ if (getState().getIcon() != null) {
+ iconURL = getState().getIcon().getURL();
+ }
+ getWidget().setCaption(getState().getCaption(), iconURL);
}
getWidget().visibilityChangesDisabled = true;
*/
public static JSONArray encode(Object value, PaintableIdMapper idMapper)
throws JSONException {
+ return encode(value, null, idMapper);
+ }
+
+ public static JSONArray encode(Object value, Class<?> valueType,
+ PaintableIdMapper idMapper) throws JSONException {
+
if (null == value) {
// TODO as undefined type?
return combineTypeAndValue(JsonEncoder.VTYPE_UNDEFINED,
} else {
// Any object that we do not know how to encode we encode by looping
// through fields
- return combineTypeAndValue(value.getClass().getCanonicalName(),
+ if (valueType == null) {
+ valueType = value.getClass();
+ }
+
+ return combineTypeAndValue(valueType.getCanonicalName(),
encodeObject(value, idMapper));
}
}
for (PropertyDescriptor pd : Introspector.getBeanInfo(
value.getClass()).getPropertyDescriptors()) {
String fieldName = pd.getName();
+ Class<?> fieldType = pd.getPropertyType();
if (pd.getReadMethod() == null || pd.getWriteMethod() == null) {
continue;
}
Method getterMethod = pd.getReadMethod();
Object fieldValue = getterMethod.invoke(value, null);
- jsonMap.put(fieldName, encode(fieldValue, idMapper));
+ jsonMap.put(fieldName, encode(fieldValue, fieldType, idMapper));
}
} catch (Exception e) {
// TODO: Should exceptions be handled in a different way?
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ConnectorMap;
+import com.vaadin.terminal.gwt.client.communication.JSONSerializer;
import com.vaadin.terminal.gwt.client.communication.JsonDecoder;
import com.vaadin.terminal.gwt.client.communication.JsonEncoder;
import com.vaadin.terminal.gwt.client.communication.SerializerMap;
-import com.vaadin.terminal.gwt.client.communication.JSONSerializer;
/**
* GWT generator for creating serializer classes for custom classes sent from
// Serializer
- // public JSONValue serialize(Object value, ConnectorMap idMapper) {
+ // public JSONValue serialize(Object value, ConnectorMap idMapper,
+ // ApplicationConnection connection) {
sourceWriter.println("public " + JSONObject.class.getName()
+ " serialize(" + Object.class.getName() + " value, "
- + ConnectorMap.class.getName() + " idMapper) {");
+ + ConnectorMap.class.getName() + " idMapper, "
+ + ApplicationConnection.class.getName() + " connection) {");
sourceWriter.indent();
// MouseEventDetails castedValue = (MouseEventDetails) value;
sourceWriter.println(beanQualifiedSourceName + " castedValue = ("
+ ". Serialization will likely fail");
}
// json.put("button",
- // JsonEncoder.encode(castedValue.getButton(), idMapper));
+ // JsonEncoder.encode(castedValue.getButton(), idMapper,
+ // connection));
sourceWriter.println("json.put(\"" + fieldName + "\", "
+ JsonEncoder.class.getName() + ".encode(castedValue."
- + getterName + "(), idMapper));");
+ + getterName + "(), idMapper, connection));");
}
// return json;
sourceWriter.println("return json;");
// Deserializer
sourceWriter.println("public " + beanQualifiedSourceName
+ " deserialize(" + JSONObject.class.getName() + " jsonValue, "
- + ConnectorMap.class.getName() + " idMapper) {");
+ + ConnectorMap.class.getName() + " idMapper, "
+ + ApplicationConnection.class.getName() + " connection) {");
sourceWriter.indent();
// VButtonState state = GWT.create(VButtonState.class);
+ " = (JSONArray) jsonValue.get(\"" + fieldName + "\");");
// state.setHeight((String)
- // JsonDecoder.convertValue(jsonFieldValue,idMapper));
+ // JsonDecoder.convertValue(jsonFieldValue,idMapper, connection));
String fieldType;
JPrimitiveType primitiveType = setterParameterType.isPrimitive();
sourceWriter.println("state." + setterName + "((" + fieldType
+ ") JsonDecoder.convertValue(" + jsonFieldName
- + ", idMapper));");
+ + ", idMapper, connection));");
}
// return state;
import com.google.gwt.core.ext.typeinfo.JMethod;
import com.google.gwt.core.ext.typeinfo.JType;
import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ConnectorMap;
import com.vaadin.terminal.gwt.client.communication.ClientRpc;
+import com.vaadin.terminal.gwt.client.communication.JSONSerializer;
import com.vaadin.terminal.gwt.client.communication.SerializerMap;
import com.vaadin.terminal.gwt.client.communication.ServerRpc;
import com.vaadin.terminal.gwt.client.communication.SharedState;
-import com.vaadin.terminal.gwt.client.communication.JSONSerializer;
/**
* GWT generator that creates a {@link SerializerMap} implementation (mapper
TypeOracle typeOracle = context.getTypeOracle();
Set<JClassType> typesNeedingSerializers = findTypesNeedingSerializers(
typeOracle, logger);
-
+ Set<JClassType> typesWithExistingSerializers = findTypesWithExistingSerializers(
+ typeOracle, logger);
+ Set<JClassType> serializerMappings = new HashSet<JClassType>();
+ serializerMappings.addAll(typesNeedingSerializers);
+ serializerMappings.addAll(typesWithExistingSerializers);
// get classType and save instance variables
JClassType classType = typeOracle.getType(typeName);
packageName = classType.getPackage().getName();
className = classType.getSimpleSourceName() + "Impl";
// Generate class source code for SerializerMapImpl
- generateSerializerMap(typesNeedingSerializers, logger, context);
+ generateSerializerMap(serializerMappings, logger, context);
SerializerGenerator sg = new SerializerGenerator();
for (JClassType type : typesNeedingSerializers) {
return packageName + "." + className;
}
+ private Set<JClassType> findTypesWithExistingSerializers(
+ TypeOracle typeOracle, TreeLogger logger) {
+ JClassType serializerInterface = typeOracle
+ .findType(JSONSerializer.class.getName());
+ Set<JClassType> types = new HashSet<JClassType>();
+ for (JClassType serializer : serializerInterface.getSubtypes()) {
+ JType[] deserializeParamTypes = new JType[] {
+ typeOracle.findType(JSONObject.class.getName()),
+ typeOracle.findType(ConnectorMap.class.getName()),
+ typeOracle.findType(ApplicationConnection.class.getName()) };
+ JMethod deserializeMethod = serializer.findMethod("deserialize",
+ deserializeParamTypes);
+ if (deserializeMethod == null) {
+ continue;
+ }
+
+ types.add(deserializeMethod.getReturnType().isClass());
+ }
+ return types;
+ }
+
/**
* Generate source code for SerializerMapImpl
*
import com.vaadin.terminal.Terminal;
import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.communication.ClientRpc;
-import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
+import com.vaadin.terminal.gwt.client.communication.ResourceReference;
import com.vaadin.terminal.gwt.server.ClientMethodInvocation;
import com.vaadin.terminal.gwt.server.ComponentSizeValidator;
import com.vaadin.terminal.gwt.server.RpcManager;
*/
private Object applicationData;
- /**
- * Icon to be shown together with caption.
- */
- private Resource icon;
-
/**
* The container this component resides in.
*/
* use the default documentation from implemented interface.
*/
public Resource getIcon() {
- return icon;
+ return ((ResourceReference) getState().getIcon()).getResource();
}
/**
* the icon to be shown with the component's caption.
*/
public void setIcon(Resource icon) {
- this.icon = icon;
+ if (icon == null) {
+ getState().setIcon(null);
+ } else {
+ getState().setIcon(new ResourceReference(icon));
+ }
requestRepaint();
}
// Only paint content of visible components.
if (isVisible()) {
- // width and height are only in shared state
-
- // TODO probably can remove also icon once all the VCaption
- // related code has been updated
- if (getIcon() != null) {
- target.addAttribute(
- AbstractComponentConnector.ATTRIBUTE_ICON,
- getIcon());
- }
if (eventIdentifiers != null) {
target.addAttribute("eventListeners",
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Resource;
-import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector;
import com.vaadin.terminal.gwt.client.ui.TabsheetBaseConnector;
import com.vaadin.terminal.gwt.client.ui.TabsheetConnector;
import com.vaadin.terminal.gwt.client.ui.VTabsheet;
// VCaption.updateCaption(uidl)
final Resource icon = tab.getIcon();
if (icon != null) {
- target.addAttribute(AbstractComponentConnector.ATTRIBUTE_ICON,
+ target.addAttribute(TabsheetBaseConnector.ATTRIBUTE_TAB_ICON,
icon);
}
final String caption = tab.getCaption();