diff options
author | Matti Tahvonen <matti@vaadin.com> | 2013-12-07 17:51:56 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-12-18 09:04:53 +0000 |
commit | 0d303da73bca604474649a83817d1b7d5e09f2e2 (patch) | |
tree | 7957147de6eeaeb4d744f8d50b31d39bcc7fdc52 /server | |
parent | 78a6232b6b0dd2e6c89039e9ca50c164f2d9ab6a (diff) | |
download | vaadin-framework-0d303da73bca604474649a83817d1b7d5e09f2e2.tar.gz vaadin-framework-0d303da73bca604474649a83817d1b7d5e09f2e2.zip |
Added convenience method to add items as a varargs array (#13067)
Change-Id: Iab49d0960946cec5e949f4f60bb2f79dce66dcc3
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/AbstractSelect.java | 31 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java | 26 |
2 files changed, 57 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/AbstractSelect.java b/server/src/com/vaadin/ui/AbstractSelect.java index 556b16943f..a32d40b11d 100644 --- a/server/src/com/vaadin/ui/AbstractSelect.java +++ b/server/src/com/vaadin/ui/AbstractSelect.java @@ -878,6 +878,37 @@ public abstract class AbstractSelect extends AbstractField<Object> implements return retval; } + /** + * Adds given items with given item ids to container. + * + * @since 7.2 + * @param itemId + * item identifiers to be added to underlying container + * @throws UnsupportedOperationException + * if the underlying container don't support adding items with + * identifiers + */ + public void addItems(Object... itemId) throws UnsupportedOperationException { + for (Object id : itemId) { + addItem(id); + } + } + + /** + * Adds given items with given item ids to container. + * + * @since 7.2 + * @param itemIds + * item identifiers to be added to underlying container + * @throws UnsupportedOperationException + * if the underlying container don't support adding items with + * identifiers + */ + public void addItems(Collection<Object> itemIds) + throws UnsupportedOperationException { + addItems(itemIds.toArray()); + } + /* * (non-Javadoc) * diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java new file mode 100644 index 0000000000..5575b8fd3d --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java @@ -0,0 +1,26 @@ +package com.vaadin.tests.server.component.abstractselect; + +import java.util.Collection; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.vaadin.ui.OptionGroup; + +public class TestVarargsItemAddition extends TestCase { + + public void itemAddition() throws Exception { + + OptionGroup optionGroup = new OptionGroup(); + + optionGroup.addItems("foo", "bar", "car"); + + Collection<?> itemIds = optionGroup.getItemIds(); + Assert.assertEquals(3, itemIds.size()); + Assert.assertTrue(itemIds.contains("foo")); + Assert.assertTrue(itemIds.contains("bar")); + Assert.assertTrue(itemIds.contains("car")); + + } +} |