aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2011-08-25 07:52:01 +0000
committerLeif Åstrand <leif@vaadin.com>2011-08-25 07:52:01 +0000
commitfe5af04f3c4dbd05d16a6819df12c1f806809293 (patch)
treee341f51c8142ee63c48d37716294280d7bc44b9d
parent6bf025cca40b76ed53472c2506ead508088b99bb (diff)
downloadvaadin-framework-fe5af04f3c4dbd05d16a6819df12c1f806809293.tar.gz
vaadin-framework-fe5af04f3c4dbd05d16a6819df12c1f806809293.zip
#5608 Item icons do not work in OptionGroup
svn changeset:20638/svn branch:6.7
-rw-r--r--WebContent/VAADIN/themes/base/select/select.css5
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java43
-rw-r--r--tests/src/com/vaadin/tests/components/optiongroup/OptionGroupItemIcons.html67
-rw-r--r--tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java25
4 files changed, 133 insertions, 7 deletions
diff --git a/WebContent/VAADIN/themes/base/select/select.css b/WebContent/VAADIN/themes/base/select/select.css
index 3214d4eb2f..3c515b8c52 100644
--- a/WebContent/VAADIN/themes/base/select/select.css
+++ b/WebContent/VAADIN/themes/base/select/select.css
@@ -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;
}
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
index 828a10399e..e524d4ed9a 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VOptionGroup.java
@@ -16,8 +16,11 @@ import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
+import com.google.gwt.event.dom.client.LoadEvent;
+import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Focusable;
@@ -25,8 +28,10 @@ import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.BrowserInfo;
import com.vaadin.terminal.gwt.client.EventId;
import com.vaadin.terminal.gwt.client.UIDL;
+import com.vaadin.terminal.gwt.client.Util;
public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
BlurHandler {
@@ -44,6 +49,16 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
private List<HandlerRegistration> focusHandlers = null;
private List<HandlerRegistration> blurHandlers = null;
+ private final LoadHandler iconLoadHandler = new LoadHandler() {
+ public void onLoad(LoadEvent event) {
+ if (BrowserInfo.get().isIE6()) {
+ Util.doIE6PngFix((Element) Element.as(event.getNativeEvent()
+ .getEventTarget()));
+ }
+ Util.notifyParentOfSizeChange(VOptionGroup.this, true);
+ }
+ };
+
/**
* used to check whether a blur really was a blur of the complete
* optiongroup: if a control inside this optiongroup gains focus right after
@@ -107,18 +122,32 @@ public class VOptionGroup extends VOptionGroupBase implements FocusHandler,
for (final Iterator<?> it = uidl.getChildIterator(); it.hasNext();) {
final UIDL opUidl = (UIDL) it.next();
CheckBox op;
- String caption = opUidl.getStringAttribute("caption");
+
+ String itemHtml = opUidl.getStringAttribute("caption");
+ if (!htmlContentAllowed) {
+ itemHtml = Util.escapeHTML(itemHtml);
+ }
+
+ String icon = opUidl.getStringAttribute("icon");
+ if (icon != null && icon.length() != 0) {
+ String iconUrl = client.translateVaadinUri(icon);
+ itemHtml = "<img src=\"" + iconUrl + "\" class=\""
+ + Icon.CLASSNAME + "\" alt=\"\" />" + itemHtml;
+ }
+
if (isMultiselect()) {
op = new VCheckBox();
- if (htmlContentAllowed) {
- op.setHTML(caption);
- } else {
- op.setText(caption);
- }
+ op.setHTML(itemHtml);
} else {
- op = new RadioButton(id, caption, htmlContentAllowed);
+ op = new RadioButton(id, itemHtml, true);
op.setStyleName("v-radiobutton");
}
+
+ if (icon != null && icon.length() != 0) {
+ Util.sinkOnloadForImages(op.getElement());
+ op.addHandler(iconLoadHandler, LoadEvent.getType());
+ }
+
op.addStyleName(CLASSNAME_OPTION);
op.setValue(opUidl.getBooleanAttribute("selected"));
boolean enabled = !opUidl.getBooleanAttribute("disabled")
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
index 0000000000..978d911a2d
--- /dev/null
+++ b/tests/src/com/vaadin/tests/components/optiongroup/OptionGroupItemIcons.html
@@ -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>
diff --git a/tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java b/tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java
index 07dee0ad0c..1e752e7c26 100644
--- a/tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java
+++ b/tests/src/com/vaadin/tests/components/optiongroup/OptionGroups.java
@@ -1,5 +1,9 @@
package com.vaadin.tests.components.optiongroup;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+
+import com.vaadin.terminal.ThemeResource;
import com.vaadin.tests.components.select.AbstractSelectTestCase;
import com.vaadin.ui.OptionGroup;
@@ -22,6 +26,27 @@ public class OptionGroups extends AbstractSelectTestCase<OptionGroup> {
og.setHtmlContentAllowed(value.booleanValue());
}
});
+ createIconToggle("Item icons");
+ }
+
+ private void createIconToggle(String string) {
+ LinkedHashMap<String, ThemeResource> options = new LinkedHashMap<String, ThemeResource>();
+ options.put("-", null);
+ options.put("16x16", ICON_16_USER_PNG_CACHEABLE);
+ options.put("32x32", ICON_32_ATTENTION_PNG_CACHEABLE);
+ options.put("64x64", ICON_64_EMAIL_REPLY_PNG_CACHEABLE);
+
+ createSelectAction(string, CATEGORY_DECORATIONS, options, options
+ .keySet().iterator().next(),
+ new Command<OptionGroup, ThemeResource>() {
+ public void execute(OptionGroup c, ThemeResource icon,
+ Object data) {
+ Collection<?> itemIds = c.getItemIds();
+ for (Object itemId : itemIds) {
+ c.setItemIcon(itemId, icon);
+ }
+ }
+ });
}
private void createDisabledItemsMultiToggle(String category) {