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.
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());
+ }
}
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();
// 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
captionText = null;
}
- if (hasDescription) {
- if (captionText != null) {
+ if (null != owner) {
+ if (hasDescription && captionText != null) {
addStyleDependentName("hasdescription");
} else {
removeStyleDependentName("hasdescription");
}
+ @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);
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);
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;
// 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);
!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];
}
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());
public void updateCaption(UIDL uidl) {
caption.updateCaption(uidl);
+ // TODO required because the caption does not have an owner
+ caption.updateCaptionWithoutOwner(uidl);
}
public int getWidgetWidth() {
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;
/**
* 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]);
}
}
getWidgetForPaintable().inputPrompt = "";
}
- getWidgetForPaintable().suggestionPopup.updateStyleNames(uidl);
+ getWidgetForPaintable().suggestionPopup.updateStyleNames(uidl,
+ getState());
getWidgetForPaintable().allowNewItem = uidl
.hasAttribute("allownewitem");
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;
*
* @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);
}
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());
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;
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";
// 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);
}
}
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;
// 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);
// 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();
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(
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;
private ApplicationConnection client;
TabCaption(Tab tab, ApplicationConnection client) {
- super(null, client);
+ super(client);
this.client = client;
this.tab = tab;
}
boolean ret = super.updateCaption(uidl);
+ // TODO required because the caption does not have an owner
+ updateCaptionWithoutOwner(uidl);
+
setClosable(uidl.hasAttribute("closable"));
return ret;
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(" ");
if (isRealUpdate(uidl)) {
// Handle stylename changes before generics (might affect size
// calculations)
- getWidgetForPaintable().handleStyleNames(uidl);
+ getWidgetForPaintable().handleStyleNames(uidl, getState());
}
super.updateFromUIDL(uidl, client);
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;
} 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);
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);
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);
// }