JSONArray stateDataAndType = new JSONArray(
states.getJavaScriptObject(paintableId));
- Object state = JsonDecoder.deserialize(
+ Object state = JsonDecoder.convertValue(
stateDataAndType, paintableMap);
paintable.setState((SharedState) state);
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.ComponentState_Serializer;
import com.vaadin.terminal.gwt.client.VPaintable;
import com.vaadin.terminal.gwt.client.VPaintableMap;
* @since 7.0
*/
public class JsonDecoder {
+ private static SerializerMap serializerMap = GWT
+ .create(SerializerMap.class);
+
/**
* Convert a JSON array with two elements (type and value) into a
* client-side type, recursively if necessary.
*
- * @param value
+ * @param jsonArray
* JSON array with two elements
* @param idMapper
* mapper between paintable ID and {@link VPaintable} objects
* @return converted value (does not contain JSON types)
*/
- public static Object convertValue(JSONArray value, VPaintableMap idMapper) {
- return convertValue(((JSONString) value.get(0)).stringValue(),
- value.get(1), idMapper);
+ public static Object convertValue(JSONArray jsonArray,
+ VPaintableMap idMapper) {
+ String type = ((JSONString) jsonArray.get(0)).stringValue();
+ return convertValue(type, jsonArray.get(1), idMapper);
}
private static Object convertValue(String variableType, Object value,
val = idMapper.getPaintable(String.valueOf(value));
} else {
// object, class name as type
- VaadinSerializer serializer = getSerializer(variableType);
+ VaadinSerializer serializer = serializerMap
+ .getSerializer(variableType);
Object object = serializer
.deserialize((JSONObject) value, idMapper);
return object;
return val;
}
- public static Map<String, Object> convertMap(JSONObject jsonMap,
+ private static Map<String, Object> convertMap(JSONObject jsonMap,
VPaintableMap idMapper) {
HashMap<String, Object> map = new HashMap<String, Object>();
Iterator<String> it = jsonMap.keySet().iterator();
return tokens.toArray(new Object[tokens.size()]);
}
- public static Object deserialize(JSONArray jsonArray, VPaintableMap idMapper) {
- // jsonArray always contains two items
- // 1. type (String)
- // 2. data (Serialized)
- String type = ((JSONString) jsonArray.get(0)).stringValue();
- VaadinSerializer serializer = getSerializer(type);
- Object object = serializer.deserialize((JSONObject) jsonArray.get(1),
- idMapper);
- return object;
- }
-
- private static VaadinSerializer getSerializer(String type) {
- // TODO This should be in a separate class and constructed by a
- // generator
- return GWT.create(ComponentState_Serializer.class);
- }
}
--- /dev/null
+package com.vaadin.terminal.gwt.client.communication;\r
+\r
+public interface SerializerMap {\r
+\r
+ public VaadinSerializer getSerializer(String type);\r
+\r
+}\r
--- /dev/null
+package com.vaadin.terminal.gwt.client.communication;\r
+\r
+import com.google.gwt.core.client.GWT;\r
+import com.vaadin.terminal.gwt.client.ComponentState_Serializer;\r
+import com.vaadin.terminal.gwt.client.ui.VButtonState_Serializer;\r
+\r
+public class SerializerMapImpl implements SerializerMap {\r
+\r
+ public VaadinSerializer getSerializer(String type) {\r
+ // TODO This should be in a separate class and constructed by a\r
+ // generator\r
+ if (type.equals("com.vaadin.terminal.gwt.client.ui.VButtonState")) {\r
+ return GWT.create(VButtonState_Serializer.class);\r
+ }\r
+\r
+ return GWT.create(ComponentState_Serializer.class);\r
+ }\r
+\r
+}\r
public void disableOnClick();
}
- public static final String ATTR_DISABLE_ON_CLICK = "dc";
-
// mouse movement is checked before synthesizing click event on mouseout
protected static int MOVE_THRESHOLD = 3;
protected int mousedownX = 0;
getWidgetForPaintable().setText(
uidl.getStringAttribute(ATTRIBUTE_CAPTION));
- getWidgetForPaintable().disableOnClick = uidl
- .hasAttribute(VButton.ATTR_DISABLE_ON_CLICK);
+ getWidgetForPaintable().disableOnClick = getState().isDisableOnClick();
// handle error
if (uidl.hasAttribute("error")) {
}
}
- if (uidl.hasAttribute("keycode")) {
- getWidgetForPaintable().clickShortcut = uidl
- .getIntAttribute("keycode");
- }
+ getWidgetForPaintable().clickShortcut = getState()
+ .getClickShortcutKeyCode();
}
@Override
public VButton getWidgetForPaintable() {
return (VButton) super.getWidgetForPaintable();
}
+
+ @Override
+ public VButtonState getState() {
+ return (VButtonState) super.getState();
+ }
}
\r
public class VButtonState extends ComponentState {\r
private boolean disableOnClick = false;\r
+ private int clickShortcutKeyCode = 0;\r
\r
public boolean isDisableOnClick() {\r
return disableOnClick;\r
this.disableOnClick = disableOnClick;\r
}\r
\r
+ public int getClickShortcutKeyCode() {\r
+ return clickShortcutKeyCode;\r
+ }\r
+\r
+ public void setClickShortcutKeyCode(int clickShortcutKeyCode) {\r
+ this.clickShortcutKeyCode = clickShortcutKeyCode;\r
+ }\r
+\r
}\r
state.setDisableOnClick((Boolean) JsonDecoder.convertValue(\r
jsonDisableOnClick, idMapper));\r
\r
+ JSONArray jsonClickShortcutKeyCode = (JSONArray) jsonValue\r
+ .get("clickShortcutKeyCode");\r
+ state.setClickShortcutKeyCode((Integer) JsonDecoder.convertValue(\r
+ jsonClickShortcutKeyCode, idMapper));\r
+\r
return state;\r
}\r
}\r
return;
}
- getWidgetForPaintable().disableOnClick = uidl
- .hasAttribute(VButton.ATTR_DISABLE_ON_CLICK);
-
+ getWidgetForPaintable().disableOnClick = getState().isDisableOnClick();
getWidgetForPaintable().focusHandlerRegistration = EventHelper
.updateFocusHandler(this, client,
getWidgetForPaintable().focusHandlerRegistration);
public VNativeButton getWidgetForPaintable() {
return (VNativeButton) super.getWidgetForPaintable();
}
+
+ @Override
+ public VButtonState getState() {
+ return (VButtonState) super.getState();
+ }
}
\ No newline at end of file
}
/**
- * Encode a value to a JSON representation for transport from the client to
- * the server.
+ * Encode a value to a JSON representation for transport from the server to
+ * the client.
*
* @param value
* value to convert
return combineTypeAndValue(JsonEncoder.VTYPE_STRING, value);
} else if (value instanceof Boolean) {
return combineTypeAndValue(JsonEncoder.VTYPE_BOOLEAN, value);
+ } else if (value instanceof Number) {
+ return combineTypeAndValue(getTransportType(value), value);
} else if (value instanceof Object[]) {
Object[] array = (Object[]) value;
JSONArray jsonArray = encodeArrayContents(array, idMapper);
package com.vaadin.ui;
-import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Map;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.event.ShortcutListener;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
-import com.vaadin.terminal.gwt.client.ui.VButton;
import com.vaadin.terminal.gwt.client.ui.VButton.ButtonClientToServerRpc;
import com.vaadin.terminal.gwt.client.ui.VButtonPaintable;
import com.vaadin.terminal.gwt.client.ui.VButtonState;
addListener(listener);
}
- /**
- * Paints the content of this component.
- *
- * @param event
- * the PaintEvent.
- * @throws IOException
- * if the writing failed due to input/output error.
- * @throws PaintException
- * if the paint operation failed.
- */
- @Override
- public void paintContent(PaintTarget target) throws PaintException {
- super.paintContent(target);
-
- if (isDisableOnClick()) {
- target.addAttribute(VButton.ATTR_DISABLE_ON_CLICK, true);
- }
- if (clickShortcut != null) {
- target.addAttribute("keycode", clickShortcut.getKeyCode());
- }
- }
-
/**
* Invoked when the value of a variable has changed. Button listeners are
* notified if the button is clicked.
}
clickShortcut = new ClickShortcut(this, keyCode, modifiers);
addShortcutListener(clickShortcut);
+ getState().setClickShortcutKeyCode(clickShortcut.getKeyCode());
}
/**
if (clickShortcut != null) {
removeShortcutListener(clickShortcut);
clickShortcut = null;
+ getState().setClickShortcutKeyCode(0);
}
}