public class VOptionGroup extends VOptionGroupBase implements FocusHandler,\r
BlurHandler {\r
\r
+ public static final String HTML_CONTENT_ALLOWED = "htmlcontentallowed";\r
+\r
public static final String CLASSNAME = "v-select-optiongroup";\r
\r
private final Panel panel;\r
*/\r
private boolean blurOccured = false;\r
\r
+ private boolean htmlItems = false;\r
+\r
public VOptionGroup() {\r
super(CLASSNAME);\r
panel = (Panel) optionsContainer;\r
\r
@Override\r
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
+ if (uidl.hasAttribute(HTML_CONTENT_ALLOWED)\r
+ && uidl.getBooleanAttribute(HTML_CONTENT_ALLOWED)) {\r
+ htmlItems = true;\r
+ } else {\r
+ htmlItems = false;\r
+ }\r
super.updateFromUIDL(uidl, client);\r
\r
sendFocusEvents = client.hasEventListeners(this, EventId.FOCUS);\r
for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {\r
final UIDL opUidl = (UIDL) it.next();\r
CheckBox op;\r
+ String caption = opUidl.getStringAttribute("caption");\r
if (isMultiselect()) {\r
op = new VCheckBox();\r
- op.setText(opUidl.getStringAttribute("caption"));\r
+ if (htmlItems) {\r
+ op.setHTML(caption);\r
+ } else {\r
+ op.setText(caption);\r
+ }\r
} else {\r
- op = new RadioButton(id, opUidl.getStringAttribute("caption"));\r
+ op = new RadioButton(id, caption, htmlItems);\r
op.setStyleName("v-radiobutton");\r
}\r
op.addStyleName(CLASSNAME_OPTION);\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8888/" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.optiongroup.HtmlOptionGroupItems?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupHtmlOptionGroupItems::PID_Sbuttonaction-Toggle html mode/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>html-and-text</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupHtmlOptionGroupItems::PID_Sbuttonaction-Toggle html mode/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>text-and-html</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.optiongroup;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.tests.components.ComponentTestCase;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.OptionGroup;
+
+public class HtmlOptionGroupItems extends ComponentTestCase<OptionGroup> {
+
+ private static final List<String> cities = Arrays.asList(new String[] {
+ "<i>Berlin</i>", "<b>Brussels</b>", "<u>H</u>elsinki",
+ "<span style='font-size: 20px'>Madrid</span>",
+ "<pre><i>Oslo</i>\nNorway</pre>", "<button>Paris</button>",
+ "<input type='text' value='Stockholm' />" });
+
+ private static final String NULL_SELECTION_ID = cities.get(0);
+
+ @Override
+ protected Class<OptionGroup> getTestClass() {
+ return OptionGroup.class;
+ }
+
+ @Override
+ protected void initializeComponents() {
+
+ OptionGroup og = createOptionGroup("");
+ og.setItemEnabled(cities.get(2), false);
+ og.setItemEnabled(cities.get(5), false);
+ og.setValue(Arrays.asList(cities.get(2)));
+ og.setNullSelectionAllowed(true);
+ og.setNullSelectionItemId(NULL_SELECTION_ID);
+ addTestComponent(og);
+
+ og = createOptionGroup("");
+ og.setMultiSelect(true);
+ og.setHtmlContentAllowed(true);
+ og.setValue(Arrays.asList(cities.get(2)));
+ og.setNullSelectionAllowed(true);
+ og.setItemEnabled(cities.get(2), false);
+ og.setItemEnabled(cities.get(5), false);
+ addTestComponent(og);
+
+ }
+
+ @Override
+ protected void createCustomActions(List<Component> actions) {
+ actions.add(createInvertDisabledItemsAction());
+ actions.add(createToggleSelectionModeAction());
+ actions.add(createInvertHtmlItemsAction());
+ }
+
+ private Component createInvertHtmlItemsAction() {
+ return createButtonAction("Toggle html mode",
+ new Command<OptionGroup, Boolean>() {
+ @Override
+ public void execute(OptionGroup og, Boolean value,
+ Object data) {
+ og.setHtmlContentAllowed(!og.isHtmlContentAllowed());
+ }
+ });
+ }
+
+ private Component createToggleSelectionModeAction() {
+ return createButtonAction("Toggle selection mode",
+ new Command<OptionGroup, Boolean>() {
+
+ public void execute(OptionGroup og, Boolean value,
+ Object data) {
+ if (og.isMultiSelect()) {
+ og.setMultiSelect(false);
+ og.setNullSelectionItemId(NULL_SELECTION_ID);
+ } else {
+ og.setNullSelectionItemId(null);
+ og.setMultiSelect(true);
+ }
+ }
+ });
+ }
+
+ private Component createInvertDisabledItemsAction() {
+ return createButtonAction("Invert disabled items",
+ new Command<OptionGroup, Boolean>() {
+
+ public void execute(OptionGroup c, Boolean value,
+ Object data) {
+ for (Object itemId : c.getItemIds()) {
+ c.setItemEnabled(itemId, !c.isItemEnabled(itemId));
+ }
+ }
+ });
+ }
+
+ private OptionGroup createOptionGroup(String caption) {
+ OptionGroup og = new OptionGroup(caption, cities);
+ og.setImmediate(true);
+ return og;
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Test case for html items in an OptionGroup";
+ }
+}