]> source.dussan.org Git - vaadin-framework.git/commitdiff
Changed getStyleNames to be non static so it can be overridden
authorArtur Signell <artur@vaadin.com>
Mon, 16 Apr 2012 11:06:39 +0000 (14:06 +0300)
committerArtur Signell <artur@vaadin.com>
Mon, 16 Apr 2012 11:06:39 +0000 (14:06 +0300)
src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java
src/com/vaadin/terminal/gwt/client/ui/AbstractFieldConnector.java
src/com/vaadin/terminal/gwt/client/ui/datefield/PopupDateFieldConnector.java

index e5d2fc14cc3e103f5c433a5def97db2e7bff99df..2458a27eac6fe8d85cb9f3367014dd3e7e851d04 100644 (file)
@@ -108,8 +108,7 @@ public abstract class AbstractComponentConnector extends AbstractConnector
         }
 
         // Style names
-        String styleName = getStyleNames(getWidget().getStylePrimaryName(),
-                this);
+        String styleName = getStyleNames(getWidget().getStylePrimaryName());
         getWidget().setStyleName(styleName);
 
         // Update tooltip
@@ -223,32 +222,32 @@ public abstract class AbstractComponentConnector extends AbstractConnector
 
     /**
      * Generates the style name for the widget based on the given primary style
-     * name (typically returned by Widget.getPrimaryStyleName()) and the UIDL
-     * and shared state of the component. An additional "modified" style name
-     * can be added if the field parameter is set to true.
+     * name and the shared state.
+     * <p>
+     * This method can be overridden to provide additional style names for the
+     * component
+     * </p>
      * 
      * @param primaryStyleName
-     * @param uidl
-     * @param state
-     *            component shared state
-     * @param field
-     * @return
+     *            The primary style name to use when generating the final style
+     *            names
+     * @return The style names, settable using
+     *         {@link Widget#setStyleName(String)}
      */
-    protected static String getStyleNames(String primaryStyleName,
-            ComponentConnector connector) {
-        ComponentState state = connector.getState();
+    protected String getStyleNames(String primaryStyleName) {
+        ComponentState state = getState();
 
-        StringBuffer styleBuf = new StringBuffer();
+        StringBuilder styleBuf = new StringBuilder();
         styleBuf.append(primaryStyleName);
         styleBuf.append(" v-connector");
 
         // Uses connector methods to enable connectors to take hierarchy or
         // multiple state variables into account
-        if (!connector.isEnabled()) {
+        if (!isEnabled()) {
             styleBuf.append(" ");
             styleBuf.append(ApplicationConnection.DISABLED_CLASSNAME);
         }
-        if (connector.isReadOnly()) {
+        if (isReadOnly()) {
             styleBuf.append(" ");
             styleBuf.append("v-readonly");
         }
@@ -266,23 +265,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector
             }
         }
 
-        if (connector instanceof AbstractFieldConnector) {
-            // TODO Move to AbstractFieldConnector
-            AbstractFieldConnector afc = ((AbstractFieldConnector) connector);
-            if (afc.isModified()) {
-                // add modified classname to Fields
-                styleBuf.append(" ");
-                styleBuf.append(ApplicationConnection.MODIFIED_CLASSNAME);
-            }
-
-            if (afc.isRequired()) {
-                // add required classname to required fields
-                styleBuf.append(" ");
-                styleBuf.append(primaryStyleName);
-                styleBuf.append(ApplicationConnection.REQUIRED_CLASSNAME_EXT);
-            }
-        }
-
         // add error classname to components w/ error
         if (null != state.getErrorMessage()) {
             styleBuf.append(" ");
index 5e629f2dc9568bdfdc755d9e6390e2cbbaec4626..4be0f02c2ae99945ecdec8f20691d22a38f3abed 100644 (file)
@@ -4,6 +4,7 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.vaadin.terminal.gwt.client.AbstractFieldState;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
 
 public abstract class AbstractFieldConnector extends AbstractComponentConnector {
 
@@ -33,4 +34,21 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector
         return getState().isRequired() && !isReadOnly();
     }
 
+    @Override
+    protected String getStyleNames(String primaryStyleName) {
+        String styleNames = super.getStyleNames(primaryStyleName);
+
+        if (isModified()) {
+            // add modified classname to Fields
+            styleNames += " " + ApplicationConnection.MODIFIED_CLASSNAME;
+        }
+
+        if (isRequired()) {
+            // add required classname to Fields
+            styleNames += " " + primaryStyleName
+                    + ApplicationConnection.REQUIRED_CLASSNAME_EXT;
+        }
+
+        return styleNames;
+    }
 }
index 1e9de1747600001e10220489acfe55781621fee8..1bcb40d549373f94113227468dc835ef4d46aa7c 100644 (file)
@@ -37,8 +37,7 @@ public class PopupDateFieldConnector extends TextualDateConnector {
 
         super.updateFromUIDL(uidl, client);
 
-        String popupStyleNames = getStyleNames(
-                VPopupCalendar.POPUP_PRIMARY_STYLE_NAME, this);
+        String popupStyleNames = getStyleNames(VPopupCalendar.POPUP_PRIMARY_STYLE_NAME);
         popupStyleNames += " "
                 + VDateField.CLASSNAME
                 + "-"