]> source.dussan.org Git - vaadin-framework.git/commitdiff
Communicate component style names in shared state (#8304).
authorHenri Sara <hesara@vaadin.com>
Thu, 23 Feb 2012 09:21:42 +0000 (11:21 +0200)
committerHenri Sara <hesara@vaadin.com>
Thu, 23 Feb 2012 09:21:42 +0000 (11:21 +0200)
20 files changed:
src/com/vaadin/terminal/gwt/client/ComponentState.java
src/com/vaadin/terminal/gwt/client/VCaption.java
src/com/vaadin/terminal/gwt/client/VCaptionWrapper.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractPaintableWidget.java
src/com/vaadin/terminal/gwt/client/ui/VAbstractSplitPanelPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VAccordion.java
src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
src/com/vaadin/terminal/gwt/client/ui/VFilterSelectPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java
src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java
src/com/vaadin/terminal/gwt/client/ui/VMenuBarPaintable.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/VSliderPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java
src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java
src/com/vaadin/terminal/gwt/client/ui/VTreePaintable.java
src/com/vaadin/terminal/gwt/client/ui/VViewPaintable.java
src/com/vaadin/ui/AbstractComponent.java

index ac478cd1d3e79f20c01877cf34731a9d10d77f25..6006086d6a3b68868993ca1d4c2fb5641dcbc66c 100644 (file)
@@ -18,6 +18,9 @@ public class ComponentState extends SharedState {
     private String width = "";
     private boolean readOnly = false;
     private boolean immediate = false;
+    private String style = "";
+
+    // TODO more fields to move here: disabled, caption and description
 
     /**
      * Returns the component height as set by the server.
@@ -95,22 +98,82 @@ public class ComponentState extends SharedState {
         return "".equals(getWidth());
     }
 
+    /**
+     * Returns true if the component is in read-only mode.
+     * 
+     * @see Component.isReadOnly()
+     * 
+     * @return true if the component is in read-only mode
+     */
     public boolean isReadOnly() {
         return readOnly;
     }
 
+    /**
+     * Sets or resets the read-only mode for a component.
+     * 
+     * @see Component.setReadOnly()
+     * 
+     * @param readOnly
+     *            new mode for the component
+     */
     public void setReadOnly(boolean readOnly) {
         this.readOnly = readOnly;
     }
 
+    /**
+     * Returns true if the component is in immediate mode.
+     * 
+     * @see VariableOwner.isImmediate()
+     * 
+     * @return true if the component is in immediate mode
+     */
     public boolean isImmediate() {
         return immediate;
     }
 
+    /**
+     * Sets or resets the immediate mode for a component.
+     * 
+     * @see VariableOwner.setImmediate()
+     * 
+     * @param immediate
+     *            new mode for the component
+     */
     public void setImmediate(boolean immediate) {
         this.immediate = immediate;
     }
 
-    // TODO more fields to move here: style, disabled, caption and description
+    /**
+     * Returns the component styles as set by the server, as a space separated
+     * string.
+     * 
+     * @return component styles as defined by the server, not null
+     */
+    public String getStyle() {
+        if (style == null) {
+            return "";
+        }
+        return style;
+    }
+
+    /**
+     * Sets the component styles as a space separated string.
+     * 
+     * @param style
+     *            component styles as a space separated string, not null
+     */
+    public void setStyle(String style) {
+        this.style = style;
+    }
+
+    /**
+     * Returns true if the component has user-defined styles.
+     * 
+     * @return true if the component has user-defined styles
+     */
+    public boolean hasStyles() {
+        return !"".equals(getStyle());
+    }
 
 }
index 756fa71b6a4c71f904b24b48f8647991c709d15d..5a15478ba6fd41f8e074bfa29b36e5ff873e06dd 100644 (file)
@@ -36,11 +36,33 @@ public class VCaption extends HTML {
     private static final String CLASSNAME_CLEAR = CLASSNAME + "-clearelem";
 
     /**
+     * Creates a caption that is not linked to a {@link VPaintableWidget}.
+     * 
+     * When using this constructor, {@link #getOwner()} returns null.
+     * 
+     * @param client
+     *            ApplicationConnection
+     * @deprecated all captions should be associated with a paintable widget and
+     *             be updated from shared state, not UIDL
+     */
+    @Deprecated
+    public VCaption(ApplicationConnection client) {
+        super();
+        this.client = client;
+        owner = null;
+
+        setStyleName(CLASSNAME);
+        sinkEvents(VTooltip.TOOLTIP_EVENTS);
+
+    }
+
+    /**
+     * Creates a caption for a {@link VPaintableWidget}.
      * 
      * @param component
-     *            optional owner of caption. If not set, getOwner will return
-     *            null
+     *            owner of caption, not null
      * @param client
+     *            ApplicationConnection
      */
     public VCaption(VPaintableWidget component, ApplicationConnection client) {
         super();
@@ -72,21 +94,21 @@ public class VCaption extends HTML {
         // moves it above.
         placedAfterComponent = true;
 
-        String style = CLASSNAME;
-        if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
-            final String[] styles = uidl.getStringAttribute(
-                    VAbstractPaintableWidget.ATTRIBUTE_STYLE).split(" ");
-            for (int i = 0; i < styles.length; i++) {
-                style += " " + CLASSNAME + "-" + styles[i];
+        // 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];
+                }
             }
+            if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_DISABLED)) {
+                style += " " + ApplicationConnection.DISABLED_CLASSNAME;
+            }
+            setStyleName(style);
         }
 
