import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.RenderInformation.FloatSize;
import com.vaadin.terminal.gwt.client.communication.MethodInvocation;
+import com.vaadin.terminal.gwt.client.communication.SharedState;
public class Util {
}
/**
- * Parses the UIDL parameter and fetches the relative size of the component.
- * If a dimension is not specified as relative it will return -1. If the
- * UIDL does not contain width or height specifications this will return
+ * Parses shared state and fetches the relative size of the component. If a
+ * dimension is not specified as relative it will return -1. If the shared
+ * state does not contain width or height specifications this will return
* null.
*
- * @param uidl
+ * @param state
* @return
*/
- public static FloatSize parseRelativeSize(UIDL uidl) {
+ public static FloatSize parseRelativeSize(SharedState state) {
+ if (null == state) {
+ return null;
+ }
+
boolean hasAttribute = false;
String w = "";
String h = "";
- if (uidl.hasAttribute("width")) {
+ Map<String, Object> stateMap = state.getState();
+ if (stateMap.containsKey("width")) {
hasAttribute = true;
- w = uidl.getStringAttribute("width");
+ w = String.valueOf(stateMap.get("width"));
}
- if (uidl.hasAttribute("height")) {
+ if (stateMap.containsKey("height")) {
hasAttribute = true;
- h = uidl.getStringAttribute("height");
+ h = String.valueOf(stateMap.get("height"));
}
if (!hasAttribute) {
}
Set<String> keySet = u.getKeySet();
for (String key : keySet) {
- if (key.equals("changes")) {
+ if (key.equals("state")) {
+ // TODO print updated shared states
+ } else if (key.equals("changes")) {
JsArray<UIDL> jsValueMapArray = u.getJSValueMapArray("changes")
.cast();
for (int i = 0; i < jsValueMapArray.length(); i++) {
return;
}
+ if (!isRealUpdate(uidl)) {
+ return;
+ }
+
/*
* Disabled state may affect (override) tabindex so the order must be
* first setting tabindex, then enabled state.
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VTooltip;
// Set attributes
Style style = el.getStyle();
- String w = uidl.getStringAttribute("width");
- if (w != null) {
- style.setProperty("width", w);
- } else {
- style.setProperty("width", "");
- }
- String h = uidl.getStringAttribute("height");
- if (h != null) {
- style.setProperty("height", h);
- } else {
- style.setProperty("height", "");
+ String w = "";
+ String h = "";
+ if (null != getState()) {
+ if (getState().getState().containsKey(
+ ComponentState.STATE_WIDTH)) {
+ w = String.valueOf(getState().getState().get(
+ ComponentState.STATE_WIDTH));
+ }
+ if (getState().getState().containsKey(
+ ComponentState.STATE_HEIGHT)) {
+ h = String.valueOf(getState().getState().get(
+ ComponentState.STATE_HEIGHT));
+ }
}
+ style.setProperty("width", w);
+ style.setProperty("height", h);
+
DOM.setElementProperty(el, "src", getWidgetForPaintable()
.getSrc(uidl, client));
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
+import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.client.ui.layout.CellBasedLayout;
import com.vaadin.terminal.gwt.client.ui.layout.ChildComponentContainer;
}
}
childUidl = c;
- updateRelSizeStatus(c);
+ updateRelSizeStatus(client.getPaintable(c).getState(),
+ c.getBooleanAttribute("cached"));
}
- protected void updateRelSizeStatus(UIDL uidl) {
- if (uidl != null && !uidl.getBooleanAttribute("cached")) {
- if (uidl.hasAttribute("height")
- && uidl.getStringAttribute("height").contains("%")) {
+ protected void updateRelSizeStatus(SharedState state, boolean cached) {
+ if (state != null && !cached) {
+ boolean widthDefined = state.getState().containsKey("width");
+ boolean heightDefined = state.getState().containsKey("height");
+ if (heightDefined
+ && String.valueOf(state.getState().get("height"))
+ .contains("%")) {
relHeight = true;
} else {
relHeight = false;
}
- if (uidl.hasAttribute("width")) {
- widthCanAffectHeight = relWidth = uidl.getStringAttribute(
- "width").contains("%");
- if (uidl.hasAttribute("height")) {
+ if (widthDefined) {
+ widthCanAffectHeight = relWidth = String.valueOf(
+ state.getState().get("width")).contains("%");
+ if (heightDefined) {
widthCanAffectHeight = false;
}
} else {
- widthCanAffectHeight = !uidl.hasAttribute("height");
+ widthCanAffectHeight = !heightDefined;
relWidth = false;
}
}
}
if (!getWidgetForPaintable().rendering) {
// ensure rel size details are updated
+ boolean cached = uidl.getBooleanAttribute("cached");
getWidgetForPaintable().widgetToCell.get(widget)
- .updateRelSizeStatus(uidl);
+ .updateRelSizeStatus(paintable.getState(), cached);
/*
* This was a component-only update and the possible size change
* must be propagated to the layout
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.ui.VMenuBar.CustomMenuItem;
UIDL options = uidl.getChildUIDL(0);
- if (uidl.hasAttribute("width")) {
+ if (null != getState()
+ && getState().getState()
+ .containsKey(ComponentState.STATE_WIDTH)) {
UIDL moreItemUIDL = options.getChildUIDL(0);
StringBuffer itemHTML = new StringBuffer();
* the layout are rendered later when it is clear how much space
* they can use
*/
- if (isRealUpdate(childUIDL)) {
- FloatSize relativeSize = Util.parseRelativeSize(childUIDL);
+ if (null != childPaintable.getState()) {
+ FloatSize relativeSize = Util.parseRelativeSize(childPaintable
+ .getState());
childComponentContainer.setRelativeSize(relativeSize);
}
*/
package com.vaadin.terminal.gwt.client.ui;
+import java.util.Map;
+
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.DomEvent.Type;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
getWidgetForPaintable().layout = lo;
}
- getWidgetForPaintable().dynamicWidth = !uidl.hasAttribute("width");
- getWidgetForPaintable().dynamicHeight = !uidl.hasAttribute("height");
+ if (null != getState()) {
+ Map<String, Object> state = getState().getState();
+ getWidgetForPaintable().dynamicWidth = !state
+ .containsKey(ComponentState.STATE_WIDTH);
+ getWidgetForPaintable().dynamicHeight = !state
+ .containsKey(ComponentState.STATE_HEIGHT);
+ } else {
+ getWidgetForPaintable().dynamicWidth = true;
+ getWidgetForPaintable().dynamicHeight = true;
+ }
getWidgetForPaintable().layoutRelativeWidth = uidl
.hasAttribute("layoutRelativeWidth");
package com.vaadin.terminal.gwt.client.ui.layout;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.ComponentState;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidgetContainer;
import com.vaadin.terminal.gwt.client.ui.VMarginInfo;
super.updateFromUIDL(uidl, client);
if (isRealUpdate(uidl)) {
- handleDynamicDimensions(uidl);
+ handleDynamicDimensions();
}
}
- private void handleDynamicDimensions(UIDL uidl) {
- String w = uidl.hasAttribute("width") ? uidl
- .getStringAttribute("width") : "";
-
- String h = uidl.hasAttribute("height") ? uidl
- .getStringAttribute("height") : "";
+ private void handleDynamicDimensions() {
+ String w = "";
+ String h = "";
+ if (null != getState()) {
+ if (getState().getState().containsKey(ComponentState.STATE_WIDTH)) {
+ w = String.valueOf(getState().getState().get(
+ ComponentState.STATE_WIDTH));
+ }
+ if (getState().getState().containsKey(ComponentState.STATE_HEIGHT)) {
+ h = String.valueOf(getState().getState().get(
+ ComponentState.STATE_HEIGHT));
+ }
+ }
if (w.equals("")) {
getWidgetForPaintable().dynamicWidth = true;
}
updateCaptionSize();
-
- if (relativeSize == null) {
- /*
- * relativeSize may be null if component is updated via independent
- * update, after it has initially been hidden. See #4608
- *
- * It might also change in which case there would be similar issues.
- *
- * Yes, it is an ugly hack. Don't come telling me about it.
- */
- setRelativeSize(Util.parseRelativeSize(uidl));
- }
}
public void updateCaptionSize() {
// Only paint content of visible components.
if (isVisible()) {
- if (getHeight() >= 0
- && (getHeightUnits() != Unit.PERCENTAGE || ComponentSizeValidator
- .parentCanDefineHeight(this))) {
- target.addAttribute("height", "" + getCSSHeight());
- }
+ // width and height are only in shared state
- if (getWidth() >= 0
- && (getWidthUnits() != Unit.PERCENTAGE || ComponentSizeValidator
- .parentCanDefineWidth(this))) {
- target.addAttribute("width", "" + getCSSWidth());
- }
if (styles != null && styles.size() > 0) {
target.addAttribute("style", getStyle());
}
state.put(ComponentState.STATE_WIDTH, "" + getCSSWidth());
}
+ // TODO use the rest on the client side
+
if (styles != null && styles.size() > 0) {
state.put(ComponentState.STATE_STYLE, getStyle());
}