import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
import java.util.Iterator;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.KeyboardListener;
+import com.google.gwt.user.client.ui.PopupListener;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
* @author mattitahvonen
*
*/
- public class SuggestionPopup extends PopupPanel implements PositionCallback {
+ public class SuggestionPopup extends PopupPanel implements PositionCallback, PopupListener {
private static final int EXTRASPACE = 8;
private static final String Z_INDEX = "30000";
private boolean isPagingEnabled = true;
+ private long lastAutoClosed;
+
SuggestionPopup() {
super(true);
this.menu = new SuggestionMenu();
setStyleName(CLASSNAME + "-suggestpopup");
DOM.setStyleAttribute(getElement(), "zIndex", Z_INDEX);
- Element root = getElement();
+ Element root = getContainerElement();
DOM.setInnerHTML(up, "<span>Prev</span>");
DOM.sinkEvents(up, Event.ONCLICK);
DOM.appendChild(root, down);
DOM.appendChild(root, status);
DOM.setElementProperty(status, "className", CLASSNAME + "-status");
+
+ this.addPopupListener(this);
}
public void showSuggestions(Collection currentSuggestions,
+ totalSuggestions);
setPrevButtonActive(first > 1);
setNextButtonActive(last < totalSuggestions);
+
+ // clear previously fixed width
+ menu.setWidth("");
+ DOM.setStyleAttribute(DOM.getFirstChild(menu.getElement()), "width", "");
+
setPopupPositionAndShow(this);
}
* int)
*/
public void setPosition(int offsetWidth, int offsetHeight) {
- ApplicationConnection.getConsole().log("callback");
// reset menu size and retrieve its "natural"; size
menu.setHeight("");
- menu.setWidth("");
offsetHeight = getOffsetHeight();
- offsetWidth = getOffsetWidth();
int desiredWidth = IFilterSelect.this.getOffsetWidth() - popupOpener.getOffsetWidth();
- if(offsetWidth < desiredWidth) {
+ int w2 = DOM.getElementPropertyInt(DOM.getFirstChild(menu.getElement()), "offsetWidth");
+ if(w2 < desiredWidth) {
menu.setWidth(desiredWidth + "px");
+ DOM.setStyleAttribute(DOM.getFirstChild(menu.getElement()), "width", "100%");
+ w2 = desiredWidth;
+ }
+ if(Util.isIE()) {
+ ApplicationConnection.getConsole().log("perseensuti");
+ DOM.setStyleAttribute(getElement(), "width", w2 + "px");
}
if (!isPagingEnabled && offsetHeight > Window.getClientHeight()) {
setPopupPosition(getPopupLeft(), top);
}
}
+
+ /**
+ * @return true if popup was just closed
+ */
+ public boolean isJustClosed() {
+ long now = (new Date()).getTime();
+ return (lastAutoClosed > 0 && (now - lastAutoClosed) < 200);
+ }
+
+ public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
+ if(autoClosed) {
+ lastAutoClosed = (new Date()).getTime();
+ }
+ }
+
}
public class SuggestionMenu extends MenuBar {
public void setWidth(String width) {
super.setWidth(width);
- if(!width.equals("") || width != null) {
- DOM.setStyleAttribute(DOM.getFirstChild(getElement()), "width", "100%");
- } else {
- DOM.setStyleAttribute(DOM.getFirstChild(getElement()), "width", "");
- }
+// if(width != null && !width.equals("")) {
+// DOM.setStyleAttribute(DOM.getFirstChild(getElement()), "width", "100%");
+// } else {
+// DOM.setStyleAttribute(DOM.getFirstChild(getElement()), "width", "");
+// }
}
}
* Listener for popupopener
*/
public void onClick(Widget sender) {
- filterOptions(0, "");
+ // ask suggestionPopup if it was just closed, we are using GWT Popup's
+ // auto close feature
+ if(!suggestionPopup.isJustClosed()) {
+ filterOptions(0, "");
+ }
tb.setFocus(true);
tb.selectAll();
}