-        if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_DISABLED)) {
-            style += " " + ApplicationConnection.DISABLED_CLASSNAME;
-        }
-
-        setStyleName(style);
-
         boolean hasIcon = uidl
                 .hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_ICON);
         boolean hasText = uidl
@@ -162,8 +184,8 @@ public class VCaption extends HTML {
             captionText = null;
         }
 
-        if (hasDescription) {
-            if (captionText != null) {
+        if (null != owner) {
+            if (hasDescription && captionText != null) {
                 addStyleDependentName("hasdescription");
             } else {
                 removeStyleDependentName("hasdescription");
@@ -245,6 +267,28 @@ public class VCaption extends HTML {
 
     }
 
+    @Deprecated
+    public void updateCaptionWithoutOwner(UIDL uidl) {
+        // 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().
+        String style = VCaption.CLASSNAME;
+        if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_DISABLED)) {
+            style += " " + ApplicationConnection.DISABLED_CLASSNAME;
+        }
+        setStyleName(style);
+        boolean hasDescription = uidl
+                .hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_DESCRIPTION);
+        if (hasDescription) {
+            if (captionText != null) {
+                addStyleDependentName("hasdescription");
+            } else {
+                removeStyleDependentName("hasdescription");
+            }
+        }
+    }
+
     @Override
     public void onBrowserEvent(Event event) {
         super.onBrowserEvent(event);
index bc1a240aa983e41a59a29e5bf535633d04d10022..90e1d65b0a62ca2f8aaf97c9cf65db6fb0d82219 100644 (file)
@@ -12,6 +12,14 @@ public class VCaptionWrapper extends FlowPanel {
     VCaption caption;
     VPaintableWidget paintable;
 
+    /**
+     * Creates a new caption wrapper panel.
+     * 
+     * @param toBeWrapped
+     *            paintable that the caption is associated with, not null
+     * @param client
+     *            ApplicationConnection
+     */
     public VCaptionWrapper(VPaintableWidget toBeWrapped,
             ApplicationConnection client) {
         caption = new VCaption(toBeWrapped, client);
index d6404b03fc323653f65f778ba7536ff1730d306f..6be193afe07044ff90259f5cdd7ebf70eb9ab568 100644 (file)
@@ -33,7 +33,6 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
     public static final String ATTRIBUTE_ERROR = "error";
     public static final String ATTRIBUTE_HIDEERRORS = "hideErrors";
     public static final String ATTRIBUTE_DISABLED = "disabled";
-    public static final String ATTRIBUTE_STYLE = "style";
 
     private Widget widget;
     private ApplicationConnection connection;
@@ -336,9 +335,8 @@ public abstract class VAbstractPaintableWidget implements VPaintableWidget {
 
         // add additional styles as css classes, prefixed with component default
         // stylename
-        if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
-            final String[] styles = uidl.getStringAttribute(ATTRIBUTE_STYLE)
-                    .split(" ");
+        if (state.hasStyles()) {
+            final String[] styles = state.getStyle().split(" ");
             for (int i = 0; i < styles.length; i++) {
                 styleBuf.append(" ");
                 styleBuf.append(primaryStyleName);
index 1e8349b4ad0118e1b228fe2da4c3268fad6f2447..a255fdbd5163ca1df641b3847d4181267317d1fc 100644 (file)
@@ -81,9 +81,9 @@ public abstract class VAbstractSplitPanelPaintable extends
                 !uidl.getBooleanAttribute(ATTRIBUTE_DISABLED));
 
         clickEventHandler.handleEventHandlerRegistration(client);
-        if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
-            getWidgetForPaintable().componentStyleNames = uidl
-                    .getStringAttribute(ATTRIBUTE_STYLE).split(" ");
+        if (getState().hasStyles()) {
+            getWidgetForPaintable().componentStyleNames = getState().getStyle()
+                    .split(" ");
         } else {
             getWidgetForPaintable().componentStyleNames = new String[0];
         }
index 3e4f21477b46df012cd5c24cf441f1a9688b5995..671f0a1c8c34c57321924c6ffc360c25f8bace10 100644 (file)
@@ -392,7 +392,7 @@ public class VAccordion extends VTabsheetBase implements
 
         public StackItem(UIDL tabUidl) {
             setElement(DOM.createDiv());
-            caption = new VCaption(null, client);
+            caption = new VCaption(client);
             caption.addClickHandler(this);
             super.add(caption, captionNode);
             DOM.appendChild(captionNode, caption.getElement());
@@ -491,6 +491,8 @@ public class VAccordion extends VTabsheetBase implements
 
         public void updateCaption(UIDL uidl) {
             caption.updateCaption(uidl);
+            // TODO required because the caption does not have an owner
+            caption.updateCaptionWithoutOwner(uidl);
         }
 
         public int getWidgetWidth() {
index f205162769ad1d357df87be20b2995eeeb6036ba..08d8a39e6eeffc93b5d15502d28cbb646af5923e 100644 (file)
@@ -44,6 +44,7 @@ import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
 import com.google.gwt.user.client.ui.TextBox;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.EventId;
 import com.vaadin.terminal.gwt.client.Focusable;
 import com.vaadin.terminal.gwt.client.UIDL;
@@ -539,13 +540,17 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler,
 
         /**
          * Updates style names in suggestion popup to help theme building.
+         * 
+         * @param uidl
+         *            UIDL for the whole combo box
+         * @param componentState
+         *            shared state of the combo box
          */
-        public void updateStyleNames(UIDL uidl) {
-            if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
-                setStyleName(CLASSNAME + "-suggestpopup");
-                final String[] styles = uidl.getStringAttribute(
-                        VAbstractPaintableWidget.ATTRIBUTE_STYLE).split(" ");
-                for (int i = 0; i < styles.length; i++) {
+        public void updateStyleNames(UIDL uidl, ComponentState componentState) {
+            setStyleName(CLASSNAME + "-suggestpopup");
+            final String[] styles = componentState.getStyle().split(" ");
+            for (int i = 0; i < styles.length; i++) {
+                if (!"".equals(styles[i])) {
                     addStyleDependentName(styles[i]);
                 }
             }
index 581baad8f9cf427258f754e274e8eaea0b6bd103..67f380a03f75f0571a185e7a11699b497141bd83 100644 (file)
@@ -82,7 +82,8 @@ public class VFilterSelectPaintable extends VAbstractPaintableWidget {
             getWidgetForPaintable().inputPrompt = "";
         }
 
-        getWidgetForPaintable().suggestionPopup.updateStyleNames(uidl);
+        getWidgetForPaintable().suggestionPopup.updateStyleNames(uidl,
+                getState());
 
         getWidgetForPaintable().allowNewItem = uidl
                 .hasAttribute("allownewitem");
index 3e5600e4e6836a691eb8f986e9faf22a821b83fe..440c45f90f98e255d19ebd8ab703d5da58d9e710 100644 (file)
@@ -21,6 +21,7 @@ import com.google.gwt.user.client.ui.SimplePanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.Container;
 import com.vaadin.terminal.gwt.client.Focusable;
 import com.vaadin.terminal.gwt.client.RenderSpace;
@@ -58,13 +59,14 @@ public class VFormLayout extends SimplePanel implements Container {
      * 
      * @param uidl
      *            The uidl to get the stylenames from
+     * @param state
+     *            shared state of the component
      * @return An array of stylenames
      */
-    private String[] getStylesFromUIDL(UIDL uidl) {
+    private String[] getStylesFromUIDL(UIDL uidl, ComponentState state) {
         List<String> styles = new ArrayList<String>();
-        if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
-            String[] stylesnames = uidl.getStringAttribute(
-                    VAbstractPaintableWidget.ATTRIBUTE_STYLE).split(" ");
+        if (state.hasStyles()) {
+            String[] stylesnames = state.getStyle().split(" ");
             for (String name : stylesnames) {
                 styles.add(name);
             }
@@ -235,7 +237,7 @@ public class VFormLayout extends SimplePanel implements Container {
             final Caption c = widgetToCaption.get(paintable
                     .getWidgetForPaintable());
             if (c != null) {
-                c.updateCaption(uidl);
+                c.updateCaption(uidl, paintable.getState());
             }
             final ErrorFlag e = widgetToError.get(paintable
                     .getWidgetForPaintable());
@@ -339,11 +341,11 @@ public class VFormLayout extends SimplePanel implements Container {
             setStyleName(styleName);
         }
 
-        public void updateCaption(UIDL uidl) {
+        public void updateCaption(UIDL uidl, ComponentState state) {
             setVisible(!uidl.getBooleanAttribute("invisible"));
 
             // Update styles as they might have changed when the caption changed
-            setStyles(getStylesFromUIDL(uidl));
+            setStyles(getStylesFromUIDL(uidl, state));
 
             boolean isEmpty = true;
 
index a6bc1f2c4e2ba758aad183a9683d2ad9b38a4a89..0d559b07c4aea46c997ef5b9db87c08bb9b44148 100644 (file)
@@ -68,7 +68,7 @@ public class VMenuBar extends SimpleFocusablePanel implements
     public static final String ATTRIBUTE_ITEM_DESCRIPTION = VAbstractPaintableWidget.ATTRIBUTE_DESCRIPTION;
     public static final String ATTRIBUTE_ITEM_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
     public static final String ATTRIBUTE_ITEM_DISABLED = VAbstractPaintableWidget.ATTRIBUTE_DISABLED;
-    public static final String ATTRIBUTE_ITEM_STYLE = VAbstractPaintableWidget.ATTRIBUTE_STYLE;
+    public static final String ATTRIBUTE_ITEM_STYLE = "style";
 
     public static final String HTML_CONTENT_ALLOWED = "usehtml";
 
index ee86ef4e5254e7e56a409370e3d18995f9abe296..83e60a03f55e0b0cf3cfb659e5983c4639c4f892 100644 (file)
@@ -124,10 +124,8 @@ public class VMenuBarPaintable extends VAbstractPaintableWidget {
                 // this is the top-level style that also propagates to items -
                 // any item specific styles are set above in
                 // currentItem.updateFromUIDL(item, client)
-                if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
-                    for (String style : uidl.getStringAttribute(
-                            VAbstractPaintableWidget.ATTRIBUTE_STYLE)
-                            .split(" ")) {
+                if (getState().hasStyles()) {
+                    for (String style : getState().getStyle().split(" ")) {
                         currentMenu.addStyleDependentName(style);
                     }
                 }
index 1276c1612cbf7a3f04d961571cf139efb62002b7..8f8bdb09f6f7e579c136910e962d1dda14ded3e3 100644 (file)
@@ -56,7 +56,7 @@ public class VNotification extends VOverlay {
     private ArrayList<EventListener> listeners;
     private static final int TOUCH_DEVICE_IDLE_DELAY = 1000;
 
-    public static final String ATTRIBUTE_NOTIFICATION_STYLE = VAbstractPaintableWidget.ATTRIBUTE_STYLE;
+    public static final String ATTRIBUTE_NOTIFICATION_STYLE = "style";
     public static final String ATTRIBUTE_NOTIFICATION_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION;
     public static final String ATTRIBUTE_NOTIFICATION_MESSAGE = "message";
     public static final String ATTRIBUTE_NOTIFICATION_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
index ce1c1f24820d99160755f0cce3c2aac3b70ead52..24e3c32c245df6e8643d1202eec47b410849ebea 100644 (file)
@@ -60,27 +60,24 @@ public class VPanelPaintable extends VAbstractPaintableWidgetContainer {
 
             // Add proper stylenames for all elements. This way we can prevent
             // unwanted CSS selector inheritance.
-            if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
-                final String[] styles = uidl
-                        .getStringAttribute(ATTRIBUTE_STYLE).split(" ");
-                final String captionBaseClass = VPanel.CLASSNAME
-                        + (hasCaption ? "-caption" : "-nocaption");
-                final String contentBaseClass = VPanel.CLASSNAME + "-content";
-                final String decoBaseClass = VPanel.CLASSNAME + "-deco";
-                String captionClass = captionBaseClass;
-                String contentClass = contentBaseClass;
-                String decoClass = decoBaseClass;
+            final String captionBaseClass = VPanel.CLASSNAME
+                    + (hasCaption ? "-caption" : "-nocaption");
+            final String contentBaseClass = VPanel.CLASSNAME + "-content";
+            final String decoBaseClass = VPanel.CLASSNAME + "-deco";
+            String captionClass = captionBaseClass;
+            String contentClass = contentBaseClass;
+            String decoClass = decoBaseClass;
+            if (getState().hasStyles()) {
+                final String[] styles = getState().getStyle().split(" ");
                 for (int i = 0; i < styles.length; i++) {
                     captionClass += " " + captionBaseClass + "-" + styles[i];
                     contentClass += " " + contentBaseClass + "-" + styles[i];
                     decoClass += " " + decoBaseClass + "-" + styles[i];
                 }
-                getWidgetForPaintable().captionNode.setClassName(captionClass);
-                getWidgetForPaintable().contentNode.setClassName(contentClass);
-                getWidgetForPaintable().bottomDecoration
-                        .setClassName(decoClass);
-
             }
+            getWidgetForPaintable().captionNode.setClassName(captionClass);
+            getWidgetForPaintable().contentNode.setClassName(contentClass);
+            getWidgetForPaintable().bottomDecoration.setClassName(decoClass);
         }
         // Ensure correct implementation
         super.updateFromUIDL(uidl, client);
index 366e49cd75d230d6402ad3a49e29e580bf343ca8..7b76b78786c5137d68157d271897465b3c0e0685 100644 (file)
@@ -53,9 +53,8 @@ public class VPopupViewPaintable extends VAbstractPaintableWidgetContainer {
             // showPopupOnTop(popup, hostReference);
             getWidgetForPaintable().preparePopup(getWidgetForPaintable().popup);
             getWidgetForPaintable().popup.updateFromUIDL(popupUIDL, client);
-            if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
-                final String[] styles = uidl
-                        .getStringAttribute(ATTRIBUTE_STYLE).split(" ");
+            if (getState().hasStyles()) {
+                final String[] styles = getState().getStyle().split(" ");
                 final StringBuffer styleBuf = new StringBuffer();
                 final String primaryName = getWidgetForPaintable().popup
                         .getStylePrimaryName();
index e119bfec5c2f169c174aae7b40d95b8d5ecff56d..42c9f55b99483160627c7d6b1f06ee1f2aff2130 100644 (file)
@@ -32,10 +32,7 @@ public class VSliderPaintable extends VAbstractPaintableWidget {
         getWidgetForPaintable().vertical = uidl.hasAttribute("vertical");
 
         // TODO should these style names be used?
-        String style = "";
-        if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
-            style = uidl.getStringAttribute(ATTRIBUTE_STYLE);
-        }
+        String style = getState().getStyle();
 
         if (getWidgetForPaintable().vertical) {
             getWidgetForPaintable().addStyleName(
index ccd2b287a48eb12aba81bf5aa913d48916467e32..ac0b3b05eb3a34bc6f7b9de58a85dc818543ed4b 100644 (file)
@@ -23,6 +23,7 @@ import com.google.gwt.user.client.ui.SimplePanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
+import com.vaadin.terminal.gwt.client.ComponentState;
 import com.vaadin.terminal.gwt.client.RenderInformation;
 import com.vaadin.terminal.gwt.client.RenderSpace;
 import com.vaadin.terminal.gwt.client.TooltipInfo;
@@ -191,7 +192,7 @@ public class VTabsheet extends VTabsheetBase {
         private ApplicationConnection client;
 
         TabCaption(Tab tab, ApplicationConnection client) {
-            super(null, client);
+            super(client);
             this.client = client;
             this.tab = tab;
         }
@@ -215,6 +216,9 @@ public class VTabsheet extends VTabsheetBase {
 
             boolean ret = super.updateCaption(uidl);
 
+            // TODO required because the caption does not have an owner
+            updateCaptionWithoutOwner(uidl);
+
             setClosable(uidl.hasAttribute("closable"));
 
             return ret;
@@ -635,12 +639,11 @@ public class VTabsheet extends VTabsheetBase {
         return scrollerIndex > index;
     }
 
-    void handleStyleNames(UIDL uidl) {
+    void handleStyleNames(UIDL uidl, ComponentState state) {
         // Add proper stylenames for all elements (easier to prevent unwanted
         // style inheritance)
-        if (uidl.hasAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE)) {
-            final String style = uidl
-                    .getStringAttribute(VAbstractPaintableWidget.ATTRIBUTE_STYLE);
+        if (state.hasStyles()) {
+            final String style = state.getStyle();
             if (currentStyle != style) {
                 currentStyle = style;
                 final String[] styles = style.split(" ");
index 29e3e3d95c465888d01842275b4186b13c79daa4..2b3e38576bc8db929279c3f9bd8dd31e32f09bf1 100644 (file)
@@ -19,7 +19,7 @@ public class VTabsheetPaintable extends VTabsheetBasePaintable {
         if (isRealUpdate(uidl)) {
             // Handle stylename changes before generics (might affect size
             // calculations)
-            getWidgetForPaintable().handleStyleNames(uidl);
+            getWidgetForPaintable().handleStyleNames(uidl, getState());
         }
 
         super.updateFromUIDL(uidl, client);
index 7ee67df69c484c7232a9a9949069f6b31457c0de..05c9d4c4cd3bd630f22dde12991939231bc30ae2 100644 (file)
@@ -14,7 +14,7 @@ import com.vaadin.terminal.gwt.client.ui.VTree.TreeNode;
 
 public class VTreePaintable extends VAbstractPaintableWidget {
 
-    public static final String ATTRIBUTE_NODE_STYLE = VAbstractPaintableWidget.ATTRIBUTE_STYLE;
+    public static final String ATTRIBUTE_NODE_STYLE = "style";
     public static final String ATTRIBUTE_NODE_CAPTION = VAbstractPaintableWidget.ATTRIBUTE_CAPTION;
     public static final String ATTRIBUTE_NODE_ICON = VAbstractPaintableWidget.ATTRIBUTE_ICON;
 
index 65c7bd2635ca5c7562b808d5fe85aa719f5683ff..a994d1dc5044abac870d196bf62a302510ba9458 100644 (file)
@@ -53,11 +53,10 @@ public class VViewPaintable extends VAbstractPaintableWidgetContainer {
         } else {
             getWidgetForPaintable().theme = newTheme;
         }
-        if (uidl.hasAttribute(ATTRIBUTE_STYLE)) {
-            getWidgetForPaintable().setStyleName(
-                    getWidgetForPaintable().getStylePrimaryName() + " "
-                            + uidl.getStringAttribute(ATTRIBUTE_STYLE));
-        }
+        // this also implicitly removes old styles
+        getWidgetForPaintable().setStyleName(
+                getWidgetForPaintable().getStylePrimaryName() + " "
+                        + getState().getStyle());
 
         clickEventHandler.handleEventHandlerRegistration(client);
 
index 0a2914b8aa3b5c175cd684c095a2e6807d2b0312..ce732cdf0a70056bc611b69f7e0cdd44ca086950 100644 (file)
@@ -771,11 +771,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource
             if (isVisible()) {
                 // width and height are only in shared state
 
-                if (styles != null && styles.size() > 0) {
-                    target.addAttribute(
-                            VAbstractPaintableWidget.ATTRIBUTE_STYLE,
-                            getStyle());
-                }
+                // TODO probably can remove some of these (caption, icon, ...)
+                // once all the VCaption related code has been updated
                 if (!isEnabled()) {
                     target.addAttribute(
                             VAbstractPaintableWidget.ATTRIBUTE_DISABLED, true);
@@ -897,15 +894,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         sharedState.setImmediate(isImmediate());
         sharedState.setReadOnly(isReadOnly());
 
-        // if (getCaption() != null) {
-        // state.put(ComponentState.STATE_CAPTION, getCaption());
-        // }
+        sharedState.setStyle(getStyleName());
 
         // TODO use the rest on the client side
+        // TODO icon also in shared state - how to convert Resource?
 
-        // if (styles != null && styles.size() > 0) {
-        // state.put(ComponentState.STATE_STYLE, getStyle());
-        // }
+        // sharedState.setCaption(getCaption());
         // if (!isEnabled()) {
         // state.put(ComponentState.STATE_DISABLED, true);
         // }