]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5608 Item icons do not work in OptionGroup
authorLeif Åstrand <leif@vaadin.com>
Thu, 25 Aug 2011 07:52:01 +0000 (07:52 +0000)
committerLeif Åstrand <leif@vaadin.com>
Thu, 25 Aug 2011 07:52:01 +0000 (07:52 +0000)
svn changeset:20638/svn branch:6.7

WebContent/VAADIN/themes/base/select/select.css
src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
tests/src/com/vaadin/tests/components/optiongroup/OptionGroupItemIcons.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java

index 3214d4eb2fa52dc86ed91652680959f9a1b59262..3c515b8c523a86ba2668cb93c84270a2834b38d9 100644 (file)
@@ -5,6 +5,11 @@
        display: block;
        white-space: nowrap;
 }
+.v-select-optiongroup .v-icon {
+       vertical-align: middle;
+       white-space: nowrap;
+       margin: 0 2px;  
+}
 .v-ie .v-select-optiongroup .v-select-option {
        zoom: 1;
 }
index 828a10399ef52607d5e104d4af3cb9609ff8812c..e524d4ed9ada185552846b8767969d80f53cf052 100644 (file)
@@ -16,8 +16,11 @@ import com.google.gwt.event.dom.client.BlurHandler;
 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
@@ -25,8 +28,10 @@ import com.google.gwt.user.client.ui.Panel;
 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
@@ -44,6 +49,16 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
     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
@@ -107,18 +122,32 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
         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
diff --git a/tests/src/com/vaadin/tests/components/optiongroup/OptionGroupItemIcons.html b/tests/src/com/vaadin/tests/components/optiongroup/OptionGroupItemIcons.html
new file mode 100644 (file)
index 0000000..978d911
--- /dev/null
@@ -0,0 +1,67 @@
+<?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>
index 07dee0ad0cdc0cce9197c53cac2a05f99116ce41..1e752e7c26c2df62ea17a20ca9c9f1a99939fb52 100644 (file)
@@ -1,5 +1,9 @@
 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
@@ -22,6 +26,27 @@ public class OptionGroups extends AbstractSelectTestCase<OptionGroup> {
                         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