From: Henri Sara Date: Thu, 23 Feb 2012 12:23:02 +0000 (+0200) Subject: Communicate caption of components in shared state (#8304). X-Git-Tag: 7.0.0.alpha2~440^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6c0662316c0cfd30b40bcde3588921dad4e4a58a;p=vaadin-framework.git Communicate caption of components in shared state (#8304). --- diff --git a/src/com/vaadin/terminal/gwt/client/ComponentState.java b/src/com/vaadin/terminal/gwt/client/ComponentState.java index 5f3d0f1673..4cf7c7fe13 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentState.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentState.java @@ -21,8 +21,9 @@ public class ComponentState extends SharedState { private String style = ""; private boolean disabled = false; private String description = ""; - - // TODO more fields to move here: caption + // Note: for the caption, there is a difference between null and an empty + // string! + private String caption = null; /** * Returns the component height as set by the server. @@ -236,4 +237,31 @@ public class ComponentState extends SharedState { return !"".equals(getDescription()); } + /** + * Gets the caption of the component (typically shown by the containing + * layout). + * + * @see com.vaadin.ui.Component#getCaption() + * + * @return component caption - can be null (no caption) or empty string + * (reserve space for an empty caption) + */ + public String getCaption() { + return caption; + } + + /** + * Sets the caption of the component (typically shown by the containing + * layout). + * + * @see com.vaadin.ui.Component#setCaption(String) + * + * @param caption + * new component caption - can be null (no caption) or empty + * string (reserve space for an empty caption) + */ + public void setCaption(String caption) { + this.caption = caption; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/VCaption.java b/src/com/vaadin/terminal/gwt/client/VCaption.java index cb62ddbb26..6e2c4a02d2 100644 --- a/src/com/vaadin/terminal/gwt/client/VCaption.java +++ b/src/com/vaadin/terminal/gwt/client/VCaption.java @@ -10,6 +10,7 @@ import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.HTML; import com.vaadin.terminal.gwt.client.ui.Icon; import com.vaadin.terminal.gwt.client.ui.VAbstractPaintableWidget; +import com.vaadin.terminal.gwt.client.ui.VTabsheetBasePaintable; public class VCaption extends HTML { @@ -35,6 +36,10 @@ public class VCaption extends HTML { private static final String CLASSNAME_CLEAR = CLASSNAME + "-clearelem"; + private enum InsertPosition { + ICON, CAPTION, REQUIRED, ERROR + } + /** * Creates a caption that is not linked to a {@link VPaintableWidget}. * @@ -81,6 +86,9 @@ public class VCaption extends HTML { /** * Updates the caption from UIDL. * + * This method may only be called when the caption has an owner - otherwise, + * use {@link #updateCaptionWithoutOwner(UIDL, String, boolean, boolean)}. + * * @param uidl * @return true if the position where the caption should be placed has * changed @@ -94,25 +102,20 @@ public class VCaption extends HTML { // moves it above. placedAfterComponent = true; - // TODO otherwise, the user should also call updateCaptionWithoutOwner() - if (null != owner) { - String style = CLASSNAME; - if (owner.getState().hasStyles()) { - final String[] styles = owner.getState().getStyle().split(" "); - for (int i = 0; i < styles.length; i++) { - style += " " + CLASSNAME + "-" + styles[i]; - } + String style = CLASSNAME; + if (owner.getState().hasStyles()) { + final String[] styles = owner.getState().getStyle().split(" "); + for (int i = 0; i < styles.length; i++) { + style += " " + CLASSNAME + "-" + styles[i]; } - if (owner.getState().isDisabled()) { - style += " " + ApplicationConnection.DISABLED_CLASSNAME; - } - setStyleName(style); } + if (owner.getState().isDisabled()) { + style += " " + ApplicationConnection.DISABLED_CLASSNAME; + } + setStyleName(style); boolean hasIcon = uidl .hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON); - boolean hasText = uidl - .hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION); boolean showRequired = uidl .getBooleanAttribute(VAbstractPaintableWidget.ATTRIBUTE_REQUIRED); boolean showError = uidl @@ -125,10 +128,8 @@ public class VCaption extends HTML { icon.setWidth("0"); icon.setHeight("0"); - DOM.insertChild( - getElement(), - icon.getElement(), - getInsertPosition(VAbstractPaintableWidget.ATTRIBUTE_ICON)); + DOM.insertChild(getElement(), icon.getElement(), + getInsertPosition(InsertPosition.ICON)); } // Icon forces the caption to be above the component placedAfterComponent = false; @@ -142,7 +143,7 @@ public class VCaption extends HTML { icon = null; } - if (hasText) { + if (owner.getState().getCaption() != null) { // A caption text should be shown if the attribute is set // If the caption is null the ATTRIBUTE_CAPTION should not be set to // avoid ending up here. @@ -151,15 +152,12 @@ public class VCaption extends HTML { captionText = DOM.createDiv(); captionText.setClassName("v-captiontext"); - DOM.insertChild( - getElement(), - captionText, - getInsertPosition(VAbstractPaintableWidget.ATTRIBUTE_CAPTION)); + DOM.insertChild(getElement(), captionText, + getInsertPosition(InsertPosition.CAPTION)); } // Update caption text - String c = uidl - .getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION); + String c = owner.getState().getCaption(); // A text forces the caption to be above the component. placedAfterComponent = false; if (c == null || c.trim().equals("")) { @@ -182,12 +180,10 @@ public class VCaption extends HTML { captionText = null; } - if (null != owner) { - if (owner.getState().hasDescription() && captionText != null) { - addStyleDependentName("hasdescription"); - } else { - removeStyleDependentName("hasdescription"); - } + if (owner.getState().hasDescription() && captionText != null) { + addStyleDependentName("hasdescription"); + } else { + removeStyleDependentName("hasdescription"); } if (showRequired) { @@ -197,10 +193,8 @@ public class VCaption extends HTML { .setClassName("v-required-field-indicator"); DOM.setInnerText(requiredFieldIndicator, "*"); - DOM.insertChild( - getElement(), - requiredFieldIndicator, - getInsertPosition(VAbstractPaintableWidget.ATTRIBUTE_REQUIRED)); + DOM.insertChild(getElement(), requiredFieldIndicator, + getInsertPosition(InsertPosition.REQUIRED)); } } else if (requiredFieldIndicator != null) { // Remove existing @@ -215,10 +209,8 @@ public class VCaption extends HTML { DOM.setElementProperty(errorIndicatorElement, "className", "v-errorindicator"); - DOM.insertChild( - getElement(), - errorIndicatorElement, - getInsertPosition(VAbstractPaintableWidget.ATTRIBUTE_ERROR)); + DOM.insertChild(getElement(), errorIndicatorElement, + getInsertPosition(InsertPosition.ERROR)); } } else if (errorIndicatorElement != null) { // Remove existing @@ -235,16 +227,16 @@ public class VCaption extends HTML { return (wasPlacedAfterComponent != placedAfterComponent); } - private int getInsertPosition(String element) { + private int getInsertPosition(InsertPosition element) { int pos = 0; - if (element.equals(VAbstractPaintableWidget.ATTRIBUTE_ICON)) { + if (InsertPosition.ICON.equals(element)) { return pos; } if (icon != null) { pos++; } - if (element.equals(VAbstractPaintableWidget.ATTRIBUTE_CAPTION)) { + if (InsertPosition.CAPTION.equals(element)) { return pos; } @@ -252,26 +244,33 @@ public class VCaption extends HTML { pos++; } - if (element.equals(VAbstractPaintableWidget.ATTRIBUTE_REQUIRED)) { + if (InsertPosition.REQUIRED.equals(element)) { return pos; } if (requiredFieldIndicator != null) { pos++; } - // if (element.equals(ATTRIBUTE_ERROR)) { + // if (InsertPosition.ERROR.equals(element)) { // } return pos; } @Deprecated - public void updateCaptionWithoutOwner(boolean disabled, - boolean hasDescription) { + public boolean updateCaptionWithoutOwner(UIDL uidl, String caption, + boolean disabled, boolean hasDescription) { // TODO temporary method, needed because some tabsheet and accordion - // internal captions do not have an owner or shared state. - // Remaining such cases do not use the "style" attribute - see - // Tabsheet.paintContent(). + // internal captions do not have an owner or shared state. Simplified to + // only support those cases + setVisible(!uidl.getBooleanAttribute("invisible")); + + boolean wasPlacedAfterComponent = placedAfterComponent; + + // Caption is placed after component unless there is some part which + // moves it above. + placedAfterComponent = true; + String style = VCaption.CLASSNAME; if (disabled) { style += " " + ApplicationConnection.DISABLED_CLASSNAME; @@ -284,6 +283,90 @@ public class VCaption extends HTML { removeStyleDependentName("hasdescription"); } } + boolean hasIcon = uidl + .hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON); + boolean showError = uidl + .hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_ERROR) + && !uidl.getBooleanAttribute(VAbstractPaintableWidget.ATTRIBUTE_HIDEERRORS); + + if (hasIcon) { + if (icon == null) { + icon = new Icon(client); + icon.setWidth("0"); + icon.setHeight("0"); + + DOM.insertChild(getElement(), icon.getElement(), + getInsertPosition(InsertPosition.ICON)); + } + // Icon forces the caption to be above the component + placedAfterComponent = false; + + icon.setUri(uidl + .getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON)); + + } else if (icon != null) { + // Remove existing + DOM.removeChild(getElement(), icon.getElement()); + icon = null; + } + + if (caption != null) { + // A caption text should be shown if the attribute is set + // If the caption is null the ATTRIBUTE_CAPTION should not be set to + // avoid ending up here. + + if (captionText == null) { + captionText = DOM.createDiv(); + captionText.setClassName("v-captiontext"); + + DOM.insertChild(getElement(), captionText, + getInsertPosition(InsertPosition.CAPTION)); + } + + // Update caption text + // A text forces the caption to be above the component. + placedAfterComponent = false; + if (caption.trim().equals("")) { + // This is required to ensure that the caption uses space in all + // browsers when it is set to the empty string. If there is an + // icon, error indicator or required indicator they will ensure + // that space is reserved. + if (!hasIcon && !showError) { + captionText.setInnerHTML(" "); + } + } else { + DOM.setInnerText(captionText, caption); + } + + } else if (captionText != null) { + // Remove existing + DOM.removeChild(getElement(), captionText); + captionText = null; + } + + if (showError) { + if (errorIndicatorElement == null) { + errorIndicatorElement = DOM.createDiv(); + DOM.setInnerHTML(errorIndicatorElement, " "); + DOM.setElementProperty(errorIndicatorElement, "className", + "v-errorindicator"); + + DOM.insertChild(getElement(), errorIndicatorElement, + getInsertPosition(InsertPosition.ERROR)); + } + } else if (errorIndicatorElement != null) { + // Remove existing + getElement().removeChild(errorIndicatorElement); + errorIndicatorElement = null; + } + + if (clearElement == null) { + clearElement = DOM.createDiv(); + clearElement.setClassName(CLASSNAME_CLEAR); + getElement().appendChild(clearElement); + } + + return (wasPlacedAfterComponent != placedAfterComponent); } @Override @@ -323,9 +406,17 @@ public class VCaption extends HTML { } } - public static boolean isNeeded(UIDL uidl) { - if (uidl.getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION) != null) { - return true; + public static boolean isNeeded(UIDL uidl, ComponentState state) { + if (state != null) { + if (state.getCaption() != null) { + return true; + } + } else { + // TODO fallback for cases where the caption has no owner (Tabsheet, + // Accordion) + if (uidl.getStringAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_CAPTION) != null) { + return true; + } } if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_ERROR)) { return true; diff --git a/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java b/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java index 4d28283cae..bc46104c66 100644 --- a/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java +++ b/src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java @@ -52,7 +52,9 @@ public class JsonDecoder { VPaintableMap idMapper) { Object val = null; // TODO type checks etc. - if (JsonEncoder.VTYPE_ARRAY.equals(variableType)) { + if (JsonEncoder.VTYPE_UNDEFINED.equals(variableType)) { + val = null; + } else if (JsonEncoder.VTYPE_ARRAY.equals(variableType)) { val = convertArray((JSONArray) value, idMapper); } else if (JsonEncoder.VTYPE_MAP.equals(variableType)) { val = convertMap((JSONObject) value, idMapper); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java index 7ac44bc4b7..663c309321 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java @@ -195,7 +195,8 @@ public class VAbsoluteLayout extends ComplexPanel implements Container { public void updateCaption(UIDL uidl) { - boolean captionIsNeeded = VCaption.isNeeded(uidl); + boolean captionIsNeeded = VCaption.isNeeded(uidl, + paintable.getState()); if (captionIsNeeded) { if (caption == null) { caption = new VCaption(paintable, client); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java index a0cd878f74..fb6f785ed0 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java @@ -27,7 +27,6 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget { // 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_CAPTION = "caption"; public static final String ATTRIBUTE_REQUIRED = "required"; public static final String ATTRIBUTE_ERROR = "error"; public static final String ATTRIBUTE_HIDEERRORS = "hideErrors"; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java index 6d93e6d6cc..1d536c83ee 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java @@ -490,9 +490,10 @@ public class VAccordion extends VTabsheetBase implements } public void updateCaption(UIDL uidl) { - caption.updateCaption(uidl); - // TODO required because the caption does not have an owner + // TODO need to call this because the caption does not have an owner caption.updateCaptionWithoutOwner( + uidl, + uidl.getStringAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_CAPTION), uidl.hasAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_DISABLED), uidl.hasAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_DESCRIPTION)); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java index 940e115cfd..8b09ac6285 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java @@ -41,8 +41,7 @@ public class VButtonPaintable extends VAbstractPaintableWidget { getWidgetForPaintable().paintableId = uidl.getId(); // Set text - getWidgetForPaintable().setText( - uidl.getStringAttribute(ATTRIBUTE_CAPTION)); + getWidgetForPaintable().setText(getState().getCaption()); getWidgetForPaintable().disableOnClick = getState().isDisableOnClick(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java index 9624ddd4e6..62293237f7 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java @@ -85,8 +85,7 @@ public class VCheckBoxPaintable extends VAbstractPaintableWidget { } // Set text - getWidgetForPaintable().setText( - uidl.getStringAttribute(ATTRIBUTE_CAPTION)); + getWidgetForPaintable().setText(getState().getCaption()); getWidgetForPaintable() .setValue( uidl.getBooleanVariable(getWidgetForPaintable().VARIABLE_STATE)); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java index 839b84061c..2d613ee808 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java @@ -208,7 +208,7 @@ public class VCssLayout extends SimplePanel implements Container { public void updateCaption(VPaintableWidget paintable, UIDL uidl) { Widget widget = paintable.getWidgetForPaintable(); VCaption caption = widgetToCaption.get(widget); - if (VCaption.isNeeded(uidl)) { + if (VCaption.isNeeded(uidl, paintable.getState())) { if (caption == null) { caption = new VCaption(paintable, client); widgetToCaption.put(widget, caption); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java index 4aa838b660..0300064dd2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java @@ -332,7 +332,7 @@ public class VCustomLayout extends ComplexPanel implements Container, public void updateCaption(VPaintableWidget paintable, UIDL uidl) { VCaptionWrapper wrapper = paintableToCaptionWrapper.get(paintable); Widget widget = paintable.getWidgetForPaintable(); - if (VCaption.isNeeded(uidl)) { + if (VCaption.isNeeded(uidl, paintable.getState())) { if (wrapper == null) { // Add a wrapper between the layout and the child widget final String loc = getLocation(widget); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java index 1afdb4091b..f54c6dc05d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java @@ -365,14 +365,13 @@ public class VFormLayout extends SimplePanel implements Container { } - if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION)) { + if (state.getCaption() != null) { if (captionText == null) { captionText = DOM.createSpan(); DOM.insertChild(getElement(), captionText, icon == null ? 0 : 1); } - String c = uidl - .getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION); + String c = state.getCaption(); if (c == null) { c = ""; } else { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java index daf7487ad3..727febc6d5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java @@ -31,9 +31,9 @@ public class VFormPaintable extends VAbstractPaintableWidgetContainer { } boolean legendEmpty = true; - if (uidl.hasAttribute(ATTRIBUTE_CAPTION)) { - getWidgetForPaintable().caption.setInnerText(uidl - .getStringAttribute(ATTRIBUTE_CAPTION)); + if (getState().getCaption() != null) { + getWidgetForPaintable().caption.setInnerText(getState() + .getCaption()); legendEmpty = false; } else { getWidgetForPaintable().caption.setInnerText(""); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java index 37f55db621..c55b5cbe81 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java @@ -61,8 +61,8 @@ public class VLinkPaintable extends VAbstractPaintableWidget { .getIntAttribute("targetWidth") : -1; // Set link caption - getWidgetForPaintable().captionElement.setInnerText(uidl - .getStringAttribute(ATTRIBUTE_CAPTION)); + getWidgetForPaintable().captionElement.setInnerText(getState() + .getCaption()); // handle error if (uidl.hasAttribute("error")) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java index a2aa9695de..b3e8cda832 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java @@ -41,8 +41,7 @@ public class VNativeButtonPaintable extends VAbstractPaintableWidget { getWidgetForPaintable().paintableId = uidl.getId(); // Set text - getWidgetForPaintable().setText( - uidl.getStringAttribute(ATTRIBUTE_CAPTION)); + getWidgetForPaintable().setText(getState().getCaption()); // handle error if (uidl.hasAttribute("error")) { @@ -100,4 +99,4 @@ public class VNativeButtonPaintable extends VAbstractPaintableWidget { protected ComponentState createState() { return GWT.create(ButtonState.class); } -} \ No newline at end of file +} diff --git a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java index 8f8bdb09f6..124c9a51c7 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VNotification.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VNotification.java @@ -57,7 +57,7 @@ public class VNotification extends VOverlay { private static final int TOUCH_DEVICE_IDLE_DELAY = 1000; public static final String ATTRIBUTE_NOTIFICATION_STYLE = "style"; - public static final String ATTRIBUTE_NOTIFICATION_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION; + public static final String ATTRIBUTE_NOTIFICATION_CAPTION = "caption"; public static final String ATTRIBUTE_NOTIFICATION_MESSAGE = "message"; public static final String ATTRIBUTE_NOTIFICATION_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON; public static final String ATTRIBUTE_NOTIFICATION_POSITION = "position"; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java index 24e3c32c24..a9b181da83 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java @@ -47,10 +47,9 @@ public class VPanelPaintable extends VAbstractPaintableWidgetContainer { getWidgetForPaintable().captionNode.setClassName(VPanel.CLASSNAME + "-caption"); boolean hasCaption = false; - if (uidl.hasAttribute(ATTRIBUTE_CAPTION) - && !uidl.getStringAttribute(ATTRIBUTE_CAPTION).equals("")) { - getWidgetForPaintable().setCaption( - uidl.getStringAttribute(ATTRIBUTE_CAPTION)); + if (getState().getCaption() != null + && !"".equals(getState().getCaption())) { + getWidgetForPaintable().setCaption(getState().getCaption()); hasCaption = true; } else { getWidgetForPaintable().setCaption(""); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java index 7b76b78786..eeb2d49c6c 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java @@ -80,7 +80,7 @@ public class VPopupViewPaintable extends VAbstractPaintableWidgetContainer { }// updateFromUIDL public void updateCaption(VPaintableWidget component, UIDL uidl) { - if (VCaption.isNeeded(uidl)) { + if (VCaption.isNeeded(uidl, component.getState())) { if (getWidgetForPaintable().popup.captionWrapper != null) { getWidgetForPaintable().popup.captionWrapper .updateCaption(uidl); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java index cfb1b2f0c1..97eaca8b53 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java @@ -214,10 +214,11 @@ public class VTabsheet extends VTabsheetBase { client.registerWidgetTooltip(getTabsheet(), getElement(), null); } - boolean ret = super.updateCaption(uidl); - - // TODO required because the caption does not have an owner - updateCaptionWithoutOwner( + // TODO need to call this instead of super because the caption does + // not have an owner + boolean ret = updateCaptionWithoutOwner( + uidl, + uidl.getStringAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_CAPTION), uidl.hasAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_DISABLED), uidl.hasAttribute(VTabsheetBasePaintable.ATTRIBUTE_TAB_DESCRIPTION)); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java index dc48ee56af..0d7b5205f2 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java @@ -17,6 +17,7 @@ public abstract class VTabsheetBasePaintable extends public static final String ATTRIBUTE_TAB_DISABLED = "disabled"; public static final String ATTRIBUTE_TAB_DESCRIPTION = "description"; + public static final String ATTRIBUTE_TAB_CAPTION = "caption"; @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java index ba203accc4..b4814eb409 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java @@ -15,10 +15,10 @@ import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode; public class VTreePaintable extends VAbstractPaintableWidget { public static final String ATTRIBUTE_NODE_STYLE = "style"; - public static final String ATTRIBUTE_NODE_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION; + public static final String ATTRIBUTE_NODE_CAPTION = "caption"; public static final String ATTRIBUTE_NODE_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON; - public static final String ATTRIBUTE_ACTION_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION; + public static final String ATTRIBUTE_ACTION_CAPTION = "caption"; public static final String ATTRIBUTE_ACTION_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON; @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java index a994d1dc50..c8403b429a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java @@ -61,10 +61,9 @@ public class VViewPaintable extends VAbstractPaintableWidgetContainer { clickEventHandler.handleEventHandlerRegistration(client); if (!getWidgetForPaintable().isEmbedded() - && uidl.hasAttribute(ATTRIBUTE_CAPTION)) { + && getState().getCaption() != null) { // only change window title if we're in charge of the whole page - com.google.gwt.user.client.Window.setTitle(uidl - .getStringAttribute(ATTRIBUTE_CAPTION)); + com.google.gwt.user.client.Window.setTitle(getState().getCaption()); } // Process children diff --git a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java index 3e060996bf..d5758ea5a5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java @@ -77,7 +77,7 @@ public class VWindowPaintable extends VAbstractPaintableWidgetContainer // the caption attribute is missing the caption should be cleared. getWidgetForPaintable() .setCaption( - uidl.getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_CAPTION), + getState().getCaption(), uidl.getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON)); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java b/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java index 3cba88b30d..6568bfcf97 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java +++ b/src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java @@ -403,7 +403,7 @@ public class ChildComponentContainer extends Panel { } public void updateCaption(UIDL uidl, ApplicationConnection client) { - if (VCaption.isNeeded(uidl)) { + if (VCaption.isNeeded(uidl, paintable.getState())) { // We need a caption VCaption newCaption = caption; diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index f68c928f8b..533546c557 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -771,13 +771,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource if (isVisible()) { // width and height are only in shared state - // TODO probably can remove some of these (caption, icon, ...) - // once all the VCaption related code has been updated - if (getCaption() != null) { - target.addAttribute( - VAbstractPaintableWidget.ATTRIBUTE_CAPTION, - getCaption()); - } + // TODO probably can remove also icon once all the VCaption + // related code has been updated if (getIcon() != null) { target.addAttribute( VAbstractPaintableWidget.ATTRIBUTE_ICON, getIcon()); @@ -887,9 +882,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource sharedState.setStyle(getStyleName()); + sharedState.setCaption(getCaption()); sharedState.setDescription(getDescription()); - // TODO sharedState.setCaption(getCaption()); // TODO icon also in shared state - how to convert Resource? return sharedState; diff --git a/src/com/vaadin/ui/TabSheet.java b/src/com/vaadin/ui/TabSheet.java index de95d13318..d150f9bee4 100644 --- a/src/com/vaadin/ui/TabSheet.java +++ b/src/com/vaadin/ui/TabSheet.java @@ -399,7 +399,8 @@ public class TabSheet extends AbstractComponentContainer { } final String caption = tab.getCaption(); if (caption != null && caption.length() > 0) { - target.addAttribute("caption", caption); + target.addAttribute( + VTabsheetBasePaintable.ATTRIBUTE_TAB_CAPTION, caption); } final String description = tab.getDescription();