1 16 package com.google.gwt.user.client.ui.impl; 17 18 import com.google.gwt.user.client.Window; 19 import com.google.gwt.user.client.ui.ChangeListener; 20 import com.google.gwt.user.client.ui.HasFocus; 21 import com.google.gwt.user.client.ui.PopupPanel; 22 import com.google.gwt.user.client.ui.UIObject; 23 import com.google.gwt.user.client.ui.Widget; 24 25 29 public class ItemPickerDropDownImpl extends PopupPanel { 30 private final AbstractItemPickerImpl picker; 31 private final HasFocus owner; 32 33 public ItemPickerDropDownImpl(final HasFocus owner, AbstractItemPickerImpl picker) { 34 super(true); 35 setWidget(picker); 36 this.picker = picker; 37 this.owner = owner; 38 39 picker.addChangeListener(new ChangeListener() { 40 public void onChange(Widget sender) { 41 hide(); 42 } 43 }); 44 } 45 46 50 public void show() { 51 showBelow((UIObject) owner); 52 } 53 54 65 public void showBelow(UIObject showBelow) { 66 if (picker.getItemCount() == 0) { 68 hide(); 69 return; 70 } 71 72 picker.setSelectedIndex(0); 74 75 super.show(); 79 80 int left = showBelow.getAbsoluteLeft(); 82 int windowRight = Window.getClientWidth() + Window.getScrollLeft(); 83 int overshootLeft = Math.max(0, (left + getOffsetWidth()) - windowRight); 84 left = left - overshootLeft; 85 86 int top = showBelow.getAbsoluteTop() + showBelow.getOffsetHeight(); 88 int windowBottom = Window.getScrollTop() + Window.getClientHeight(); 89 int overshootTop = Math.max(0, (top + getOffsetHeight()) - windowBottom); 90 top = top - overshootTop; 91 92 setPopupPosition(left, top); 94 super.show(); 95 } 96 } 97 | Popular Tags |