]> source.dussan.org Git - vaadin-framework.git/commitdiff
tooltips for native and list selects
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 6 Jun 2008 14:46:53 +0000 (14:46 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 6 Jun 2008 14:46:53 +0000 (14:46 +0000)
svn changeset:4782/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IListSelect.java
src/com/itmill/toolkit/terminal/gwt/client/ui/INativeSelect.java

index b49cc1c24ac6b45979fd2b3524d7e0b3b6bb9e5a..ccc149a52ef5ac13e3940cebf135da837fb621b3 100644 (file)
@@ -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
index 9d536ba8b33dd15b9858566252eab34cf977f7dc..b011928bf9a3b9950be798bf89f8dd2df79f1aa7 100644 (file)
@@ -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()) {