From: Matti Tahvonen Date: Fri, 6 Jun 2008 14:46:53 +0000 (+0000) Subject: tooltips for native and list selects X-Git-Tag: 6.7.0.beta1~4647 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9da099bd32f9f89c0fe8f1ee18a6a9a182d9fe1c;p=vaadin-framework.git tooltips for native and list selects svn changeset:4782/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java index b49cc1c24a..ccc149a52e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java @@ -10,6 +10,8 @@ import java.util.Vector; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; +import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection; +import com.itmill.toolkit.terminal.gwt.client.Paintable; import com.itmill.toolkit.terminal.gwt.client.Tooltip; import com.itmill.toolkit.terminal.gwt.client.UIDL; @@ -19,28 +21,14 @@ public class IListSelect extends IOptionGroupBase { private static final int VISIBLE_COUNT = 10; - protected ListBox select; + protected TooltipListBox select; private int lastSelectedIndex = -1; - private class MyListBox extends ListBox { - MyListBox() { - super(); - sinkEvents(Tooltip.TOOLTIP_EVENTS); - } - - public void onBrowserEvent(Event event) { - super.onBrowserEvent(event); - if (client != null) { - client.handleTooltipEvent(event, IListSelect.this); - } - } - } - public IListSelect() { - // TODO use myListBox to have Tooltips - super(new ListBox(), CLASSNAME); - select = (ListBox) optionsContainer; + super(new TooltipListBox(true), CLASSNAME); + select = (TooltipListBox) optionsContainer; + select.setSelect(this); select.addChangeListener(this); select.addClickListener(this); select.setStyleName(CLASSNAME + "-select"); @@ -48,6 +36,7 @@ public class IListSelect extends IOptionGroupBase { } protected void buildOptions(UIDL uidl) { + select.setClient(client); select.setMultipleSelect(isMultiselect()); select.setEnabled(!isDisabled() && !isReadonly()); select.clear(); @@ -106,3 +95,32 @@ public class IListSelect extends IOptionGroupBase { } } + +/** + * Extended ListBox to listen tooltip events and forward them to generic + * handler. + */ +class TooltipListBox extends ListBox { + private ApplicationConnection client; + private Paintable pntbl; + + TooltipListBox(boolean isMultiselect) { + super(isMultiselect); + sinkEvents(Tooltip.TOOLTIP_EVENTS); + } + + public void setClient(ApplicationConnection client) { + this.client = client; + } + + public void setSelect(Paintable s) { + pntbl = s; + } + + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + if (client != null) { + client.handleTooltipEvent(event, pntbl); + } + } +} \ No newline at end of file diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java index 9d536ba8b3..b011928bf9 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java @@ -7,7 +7,6 @@ package com.itmill.toolkit.terminal.gwt.client.ui; import java.util.Iterator; import java.util.Vector; -import com.google.gwt.user.client.ui.ListBox; import com.google.gwt.user.client.ui.Widget; import com.itmill.toolkit.terminal.gwt.client.UIDL; @@ -15,11 +14,12 @@ public class INativeSelect extends IOptionGroupBase implements Field { public static final String CLASSNAME = "i-select"; - protected ListBox select; + protected TooltipListBox select; public INativeSelect() { - super(new ListBox(false), CLASSNAME); - select = (ListBox) optionsContainer; + super(new TooltipListBox(false), CLASSNAME); + select = (TooltipListBox) optionsContainer; + select.setSelect(this); select.setVisibleItemCount(1); select.addChangeListener(this); select.setStyleName(CLASSNAME + "-select"); @@ -27,6 +27,7 @@ public class INativeSelect extends IOptionGroupBase implements Field { } protected void buildOptions(UIDL uidl) { + select.setClient(client); select.setEnabled(!isDisabled() && !isReadonly()); select.clear(); if (isNullSelectionAllowed() && !isNullSelectionItemAvailable()) {