]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixes #3129: setting component primary stylename, now only for Button component.
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 9 Jul 2009 11:32:00 +0000 (11:32 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Thu, 9 Jul 2009 11:32:00 +0000 (11:32 +0000)
svn changeset:8359/svn branch:6.0

src/com/vaadin/terminal/gwt/client/ui/VButton.java
src/com/vaadin/ui/Button.java

index 338cdacc304a00db028bcf115f4f8a1495480f64..c42c19dc93f42c35458e886855ed507a649395be 100644 (file)
@@ -72,6 +72,13 @@ public class VButton extends Button implements Paintable {
 
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
 
+       // client.updateComponent depends on this, so this must come before that.
+        if (uidl.hasAttribute("primarystyle")) {
+            setStyleName(uidl.getStringAttribute("primarystyle"));
+            captionElement.setPropertyString("className", getStylePrimaryName()
+                    + "-caption");
+        }
+
         // Ensure correct implementation,
         // but don't let container manage caption etc.
         if (client.updateComponent(this, uidl, false)) {
index 872285f8fcdd165903f70ad1f3dc05dfcb744aae..df40aeb0180908390bc2e4bda246511e2e6aed49 100644 (file)
@@ -28,6 +28,8 @@ public class Button extends AbstractField {
 
     boolean switchMode = false;
 
+    private String primaryStyleName;
+
     /**
      * Creates a new push button. The value of the push button is false and it
      * is immediate by default.
@@ -68,9 +70,9 @@ public class Button extends AbstractField {
      * Creates a new push button with a method listening button clicks. Using
      * this method is discouraged because it cannot be checked during
      * compilation. Use
-     * {@link #Button(String, com.vaadin.ui.Button.ClickListener)}
-     * instead. The method must have either no parameters, or only one parameter
-     * of Button.ClickEvent type.
+     * {@link #Button(String, com.vaadin.ui.Button.ClickListener)} instead. The
+     * method must have either no parameters, or only one parameter of
+     * Button.ClickEvent type.
      * 
      * @param caption
      *            the Button caption.
@@ -135,6 +137,9 @@ public class Button extends AbstractField {
     public void paintContent(PaintTarget target) throws PaintException {
         super.paintContent(target);
 
+        if (primaryStyleName != null) {
+            target.addAttribute("primarystyle", primaryStyleName);
+        }
         if (isSwitchMode()) {
             target.addAttribute("type", "switch");
         }
@@ -347,4 +352,33 @@ public class Button extends AbstractField {
         super.setInternalValue(newValue);
     }
 
+    /**
+     * 
+     * <i><b>EXPERIMENTAL FEATURE</b> Use with caution, the method signature
+     * might change in following releases.</i>
+     * <p>
+     * Sets the components primary style name.
+     * <p>
+     * The primary style name is usually used on the client-side as the prefix
+     * for widget CSS classnames (this depends on the terminal implementation).
+     * The default primary styles are usually prefixed with Vaadin proprietary
+     * "v-" string, e.g. the primary style name for a default Vaadin button is
+     * "v-button".
+     * <p>
+     * With this method, you can change the primary style name to "mybutton",
+     * and then on the client-side you would have "mybutton" as the CSS
+     * classname. After that, all other style names you set for the component
+     * will be prefixed with the new primary style name, i.e. setting an
+     * additional style name "red" for the same button would result in a CSS
+     * classname "mybutton-red" on the client-side.
+     */
+    public void setPrimaryStyleName(String primary) {
+        primaryStyleName = primary;
+        requestRepaint();
+    }
+
+    public String getPrimaryStyleName() {
+        return primaryStyleName;
+    }
+
 }