package com.vaadin.terminal.gwt.client;
+import java.util.List;
+
import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.terminal.gwt.client.communication.URLReference;
import com.vaadin.ui.Component;
private String width = "";
private boolean readOnly = false;
private boolean immediate = false;
- private String style = "";
private boolean enabled = true;
private String description = "";
// Note: for the caption, there is a difference between null and an empty
private String caption = null;
private boolean visible = true;
private URLReference icon = null;
+ private List<String> styles = null;
/**
* Returns the component height as set by the server.
this.immediate = immediate;
}
- /**
- * 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());
+ return styles != null && !styles.isEmpty();
}
/**
this.icon = icon;
}
+ /**
+ * Gets the style names for the component.
+ *
+ * @return A List of style names or null if no styles have been set.
+ */
+ public List<String> getStyles() {
+ return styles;
+ }
+
+ /**
+ * Sets the style names for the component.
+ *
+ * @param styles
+ * A list containing style names
+ */
+ public void setStyles(List<String> styles) {
+ this.styles = styles;
+ }
+
}
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];
+ for (String customStyle : owner.getState().getStyles()) {
+ style += " " + CLASSNAME + "-" + customStyle;
}
}
if (!owner.isEnabled()) {
// add additional styles as css classes, prefixed with component default
// stylename
if (state.hasStyles()) {
- final String[] styles = state.getStyle().split(" ");
- for (int i = 0; i < styles.length; i++) {
+ for (String style : state.getStyles()) {
styleBuf.append(" ");
styleBuf.append(primaryStyleName);
styleBuf.append("-");
- styleBuf.append(styles[i]);
+ styleBuf.append(style);
styleBuf.append(" ");
- styleBuf.append(styles[i]);
+ styleBuf.append(style);
}
}
*/
package com.vaadin.terminal.gwt.client.ui;
+import java.util.LinkedList;
+
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.dom.client.DomEvent.Type;
import com.google.gwt.event.shared.EventHandler;
clickEventHandler.handleEventHandlerRegistration(client);
if (getState().hasStyles()) {
- getWidget().componentStyleNames = getState().getStyle().split(" ");
+ getWidget().componentStyleNames = getState().getStyles();
} else {
- getWidget().componentStyleNames = new String[0];
+ getWidget().componentStyleNames = new LinkedList<String>();
}
getWidget().setLocked(uidl.getBooleanAttribute("locked"));
// any item specific styles are set above in
// currentItem.updateFromUIDL(item, client)
if (getState().hasStyles()) {
- for (String style : getState().getStyle().split(" ")) {
+ for (String style : getState().getStyles()) {
currentMenu.addStyleDependentName(style);
}
}
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];
+ for (String style : getState().getStyles()) {
+ captionClass += " " + captionBaseClass + "-" + style;
+ contentClass += " " + contentBaseClass + "-" + style;
+ decoClass += " " + decoBaseClass + "-" + style;
}
}
getWidget().captionNode.setClassName(captionClass);
getWidget().preparePopup(getWidget().popup);
getWidget().popup.updateFromUIDL(popupUIDL, client);
if (getState().hasStyles()) {
- final String[] styles = getState().getStyle().split(" ");
final StringBuffer styleBuf = new StringBuffer();
final String primaryName = getWidget().popup
.getStylePrimaryName();
styleBuf.append(primaryName);
- for (int i = 0; i < styles.length; i++) {
+ for (String style : getState().getStyles()) {
styleBuf.append(" ");
styleBuf.append(primaryName);
styleBuf.append("-");
- styleBuf.append(styles[i]);
+ styleBuf.append(style);
}
getWidget().popup.setStyleName(styleBuf.toString());
} else {
getWidget().theme = newTheme;
}
// this also implicitly removes old styles
- getWidget()
- .setStyleName(
- getWidget().getStylePrimaryName() + " "
- + getState().getStyle());
+ String styles = "";
+ styles += getWidget().getStylePrimaryName() + " ";
+ if (getState().hasStyles()) {
+ for (String style : getState().getStyles()) {
+ styles += style + " ";
+ }
+ }
+ getWidget().setStyleName(styles.trim());
clickEventHandler.handleEventHandlerRegistration(client);
getWidget().vertical = uidl.hasAttribute("vertical");
- // TODO should these style names be used?
- String style = getState().getStyle();
+ // TODO should style names be used?
if (getWidget().vertical) {
getWidget().addStyleName(VSlider.CLASSNAME + "-vertical");
package com.vaadin.terminal.gwt.client.ui;
+import java.util.List;
+
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.Style;
import com.google.gwt.event.dom.client.TouchCancelEvent;
private boolean positionReversed = false;
- String[] componentStyleNames;
+ List<String> componentStyleNames;
private Element draggingCurtain;
splitterStyle = CLASSNAME + splitterSuffix + "-locked";
lockedSuffix = "-locked";
}
- for (int i = 0; i < componentStyleNames.length; i++) {
- splitterStyle += " " + CLASSNAME + splitterSuffix + "-"
- + componentStyleNames[i] + lockedSuffix;
- firstStyle += " " + CLASSNAME + firstContainerSuffix + "-"
- + componentStyleNames[i];
+ for (String style : componentStyleNames) {
+ splitterStyle += " " + CLASSNAME + splitterSuffix + "-" + style
+ + lockedSuffix;
+ firstStyle += " " + CLASSNAME + firstContainerSuffix + "-" + style;
secondStyle += " " + CLASSNAME + secondContainerSuffix + "-"
- + componentStyleNames[i];
+ + style;
}
DOM.setElementProperty(splitter, "className", splitterStyle);
DOM.setElementProperty(firstContainer, "className", firstStyle);
*/
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]);
+ if (componentState.hasStyles()) {
+ for (String style : componentState.getStyles()) {
+ if (!"".equals(style)) {
+ addStyleDependentName(style);
+ }
}
}
}
private String[] getStylesFromState(ComponentState state, boolean enabled) {
List<String> styles = new ArrayList<String>();
if (state.hasStyles()) {
- String[] stylesnames = state.getStyle().split(" ");
- for (String name : stylesnames) {
+ for (String name : state.getStyles()) {
styles.add(name);
}
}
package com.vaadin.terminal.gwt.client.ui;
import java.util.Iterator;
+import java.util.List;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.DivElement;
// Add proper stylenames for all elements (easier to prevent unwanted
// style inheritance)
if (state.hasStyles()) {
- final String style = state.getStyle();
- if (currentStyle != style) {
- currentStyle = style;
- final String[] styles = style.split(" ");
+ final List<String> styles = state.getStyles();
+ if (!currentStyle.equals(styles.toString())) {
+ currentStyle = styles.toString();
final String tabsBaseClass = TABS_CLASSNAME;
String tabsClass = tabsBaseClass;
final String contentBaseClass = CLASSNAME + "-content";
String contentClass = contentBaseClass;
final String decoBaseClass = CLASSNAME + "-deco";
String decoClass = decoBaseClass;
- for (int i = 0; i < styles.length; i++) {
- tb.addStyleDependentName(styles[i]);
- tabsClass += " " + tabsBaseClass + "-" + styles[i];
- contentClass += " " + contentBaseClass + "-" + styles[i];
- decoClass += " " + decoBaseClass + "-" + styles[i];
+ for (String style : styles) {
+ tb.addStyleDependentName(style);
+ tabsClass += " " + tabsBaseClass + "-" + style;
+ contentClass += " " + contentBaseClass + "-" + style;
+ decoClass += " " + decoBaseClass + "-" + style;
}
DOM.setElementProperty(tabs, "className", tabsClass);
DOM.setElementProperty(contentNode, "className", contentClass);
/* Private members */
- /**
- * Style names.
- */
- private ArrayList<String> styles;
-
/**
* Application specific data object. The component does not use or modify
* this.
*/
public String getStyleName() {
String s = "";
- if (styles != null) {
- for (final Iterator<String> it = styles.iterator(); it.hasNext();) {
+ if (getState().getStyles() != null) {
+ for (final Iterator<String> it = getState().getStyles().iterator(); it
+ .hasNext();) {
s += it.next();
if (it.hasNext()) {
s += " ";
*/
public void setStyleName(String style) {
if (style == null || "".equals(style)) {
- styles = null;
+ getState().setStyles(null);
requestRepaint();
return;
}
- if (styles == null) {
- styles = new ArrayList<String>();
+ if (getState().getStyles() == null) {
+ getState().setStyles(new ArrayList<String>());
}
+ List<String> styles = getState().getStyles();
styles.clear();
String[] styleParts = style.split(" +");
for (String part : styleParts) {
if (style == null || "".equals(style)) {
return;
}
- if (styles == null) {
- styles = new ArrayList<String>();
+ if (getState().getStyles() == null) {
+ getState().setStyles(new ArrayList<String>());
}
+ List<String> styles = getState().getStyles();
if (!styles.contains(style)) {
styles.add(style);
requestRepaint();
}
public void removeStyleName(String style) {
- if (styles != null) {
+ if (getState().getStyles() != null) {
String[] styleParts = style.split(" +");
for (String part : styleParts) {
if (part.length() > 0) {
- styles.remove(part);
+ getState().getStyles().remove(part);
}
}
requestRepaint();
if (null == sharedState) {
sharedState = createState();
}
- // basic state: caption, size, enabled, ...
-
// TODO This logic should be on the client side and the state should
// simply be a data object with "width" and "height".
if (getHeight() >= 0
sharedState.setWidth("");
}
- // TODO This should be an array in state and the logic for converting
- // array -> class name should be on the client side
- sharedState.setStyle(getStyleName());
-
- // TODO icon also in shared state - how to convert Resource?
-
return sharedState;
}