From f5c86c1344c9888a04c352d15d2e5bfae7013cfc Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Thu, 9 Jul 2009 11:32:00 +0000 Subject: [PATCH] Fixes #3129: setting component primary stylename, now only for Button component. svn changeset:8359/svn branch:6.0 --- .../terminal/gwt/client/ui/VButton.java | 7 ++++ src/com/vaadin/ui/Button.java | 40 +++++++++++++++++-- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VButton.java b/src/com/vaadin/terminal/gwt/client/ui/VButton.java index 338cdacc30..c42c19dc93 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VButton.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VButton.java @@ -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)) { diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 872285f8fc..df40aeb018 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -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); } + /** + * + * EXPERIMENTAL FEATURE Use with caution, the method signature + * might change in following releases. + *

+ * Sets the components primary style name. + *

+ * 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". + *

+ * 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; + } + } -- 2.39.5