]> source.dussan.org Git - vaadin-framework.git/commitdiff
#7422 AbstractComponent.setStyleName containing spaces causes illogical results
authorLeif Åstrand <leif@vaadin.com>
Tue, 16 Aug 2011 11:11:39 +0000 (11:11 +0000)
committerLeif Åstrand <leif@vaadin.com>
Tue, 16 Aug 2011 11:11:39 +0000 (11:11 +0000)
svn changeset:20413/svn branch:6.7

src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/Component.java
tests/src/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java [new file with mode: 0644]

index 1f1850414816bcf9ba9bb313815a210f7ca33004..ad95b6ed58bc62ede29d9532b47514dee2e21098 100644 (file)
@@ -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<String>();
         }
         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();
         }
     }
index 4dcd81da31c97d7ea489a30d713d046f8add3cbd..2d794c39b0b9f8364ad819f40b2a75737ab04351 100644 (file)
@@ -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.
      * 
      * <p>
      * 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.
      * </p>
      * 
+     * * 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 (file)
index 0000000..9d31029
--- /dev/null
@@ -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() {
+        };
+    }
+
+}