From: Leif Åstrand Date: Tue, 16 Aug 2011 11:11:39 +0000 (+0000) Subject: #7422 AbstractComponent.setStyleName containing spaces causes illogical results X-Git-Tag: 6.7.0.beta1~70 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3e2524d2d0a45e2571c643f7e173acaff640088d;p=vaadin-framework.git #7422 AbstractComponent.setStyleName containing spaces causes illogical results svn changeset:20413/svn branch:6.7 --- diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 1f18504148..ad95b6ed58 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -7,6 +7,7 @@ package com.vaadin.ui; import java.io.Serializable; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -224,7 +225,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource styles = new ArrayList(); } styles.clear(); - styles.add(style); + String[] styleParts = style.split(" "); + styles.addAll(Arrays.asList(styleParts)); requestRepaint(); } @@ -243,7 +245,8 @@ public abstract class AbstractComponent implements Component, MethodEventSource public void removeStyleName(String style) { if (styles != null) { - styles.remove(style); + String[] styleParts = style.split(" "); + styles.removeAll(Arrays.asList(styleParts)); requestRepaint(); } } diff --git a/src/com/vaadin/ui/Component.java b/src/com/vaadin/ui/Component.java index 4dcd81da31..2d794c39b0 100644 --- a/src/com/vaadin/ui/Component.java +++ b/src/com/vaadin/ui/Component.java @@ -174,7 +174,8 @@ public interface Component extends Paintable, VariableOwner, Sizeable, public void addStyleName(String style); /** - * Removes the given style name from component. + * Removes one or more style names from component. Multiple styles can be + * specified as a space-separated list of style names. * *

* The parameter must be a valid CSS style name. Only user-defined style @@ -183,8 +184,12 @@ public interface Component extends Paintable, VariableOwner, Sizeable, * style names defined in Vaadin or GWT can not be removed. *

* + * * This method will trigger a + * {@link com.vaadin.terminal.Paintable.RepaintRequestEvent + * RepaintRequestEvent}. + * * @param style - * the style name to be removed + * the style name or style names to be removed * @see #getStyleName() * @see #setStyleName(String) * @see #addStyleName(String) diff --git a/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java b/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java new file mode 100644 index 0000000000..9d31029698 --- /dev/null +++ b/tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.server.component.abstractcomponent; + +import junit.framework.TestCase; + +import com.vaadin.ui.AbstractComponent; + +public class TestAbstractComponentStyleNames extends TestCase { + + public void testSetMultiple() { + AbstractComponent component = getComponent(); + component.setStyleName("style1 style2"); + assertEquals(component.getStyleName(), "style1 style2"); + } + + public void testSetAdd() { + AbstractComponent component = getComponent(); + component.setStyleName("style1"); + component.addStyleName("style2"); + assertEquals(component.getStyleName(), "style1 style2"); + } + + public void testAddSame() { + AbstractComponent component = getComponent(); + component.setStyleName("style1 style2"); + component.addStyleName("style1"); + assertEquals(component.getStyleName(), "style1 style2"); + } + + public void testSetRemove() { + AbstractComponent component = getComponent(); + component.setStyleName("style1 style2"); + component.removeStyleName("style1"); + assertEquals(component.getStyleName(), "style2"); + } + + public void testAddRemove() { + AbstractComponent component = getComponent(); + component.addStyleName("style1"); + component.addStyleName("style2"); + component.removeStyleName("style1"); + assertEquals(component.getStyleName(), "style2"); + } + + public void testRemoveMultiple() { + AbstractComponent component = getComponent(); + component.setStyleName("style1 style2 style3"); + component.removeStyleName("style1 style3"); + assertEquals(component.getStyleName(), "style2"); + } + + private AbstractComponent getComponent() { + return new AbstractComponent() { + }; + } + +}