From fe5af04f3c4dbd05d16a6819df12c1f806809293 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 25 Aug 2011 07:52:01 +0000 Subject: #5608 Item icons do not work in OptionGroup svn changeset:20638/svn branch:6.7 --- WebContent/VAADIN/themes/base/select/select.css | 5 ++ .../terminal/gwt/client/ui/VOptionGroup.java | 43 +++++++++++--- .../optiongroup/OptionGroupItemIcons.html | 67 ++++++++++++++++++++++ .../tests/components/optiongroup/OptionGroups.java | 25 ++++++++ 4 files changed, 133 insertions(+), 7 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/optiongroup/OptionGroupItemIcons.html 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 focusHandlers = null; private List 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 = "\"\"" + 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 @@ + + + + + + +OptionGroupItemIcons + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionGroupItemIcons
open/run/com.vaadin.tests.components.optiongroup.OptionGroups?restartApplication
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::PID_Smenu#item034,8
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[0]/VMenuBar[0]#item136,4
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[1]/VMenuBar[0]#item645,8
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[2]/VMenuBar[0]#item231,10
screenCaptureradio
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::PID_Smenu#item044,11
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[0]/VMenuBar[0]#item431,12
mouseClickvaadin=runcomvaadintestscomponentsoptiongroupOptionGroups::Root/VOverlay[1]/VMenuBar[0]#item179,12
screenCapturecheck
+ + 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 { og.setHtmlContentAllowed(value.booleanValue()); } }); + createIconToggle("Item icons"); + } + + private void createIconToggle(String string) { + LinkedHashMap options = new LinkedHashMap(); + 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() { + 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) { -- cgit v1.2.3