import com.google.gwt.event.dom.client.ClickEvent;\r
import com.google.gwt.event.dom.client.FocusEvent;\r
import com.google.gwt.event.dom.client.FocusHandler;\r
+import com.google.gwt.event.dom.client.LoadEvent;\r
+import com.google.gwt.event.dom.client.LoadHandler;\r
import com.google.gwt.event.shared.HandlerRegistration;\r
import com.google.gwt.user.client.Command;\r
+import com.google.gwt.user.client.Element;\r
import com.google.gwt.user.client.ui.CheckBox;\r
import com.google.gwt.user.client.ui.FocusWidget;\r
import com.google.gwt.user.client.ui.Focusable;\r
import com.google.gwt.user.client.ui.RadioButton;\r
import com.google.gwt.user.client.ui.Widget;\r
import com.vaadin.terminal.gwt.client.ApplicationConnection;\r
+import com.vaadin.terminal.gwt.client.BrowserInfo;\r
import com.vaadin.terminal.gwt.client.EventId;\r
import com.vaadin.terminal.gwt.client.UIDL;\r
+import com.vaadin.terminal.gwt.client.Util;\r
\r
public class VOptionGroup extends VOptionGroupBase implements FocusHandler,\r
BlurHandler {\r
private List<HandlerRegistration> focusHandlers = null;\r
private List<HandlerRegistration> blurHandlers = null;\r
\r
+ private final LoadHandler iconLoadHandler = new LoadHandler() {\r
+ public void onLoad(LoadEvent event) {\r
+ if (BrowserInfo.get().isIE6()) {\r
+ Util.doIE6PngFix((Element) Element.as(event.getNativeEvent()\r
+ .getEventTarget()));\r
+ }\r
+ Util.notifyParentOfSizeChange(VOptionGroup.this, true);\r
+ }\r
+ };\r
+\r
/**\r
* used to check whether a blur really was a blur of the complete\r
* optiongroup: if a control inside this optiongroup gains focus right after\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
+\r
+ String itemHtml = opUidl.getStringAttribute("caption");\r
+ if (!htmlContentAllowed) {\r
+ itemHtml = Util.escapeHTML(itemHtml);\r
+ }\r
+\r
+ String icon = opUidl.getStringAttribute("icon");\r
+ if (icon != null && icon.length() != 0) {\r
+ String iconUrl = client.translateVaadinUri(icon);\r
+ itemHtml = "<img src=\"" + iconUrl + "\" class=\""\r
+ + Icon.CLASSNAME + "\" alt=\"\" />" + itemHtml;\r
+ }\r
+\r
if (isMultiselect()) {\r
op = new VCheckBox();\r
- if (htmlContentAllowed) {\r
- op.setHTML(caption);\r
- } else {\r
- op.setText(caption);\r
- }\r
+ op.setHTML(itemHtml);\r
} else {\r
- op = new RadioButton(id, caption, htmlContentAllowed);\r
+ op = new RadioButton(id, itemHtml, true);\r
op.setStyleName("v-radiobutton");\r
}\r
+\r
+ if (icon != null && icon.length() != 0) {\r
+ Util.sinkOnloadForImages(op.getElement());\r
+ op.addHandler(iconLoadHandler, LoadEvent.getType());\r
+ }\r
+\r
op.addStyleName(CLASSNAME_OPTION);\r
op.setValue(opUidl.getBooleanAttribute("selected"));\r
boolean enabled = !opUidl.getBooleanAttribute("disabled")\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="" />
+<title>OptionGroupItemIcons</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">OptionGroupItemIcons</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.optiongroup.OptionGroups?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::PID_Smenu#item0</td>
+ <td>34,8</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[0]/VMenuBar[0]#item1</td>
+ <td>36,4</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[1]/VMenuBar[0]#item6</td>
+ <td>45,8</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[2]/VMenuBar[0]#item2</td>
+ <td>31,10</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>radio</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::PID_Smenu#item0</td>
+ <td>44,11</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[0]/VMenuBar[0]#item4</td>
+ <td>31,12</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[1]/VMenuBar[0]#item1</td>
+ <td>79,12</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>check</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
package com.vaadin.tests.components.optiongroup;\r
\r
+import java.util.Collection;\r
+import java.util.LinkedHashMap;\r
+\r
+import com.vaadin.terminal.ThemeResource;\r
import com.vaadin.tests.components.select.AbstractSelectTestCase;\r
import com.vaadin.ui.OptionGroup;\r
\r
og.setHtmlContentAllowed(value.booleanValue());\r
}\r
});\r
+ createIconToggle("Item icons");\r
+ }\r
+\r
+ private void createIconToggle(String string) {\r
+ LinkedHashMap<String, ThemeResource> options = new LinkedHashMap<String, ThemeResource>();\r
+ options.put("-", null);\r
+ options.put("16x16", ICON_16_USER_PNG_CACHEABLE);\r
+ options.put("32x32", ICON_32_ATTENTION_PNG_CACHEABLE);\r
+ options.put("64x64", ICON_64_EMAIL_REPLY_PNG_CACHEABLE);\r
+\r
+ createSelectAction(string, CATEGORY_DECORATIONS, options, options\r
+ .keySet().iterator().next(),\r
+ new Command<OptionGroup, ThemeResource>() {\r
+ public void execute(OptionGroup c, ThemeResource icon,\r
+ Object data) {\r
+ Collection<?> itemIds = c.getItemIds();\r
+ for (Object itemId : itemIds) {\r
+ c.setItemIcon(itemId, icon);\r
+ }\r
+ }\r
+ });\r
}\r
\r
private void createDisabledItemsMultiToggle(String category) {\r