aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java5
-rw-r--r--server/src/main/java/com/vaadin/ui/RadioButtonGroup.java6
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java47
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java47
4 files changed, 85 insertions, 20 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java b/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java
index bb81b2872e..fd4d7cf98a 100644
--- a/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java
+++ b/client/src/main/java/com/vaadin/client/ui/VRadioButtonGroup.java
@@ -229,7 +229,8 @@ public class VRadioButtonGroup extends Composite implements Field, ClickHandler,
public void selectItemKey(String selectedItemKey) {
RadioButton radioButton = keyToOptions.get(selectedItemKey);
- assert radioButton != null;
- radioButton.setValue(true);
+ if(radioButton!=null) {//Items might not be loaded yet
+ radioButton.setValue(true);
+ }
}
}
diff --git a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
index 2e7ff8a706..13aa840462 100644
--- a/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
+++ b/server/src/main/java/com/vaadin/ui/RadioButtonGroup.java
@@ -169,7 +169,7 @@ public class RadioButtonGroup<T> extends AbstractSingleSelect<T> {
* Returns the item icon generator.
*
* @return the currently set icon generator
- * @see #setItemIconProvider
+ * @see #setItemIconGenerator
* @see IconGenerator
*/
public IconGenerator<T> getItemIconGenerator() {
@@ -179,8 +179,8 @@ public class RadioButtonGroup<T> extends AbstractSingleSelect<T> {
/**
* Sets the item icon generator for this radiobutton group. The icon
* generator is queried for each item to optionally display an icon next to
- * the item caption. If the provider returns null for an item, no icon is
- * displayed. The default provider always returns null (no icons).
+ * the item caption. If the generator returns null for an item, no icon is
+ * displayed. The default generator always returns null (no icons).
*
* @param itemIconGenerator
* the icon generator, not null
diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java
index 041c578f1b..036512a514 100644
--- a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java
+++ b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java
@@ -15,14 +15,15 @@
*/
package com.vaadin.tests.components.radiobutton;
-import java.util.LinkedHashMap;
-import java.util.stream.IntStream;
-
+import com.vaadin.server.FontAwesome;
import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.tests.components.abstractlisting.AbstractListingTestUI;
import com.vaadin.ui.ItemCaptionGenerator;
import com.vaadin.ui.RadioButtonGroup;
+import java.util.LinkedHashMap;
+import java.util.stream.IntStream;
+
/**
* Test UI for RadioButtonGroup component
*
@@ -44,7 +45,8 @@ public class RadioButtonGroupTestUI
super.createActions();
createListenerMenu();
createSelectionMenu();
- createItemGeneratorMenu();
+ createItemIconGeneratorMenu();
+ createItemCaptionGeneratorMenu();
}
protected void createSelectionMenu() {
@@ -60,15 +62,30 @@ public class RadioButtonGroupTestUI
.forEach(item -> createClickAction("Toggle " + item,
selectionCategory, toggleSelection, item));
}
+ private void createItemIconGeneratorMenu() {
+ createBooleanAction("Use Item Icon Generator", "Item Icon Generator", false,
+ this::useItemIconGenerator);
+ }
- private void createItemGeneratorMenu() {
+ private void useItemIconGenerator(RadioButtonGroup<Object> group,
+ boolean activate, Object data) {
+ if (activate) {
+ group.setItemIconGenerator(
+ item -> FontAwesome.values()[getIndex(item) + 1]);
+ } else {
+ group.setItemIconGenerator(item -> null);
+ }
+ group.getDataSource().refreshAll();
+ }
+
+ private void createItemCaptionGeneratorMenu() {
LinkedHashMap<String, ItemCaptionGenerator<Object>> options = new LinkedHashMap<>();
options.put("Null Caption Generator", item -> null);
options.put("Default Caption Generator", item -> item.toString());
options.put("Custom Caption Generator",
item -> item.toString() + " Caption");
- createSelectAction("Item Caption Generator", "Item Generator", options,
+ createSelectAction("Item Caption Generator", "Item Caption Generator", options,
"None", (radioButtonGroup, captionGenerator, data) -> {
radioButtonGroup.setItemCaptionGenerator(captionGenerator);
radioButtonGroup.getDataSource().refreshAll();
@@ -91,4 +108,22 @@ public class RadioButtonGroupTestUI
e -> log("Selected: " + e.getSelectedItem())));
}
+
+ private int getIndex(Object item) {
+ int index = item.toString().indexOf(' ');
+ if (index < 0) {
+ return 0;
+ }
+ String postfix = item.toString().substring(index + 1);
+ index = postfix.indexOf(' ');
+ if (index >= 0) {
+ postfix = postfix.substring(0, index);
+ }
+ try {
+ return Integer.parseInt(postfix);
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java
index 42d912edd6..b2546347dd 100644
--- a/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java
@@ -15,17 +15,20 @@
*/
package com.vaadin.tests.components.radiobutton;
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-
+import com.vaadin.server.FontAwesome;
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.customelements.RadioButtonGroupElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
-import com.vaadin.testbench.customelements.RadioButtonGroupElement;
-import com.vaadin.tests.tb3.MultiBrowserTest;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
/**
* Test for RadioButtonGroup
@@ -93,6 +96,23 @@ public class RadioButtonGroupTest extends MultiBrowserTest {
}
@Test
+ public void itemIconGenerator() {
+ selectMenuPath("Component", "Item Icon Generator", "Use Item Icon Generator");
+ assertItemsSuffices(20);
+
+ List<WebElement> icons = getSelect().findElements(By.
+ cssSelector(".v-select-optiongroup .v-icon"));
+
+ assertEquals(20,icons.size());
+
+ for (int i = 0; i < icons.size(); i++) {
+ Assert.assertEquals(FontAwesome.values()[i + 1].getCodepoint(),
+ icons.get(i).getText().charAt(0));
+ }
+ }
+
+
+ @Test
public void clickToSelect_reenable() {
selectMenuPath("Component", "State", "Enabled");
selectMenuPath("Component", "Listeners", "Selection listener");
@@ -113,14 +133,14 @@ public class RadioButtonGroupTest extends MultiBrowserTest {
@Test
public void itemCaptionGenerator() {
- selectMenuPath("Component", "Item Generator", "Item Caption Generator",
+ selectMenuPath("Component", "Item Caption Generator", "Item Caption Generator",
"Custom Caption Generator");
assertItems(20, " Caption");
}
@Test
public void nullItemCaptionGenerator() {
- selectMenuPath("Component", "Item Generator", "Item Caption Generator",
+ selectMenuPath("Component", "Item Caption Generator", "Item Caption Generator",
"Null Caption Generator");
for (String text : getSelect().getOptions()) {
Assert.assertEquals("", text);
@@ -171,4 +191,13 @@ public class RadioButtonGroupTest extends MultiBrowserTest {
}
assertEquals("Number of items", count, i);
}
+
+ protected void assertItemsSuffices(int count) {
+ int i = 0;
+ for (String text : getSelect().getOptions()) {
+ assertTrue(text.endsWith("Item " + i));
+ i++;
+ }
+ assertEquals("Number of items", count, i);
+ }
}