@@ -4,6 +4,8 @@ | |||
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; | |||
@@ -20,7 +22,6 @@ public class ComponentState extends SharedState { | |||
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 | |||
@@ -28,6 +29,7 @@ public class ComponentState extends SharedState { | |||
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. | |||
@@ -151,36 +153,13 @@ public class ComponentState extends SharedState { | |||
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(); | |||
} | |||
/** | |||
@@ -298,4 +277,23 @@ public class ComponentState extends SharedState { | |||
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; | |||
} | |||
} |
@@ -108,9 +108,8 @@ public class VCaption extends HTML { | |||
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()) { |
@@ -362,14 +362,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector | |||
// 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); | |||
} | |||
} | |||
@@ -3,6 +3,8 @@ | |||
*/ | |||
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; | |||
@@ -79,9 +81,9 @@ public abstract class AbstractSplitPanelConnector extends | |||
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")); |
@@ -122,7 +122,7 @@ public class MenuBarConnector extends AbstractComponentConnector implements | |||
// 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); | |||
} | |||
} |
@@ -82,11 +82,10 @@ public class PanelConnector extends AbstractComponentContainerConnector | |||
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); |
@@ -54,16 +54,15 @@ public class PopupViewConnector extends AbstractComponentContainerConnector { | |||
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 { |
@@ -57,10 +57,14 @@ public class RootConnector extends AbstractComponentContainerConnector | |||
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); | |||
@@ -30,8 +30,7 @@ public class SliderConnector extends AbstractFieldConnector { | |||
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"); |
@@ -4,6 +4,8 @@ | |||
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; | |||
@@ -66,7 +68,7 @@ public class VAbstractSplitPanel extends ComplexPanel { | |||
private boolean positionReversed = false; | |||
String[] componentStyleNames; | |||
List<String> componentStyleNames; | |||
private Element draggingCurtain; | |||
@@ -603,13 +605,12 @@ public class VAbstractSplitPanel extends ComplexPanel { | |||
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); |
@@ -552,10 +552,11 @@ public class VFilterSelect extends Composite implements Field, KeyDownHandler, | |||
*/ | |||
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); | |||
} | |||
} | |||
} | |||
} |
@@ -56,8 +56,7 @@ public class VFormLayout extends SimplePanel { | |||
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); | |||
} | |||
} |
@@ -5,6 +5,7 @@ | |||
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; | |||
@@ -713,21 +714,20 @@ public class VTabsheet extends VTabsheetBase implements Focusable, | |||
// 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); |
@@ -59,11 +59,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
/* Private members */ | |||
/** | |||
* Style names. | |||
*/ | |||
private ArrayList<String> styles; | |||
/** | |||
* Application specific data object. The component does not use or modify | |||
* this. | |||
@@ -206,8 +201,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
*/ | |||
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 += " "; | |||
@@ -223,13 +219,14 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
*/ | |||
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) { | |||
@@ -244,9 +241,10 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
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(); | |||
@@ -254,11 +252,11 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
} | |||
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(); | |||
@@ -813,8 +811,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
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 | |||
@@ -833,12 +829,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource | |||
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; | |||
} | |||