]> source.dussan.org Git - vaadin-framework.git/commitdiff
Communicate caption of components in shared state (#8304).
authorHenri Sara <hesara@vaadin.com>
Thu, 23 Feb 2012 12:23:02 +0000 (14:23 +0200)
committerHenri Sara <hesara@vaadin.com>
Thu, 23 Feb 2012 12:24:02 +0000 (14:24 +0200)
25 files changed:
src/com/vaadin/terminal/gwt/client/ComponentState.java
src/com/vaadin/terminal/gwt/client/VCaption.java
src/com/vaadin/terminal/gwt/client/communication/JsonDecoder.java
src/com/vaadin/terminal/gwt/client/ui/VAbsoluteLayout.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VAccordion.java
src/com/vaadin/terminal/gwt/client/ui/VButtonPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VCheckBoxPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VCssLayout.java
src/com/vaadin/terminal/gwt/client/ui/VCustomLayout.java
src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
src/com/vaadin/terminal/gwt/client/ui/VFormPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VLinkPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VNativeButtonPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VNotification.java
src/com/vaadin/terminal/gwt/client/ui/VPanelPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VPopupViewPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheetBasePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VWindowPaintable.java
src/com/vaadin/terminal/gwt/client/ui/layout/ChildComponentContainer.java
src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/TabSheet.java

index 5f3d0f1673bab81fdb7d5445f3c99b171fa113dc..4cf7c7fe139203493c0614460577b5d36cb8bd21 100644 (file)
@@ -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;
+    }
+
 }
index cb62ddbb26b6f791c2d317ea20b7bddd5efc22f6..6e2c4a02d24411e30ad4c21e78972643412e64c3 100644 (file)
@@ -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("&nbsp;");
+                }
+            } 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, "&nbsp;");
+                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;
index 4d28283caede1beac50297690dad70bae3c09feb..bc46104c66a4a9075a89873015b242d8c7974752 100644 (file)
@@ -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);
index 7ac44bc4b7931af875c7bf3e4a12fb94ad3611bb..663c309321c8cf88250eb28eaa37c93087dc2f3e 100644 (file)
@@ -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);
index a0cd878f74d949d5835c7e1c6600607e300e9976..fb6f785ed088cc1b996075222cf01c5536222a12 100644 (file)
@@ -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";
index 6d93e6d6cce538a102d4958bb3b38db1a307ef3a..1d536c83ee7bf6ce89b789dedcb512f9ecf1c9e4 100644 (file)
@@ -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));
         }
index 940e115cfd133422fb4278d06ccae6cc908620a9..8b09ac6285c0bc2f80a598925624e9a07b782daf 100644 (file)
@@ -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();
 
index 9624ddd4e632533795943e15a082eda10a19fb43..62293237f792c22946a6bf57fa9f56dedaf08d39 100644 (file)
@@ -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));
index 839b84061c605b6524e0c51c51c19860b7aa6faf..2d613ee8080e9599777e3bb969b9f012cace70d5 100644 (file)
@@ -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);
index 4aa838b6606c4031ad7904e89fc23760e38a679e..0300064dd2d4d8a25eb46a23c3f6a783c0b0b188 100644 (file)
@@ -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);
index 1afdb4091b7f430a17c071ea4135c63e5d82b64a..f54c6dc05ddfe92047fd334f86b41e2a0cc42a1b 100644 (file)
@@ -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 {
index daf7487ad3e1949bc94a60a55ba7c13dd016ea75..727febc6d5411b16f462b026d9b1dedf26b4cf26 100644 (file)
@@ -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("");
index 37f55db621b56aa6293b2bb67b557aff40eec741..c55b5cbe818f9ac167556e4ab0fcd50d06ff8cf5 100644 (file)
@@ -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")) {
index a2aa9695de17a4c0c38b001ccb5015bac497521a..b3e8cda8327e192fae331d455b6f86f470ff62b4 100644 (file)
@@ -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
+}
index 8f8bdb09f6f7e579c136910e962d1dda14ded3e3..124c9a51c7074386472d16251b49da033c26a6da 100644 (file)
@@ -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";
index 24e3c32c245df6e8643d1202eec47b410849ebea..a9b181da836612f828925e0b3bc3db0bdf14d4e1 100644 (file)
@@ -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("");
index 7b76b78786c5137d68157d271897465b3c0e0685..eeb2d49c6c2720a04c0a7a980eb64d9ec8193011 100644 (file)
@@ -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);
index cfb1b2f0c1ae66d01a1094f785fca8ee278933d1..97eaca8b53d9f71cc0f79e0572e9c9fd838e5a31 100644 (file)
@@ -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));
 
index dc48ee56af860107a7357a9eea22b1e74cf66675..0d7b5205f266fce9ebb9193c3fdbfa826c639258 100644 (file)
@@ -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) {
index ba203accc44ae0d3435337790b1463ff54cdc3e3..b4814eb409fa5e9c7b804256e5f25c247f9b45da 100644 (file)
@@ -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
index a994d1dc5044abac870d196bf62a302510ba9458..c8403b429a40e31e8995f5d767c00cb5da2801be 100644 (file)
@@ -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
index 3e060996bfdcde6cefcb8328fd6c915b2a14e826..d5758ea5a541e4ed91891caaeddcb3b203cb04a7 100644 (file)
@@ -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));
         }
 
index 3cba88b30d7a5789ae7a3755230ad211b17fbd4b..6568bfcf972384913bf2dfcdf3d52b5b6688e26d 100644 (file)
@@ -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;
index f68c928f8b51f6546fbec57c7fd6048ea0bf6a68..533546c5575fd1ead5c16301178110214b1216ca 100644 (file)
@@ -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;
index de95d13318263d562fa84f48e147a096efd06fca..d150f9bee4efffe91fb27cf6a074d071fa70982f 100644 (file)
@@ -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();