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;
styles = new ArrayList<String>();
}
styles.clear();
- styles.add(style);
+ String[] styleParts = style.split(" ");
+ styles.addAll(Arrays.asList(styleParts));
requestRepaint();
}
public void removeStyleName(String style) {
if (styles != null) {
- styles.remove(style);
+ String[] styleParts = style.split(" ");
+ styles.removeAll(Arrays.asList(styleParts));
requestRepaint();
}
}
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
* 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)
--- /dev/null
+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() {
+ };
+ }
+
+}