}
// Style names
- String styleName = getStyleNames(getWidget().getStylePrimaryName(),
- this);
+ String styleName = getStyleNames(getWidget().getStylePrimaryName());
getWidget().setStyleName(styleName);
// Update tooltip
/**
* 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");
}
}
}
- 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(" ");
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 {
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;
+ }
}