Example usage for com.google.gwt.user.client.ui MenuItem getText

List of usage examples for com.google.gwt.user.client.ui MenuItem getText

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui MenuItem getText.

Prototype

@Override
    public String getText() 

Source Link

Usage

From source file:com.vaadin.terminal.gwt.client.ui.VFilterSelect.java

License:Open Source License

@SuppressWarnings("deprecation")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    paintableId = uidl.getId();//w  w w. ja va2s. c om
    this.client = client;

    readonly = uidl.hasAttribute("readonly");
    enabled = !uidl.hasAttribute("disabled");

    tb.setEnabled(enabled);
    updateReadOnly();

    if (client.updateComponent(this, uidl, true)) {
        return;
    }

    // Inverse logic here to make the default case (text input enabled)
    // work without additional UIDL messages
    boolean noTextInput = uidl.hasAttribute(ATTR_NO_TEXT_INPUT) && uidl.getBooleanAttribute(ATTR_NO_TEXT_INPUT);
    setTextInputEnabled(!noTextInput);

    // not a FocusWidget -> needs own tabindex handling
    if (uidl.hasAttribute("tabindex")) {
        tb.setTabIndex(uidl.getIntAttribute("tabindex"));
    }

    if (uidl.hasAttribute("filteringmode")) {
        filteringmode = uidl.getIntAttribute("filteringmode");
    }

    immediate = uidl.hasAttribute("immediate");

    nullSelectionAllowed = uidl.hasAttribute("nullselect");

    nullSelectItem = uidl.hasAttribute("nullselectitem") && uidl.getBooleanAttribute("nullselectitem");

    currentPage = uidl.getIntVariable("page");

    if (uidl.hasAttribute("pagelength")) {
        pageLength = uidl.getIntAttribute("pagelength");
    }

    if (uidl.hasAttribute(ATTR_INPUTPROMPT)) {
        // input prompt changed from server
        inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT);
    } else {
        inputPrompt = "";
    }

    suggestionPopup.updateStyleNames(uidl);

    allowNewItem = uidl.hasAttribute("allownewitem");
    lastNewItemString = null;

    currentSuggestions.clear();
    if (!waitingForFilteringResponse) {
        /*
         * Clear the current suggestions as the server response always
         * includes the new ones. Exception is when filtering, then we need
         * to retain the value if the user does not select any of the
         * options matching the filter.
         */
        currentSuggestion = null;
        /*
         * Also ensure no old items in menu. Unless cleared the old values
         * may cause odd effects on blur events. Suggestions in menu might
         * not necessary exist in select at all anymore.
         */
        suggestionPopup.menu.clearItems();

    }

    final UIDL options = uidl.getChildUIDL(0);
    if (uidl.hasAttribute("totalMatches")) {
        totalMatches = uidl.getIntAttribute("totalMatches");
    } else {
        totalMatches = 0;
    }

    // used only to calculate minimum popup width
    String captions = Util.escapeHTML(inputPrompt);

    for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) {
        final UIDL optionUidl = (UIDL) i.next();
        final FilterSelectSuggestion suggestion = new FilterSelectSuggestion(optionUidl);
        currentSuggestions.add(suggestion);
        if (optionUidl.hasAttribute("selected")) {
            if (!waitingForFilteringResponse || popupOpenerClicked) {
                String newSelectedOptionKey = Integer.toString(suggestion.getOptionKey());
                if (!newSelectedOptionKey.equals(selectedOptionKey)
                        || suggestion.getReplacementString().equals(tb.getText())) {
                    // Update text field if we've got a new selection
                    // Also update if we've got the same text to retain old
                    // text selection behavior
                    setPromptingOff(suggestion.getReplacementString());
                    selectedOptionKey = newSelectedOptionKey;
                }
            }
            currentSuggestion = suggestion;
            setSelectedItemIcon(suggestion.getIconUri());
        }

        // Collect captions so we can calculate minimum width for textarea
        if (captions.length() > 0) {
            captions += "|";
        }
        captions += Util.escapeHTML(suggestion.getReplacementString());
    }

    if ((!waitingForFilteringResponse || popupOpenerClicked) && uidl.hasVariable("selected")
            && uidl.getStringArrayVariable("selected").length == 0) {
        // select nulled
        if (!waitingForFilteringResponse || !popupOpenerClicked) {
            if (!focused) {
                /*
                 * client.updateComponent overwrites all styles so we must
                 * ALWAYS set the prompting style at this point, even though
                 * we think it has been set already...
                 */
                prompting = false;
                setPromptingOn();
            } else {
                // we have focus in field, prompting can't be set on,
                // instead just clear the input
                tb.setValue("");
            }
        }
        selectedOptionKey = null;
    }

    if (waitingForFilteringResponse && lastFilter.toLowerCase().equals(uidl.getStringVariable("filter"))) {
        suggestionPopup.showSuggestions(currentSuggestions, currentPage, totalMatches);
        waitingForFilteringResponse = false;
        if (!popupOpenerClicked && selectPopupItemWhenResponseIsReceived != Select.NONE) {
            // we're paging w/ arrows
            if (selectPopupItemWhenResponseIsReceived == Select.LAST) {
                suggestionPopup.menu.selectLastItem();
            } else {
                suggestionPopup.menu.selectFirstItem();
            }

            // This is used for paging so we update the keyboard selection
            // variable as well.
            MenuItem activeMenuItem = suggestionPopup.menu.getSelectedItem();
            suggestionPopup.menu.setKeyboardSelectedItem(activeMenuItem);

            // Update text field to contain the correct text
            setTextboxText(activeMenuItem.getText());
            tb.setSelectionRange(lastFilter.length(), activeMenuItem.getText().length() - lastFilter.length());

            selectPopupItemWhenResponseIsReceived = Select.NONE; // reset
        }
        if (updateSelectionWhenReponseIsReceived) {
            suggestionPopup.menu.doPostFilterSelectedItemAction();
        }
    }

    // Calculate minumum textarea width
    suggestionPopupMinWidth = minWidth(captions);

    popupOpenerClicked = false;

    if (!initDone) {
        updateRootWidth();
    }

    // Focus dependent style names are lost during the update, so we add
    // them here back again
    if (focused) {
        addStyleDependentName("focus");
    }

    initDone = true;
}

From source file:com.vaadin.terminal.gwt.client.ui.VTimeoutSelect.java

License:Apache License

@Override
@SuppressWarnings("deprecation")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    paintableId = uidl.getId();//from   w  w  w.j ava2s . c o  m
    this.client = client;

    if (client.updateComponent(this, uidl, true)) {
        return;
    }

    //        listenTextChangeEvents = client.hasEventListeners(this,"ie"); 
    //        if (listenTextChangeEvents) {
    textChangeEventMode = uidl.getStringAttribute(VTextField.ATTR_TEXTCHANGE_EVENTMODE);
    if (textChangeEventMode.equals("EAGER")) {
        textChangeEventTimeout = 1;
    } else {
        textChangeEventTimeout = uidl.getIntAttribute(VTextField.ATTR_TEXTCHANGE_TIMEOUT);
        if (textChangeEventTimeout < 1) {
            // Sanitize and allow lazy/timeout with timeout set to 0 to
            // work as eager
            textChangeEventTimeout = 1;
        }
    }
    listenTextChangeEvents = true;
    tb.sinkEvents(TEXTCHANGE_EVENTS);
    //        }
    readonly = uidl.hasAttribute("readonly");
    enabled = !uidl.hasAttribute("disabled");

    tb.setEnabled(enabled);
    tb.setReadOnly(readonly);

    // not a FocusWidget -> needs own tabindex handling
    if (uidl.hasAttribute("tabindex")) {
        tb.setTabIndex(uidl.getIntAttribute("tabindex"));
    }

    if (uidl.hasAttribute("filteringmode")) {
        filteringmode = uidl.getIntAttribute("filteringmode");
    }

    immediate = uidl.hasAttribute("immediate");

    nullSelectionAllowed = uidl.hasAttribute("nullselect");

    nullSelectItem = uidl.hasAttribute("nullselectitem") && uidl.getBooleanAttribute("nullselectitem");

    currentPage = uidl.getIntVariable("page");

    if (uidl.hasAttribute("pagelength")) {
        pageLength = uidl.getIntAttribute("pagelength");
    }

    if (uidl.hasAttribute(ATTR_INPUTPROMPT)) {
        // input prompt changed from server
        inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT);
    } else {
        inputPrompt = "";
    }

    suggestionPopup.setPagingEnabled(true);
    suggestionPopup.updateStyleNames(uidl);

    allowNewItem = uidl.hasAttribute("allownewitem");
    lastNewItemString = null;

    currentSuggestions.clear();
    if (!filtering) {
        /*
         * Clear the current suggestions as the server response always
         * includes the new ones. Exception is when filtering, then we need
         * to retain the value if the user does not select any of the
         * options matching the filter.
         */
        currentSuggestion = null;
        /*
         * Also ensure no old items in menu. Unless cleared the old values
         * may cause odd effects on blur events. Suggestions in menu might
         * not necessary exist in select at all anymore.
         */
        suggestionPopup.menu.clearItems();

    }

    final UIDL options = uidl.getChildUIDL(0);

    if (uidl.hasAttribute("totalMatches")) {
        totalMatches = uidl.getIntAttribute("totalMatches");
    } else {
        totalMatches = 0;
    }

    String captions = inputPrompt;

    for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) {
        final UIDL optionUidl = (UIDL) i.next();
        final FilterSelectSuggestion suggestion = new FilterSelectSuggestion(optionUidl);
        currentSuggestions.add(suggestion);
        if (optionUidl.hasAttribute("selected")) {
            if (!filtering || popupOpenerClicked) {
                setPromptingOff(suggestion.getReplacementString());
                selectedOptionKey = "" + suggestion.getOptionKey();
            }
            currentSuggestion = suggestion;
            setSelectedItemIcon(suggestion.getIconUri());
        }

        // Collect captions so we can calculate minimum width for textarea
        if (captions.length() > 0) {
            captions += "|";
        }
        captions += suggestion.getReplacementString();
    }

    if ((!filtering || popupOpenerClicked) && uidl.hasVariable("selected")
            && uidl.getStringArrayVariable("selected").length == 0) {
        // select nulled
        if (!filtering || !popupOpenerClicked) {
            if (!focused) {
                /*
                 * client.updateComponent overwrites all styles so we must
                 * ALWAYS set the prompting style at this point, even though
                 * we think it has been set already...
                 */
                prompting = false;
                setPromptingOn();
            } else {
                // we have focus in field, prompting can't be set on,
                // instead just clear the input
                tb.setValue("");
            }
        }
        selectedOptionKey = null;
    }

    if (filtering && lastFilter.toLowerCase().equals(uidl.getStringVariable("filter"))) {
        suggestionPopup.showSuggestions(currentSuggestions, currentPage, totalMatches);
        //            filtering = false;
        if (!popupOpenerClicked && lastIndex != -1) {
            // we're paging w/ arrows
            MenuItem activeMenuItem;
            if (lastIndex == 0) {
                // going up, select last item
                int lastItem = pageLength - 1;
                List<MenuItem> items = suggestionPopup.menu.getItems();
                /*
                 * The first page can contain less than 10 items if the null
                 * selection item is filtered away
                 */
                if (lastItem >= items.size()) {
                    lastItem = items.size() - 1;
                }
                activeMenuItem = items.get(lastItem);
                suggestionPopup.menu.selectItem(activeMenuItem);
            } else {
                // going down, select first item
                activeMenuItem = suggestionPopup.menu.getItems().get(0);
                suggestionPopup.menu.selectItem(activeMenuItem);
            }

            setTextboxText(activeMenuItem.getText());
            tb.setSelectionRange(lastFilter.length(), activeMenuItem.getText().length() - lastFilter.length());

            lastIndex = -1; // reset
        }
        if (selecting) {
            suggestionPopup.menu.doPostFilterSelectedItemAction();
        }
    }

    // Calculate minumum textarea width
    suggestionPopupMinWidth = minWidth(captions);

    popupOpenerClicked = false;

    if (!initDone) {
        updateRootWidth();
    }

    // Focus dependent style names are lost during the update, so we add
    // them here back again
    if (focused) {
        addStyleDependentName("focus");
    }

    initDone = true;
}

From source file:n3phele.client.widgets.WorkspaceVerticalPanel.java

License:Open Source License

protected Hyperlink createHyperlink(MenuItem m) {
    String html = "<img style='border:none; vertical-align:bottom; margin:-2px; padding-right:2px;' width=20 height=20 src='"
            + m.getUrl() + "'/>" + m.getText();
    Hyperlink h = new Hyperlink(html, true, m.getPlaceToken());
    return h;//  w w w .j  av  a2s .  c  o m
}

From source file:org.pentaho.mantle.client.ui.PerspectiveManager.java

License:Open Source License

protected void setPluginPerspectives(final ArrayList<IPluginPerspective> perspectives) {

    this.perspectives = perspectives;

    clear();//  w  w w. j  av a2 s . co  m

    // sort perspectives
    Collections.sort(perspectives, new Comparator<IPluginPerspective>() {
        public int compare(IPluginPerspective o1, IPluginPerspective o2) {
            Integer p1 = new Integer(o1.getLayoutPriority());
            Integer p2 = new Integer(o2.getLayoutPriority());
            return p1.compareTo(p2);
        }
    });

    MenuBar perspectiveMenuBar = new MenuBar(true);
    perspectiveDropDown = new CustomDropDown("", perspectiveMenuBar, MODE.MAJOR);
    setWidget(perspectiveDropDown);
    loadResourceBundle(perspectiveDropDown, perspectives.get(0));

    ScheduledCommand noopCmd = new ScheduledCommand() {
        public void execute() {
        }
    };

    for (final IPluginPerspective perspective : perspectives) {

        // if we have overlays add it to the list
        if (perspective.getOverlays() != null) {
            overlays.addAll(perspective.getOverlays());
        }

        final MenuItem menuItem = new MenuItem("", noopCmd);
        perspectiveMenuItemMap.put(perspective.getId(), menuItem);
        ScheduledCommand cmd = new ScheduledCommand() {
            public void execute() {
                showPerspective(perspective);
                perspectiveDropDown.setText(menuItem.getText());
                perspectiveDropDown.hidePopup();
            }
        };
        menuItem.setScheduledCommand(cmd);
        perspectiveMenuBar.addItem(menuItem);
        loadResourceBundle(menuItem, perspective);
    }

    // register overlays with XulMainToolbar
    MantleXul.getInstance().addOverlays(overlays);

    setPerspective(perspectives.get(0).getId());

    loaded = true;
    EventBusUtil.EVENT_BUS.fireEvent(new PerspectivesLoadedEvent());
}

From source file:org.sakaiproject.sgs2.client.Sgs2.java

License:Educational Community License

private boolean menuBarHasName(Sgs2MenuBar menuBar, String name) {

    List<MenuItem> menuItems = menuBar.getItems();
    for (MenuItem menuItem : menuItems) {
        if (menuItem.getText().equals(name)) {
            return true;
        }// ww  w.  j a  va 2  s.c o m
    }

    return false;
}

From source file:org.vaadin.addons.locationtextfield.client.ui.VLocationTextField.java

License:Apache License

@SuppressWarnings("deprecation")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    boolean firstPaint = (this.client == null);
    paintableId = uidl.getId();/*from   w w  w .  j  ava 2 s.  co  m*/
    this.client = client;

    readonly = uidl.hasAttribute("readonly");
    enabled = !uidl.hasAttribute("disabled");

    tb.setEnabled(enabled);
    updateReadOnly();

    if (client.updateComponent(this, uidl, true)) {
        return;
    }

    // Inverse logic here to make the default case (text input enabled)
    // work without additional UIDL messages
    boolean noTextInput = uidl.hasAttribute(ATTR_NO_TEXT_INPUT) && uidl.getBooleanAttribute(ATTR_NO_TEXT_INPUT);
    setTextInputEnabled(!noTextInput);

    // not a FocusWidget -> needs own tabindex handling
    if (uidl.hasAttribute("tabindex")) {
        tb.setTabIndex(uidl.getIntAttribute("tabindex"));
    }

    immediate = uidl.hasAttribute("immediate");

    /*nullSelectionAllowed = uidl.hasAttribute("nullselect");
            
    nullSelectItem = uidl.hasAttribute("nullselectitem")
        && uidl.getBooleanAttribute("nullselectitem");*/

    currentPage = Math.max(uidl.getIntVariable("page"), 0);

    if (uidl.hasAttribute("pagelength")) {
        pageLength = uidl.getIntAttribute("pagelength");
    }

    textChangeEventMode = uidl.getStringAttribute(ATTR_TEXTCHANGE_EVENTMODE);
    textChangeEventTimeout = uidl.getIntAttribute(ATTR_TEXTCHANGE_TIMEOUT);
    if (textChangeEventTimeout < 1) {
        // Sanitize and allow lazy/timeout with timeout set to 0 to
        // work as eager
        textChangeEventTimeout = 1000;
    }
    sinkEvents(TEXTCHANGE_EVENTS);
    attachCutEventListener(tb.getElement());

    if (uidl.hasAttribute(ATTR_ENTER_KEY_FIRES_TEXT_CHANGE))
        this.enterKeyFiresTextChange = uidl.getBooleanAttribute(ATTR_ENTER_KEY_FIRES_TEXT_CHANGE);

    final String text;
    if (uidl.hasVariable(FILTER) && (firstPaint
            || (uidl.hasAttribute(ATTR_TEXT_CHANGED) && uidl.getBooleanAttribute(ATTR_TEXT_CHANGED)))) {
        // Use value from UIDL if this is the first time the component is
        // painted or if something has changed on the server
        text = uidl.getStringVariable(FILTER);
    } else {
        // Use what we already have if no change from the server
        text = tb.getText();
    }

    if (BrowserInfo.get().isFF3()) {
        /*
         * Firefox 3 is really sluggish when updating input attached to dom.
         * Some optimizations seems to work much better in Firefox3 if we
         * update the actual content lazily when the rest of the DOM has
         * stabilized. In tests, about ten times better performance is
         * achieved with this optimization. See for eg. #2898
         */
        Scheduler.get().scheduleDeferred(new Command() {
            public void execute() {
                /*
                 * Avoid resetting the old value. Prevents cursor flickering
                 * which then again happens due to this Gecko hack.
                 */
                if (!tb.getText().equals(text)) {
                    setTextboxText(text);
                }
            }
        });
    } else {
        if (!tb.getText().equals(text)) {
            setTextboxText(text);
        }
    }

    lastFilter = valueBeforeEdit = text;

    suggestionPopup.setPagingEnabled(true);
    suggestionPopup.updateStyleNames(uidl);

    currentSuggestions.clear();
    /*
     * Clear the current suggestions as the server response always
     * includes the new ones. Exception is when filtering, then we need
     * to retain the value if the user does not select any of the
     * options matching the filter.
     */
    this.currentSuggestion = null;
    /*
     * Also ensure no old items in menu. Unless cleared the old values
     * may cause odd effects on blur events. Suggestions in menu might
     * not necessary exist in select at all anymore.
     */
    suggestionPopup.menu.clearItems();

    final UIDL options = uidl.getChildUIDL(0);
    if (uidl.hasAttribute("totalMatches")) {
        totalMatches = uidl.getIntAttribute("totalMatches");
    }

    // used only to calculate minimum popup width
    String captions = "";

    for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) {
        final UIDL optionUidl = (UIDL) i.next();
        final FilterSelectSuggestion suggestion = new FilterSelectSuggestion(optionUidl);
        currentSuggestions.add(suggestion);
        if (optionUidl.hasAttribute("selected")) {
            VConsole.log("popupOpenerClicked " + popupOpenerClicked);
            //if (popupOpenerClicked) {
            String newSelectedOptionKey = Integer.toString(suggestion.getOptionKey());
            if (!newSelectedOptionKey.equals(selectedOptionKey)
                    || suggestion.getReplacementString().equals(tb.getText())) {
                // Update text field if we've got a new selection
                // Also update if we've got the same text to retain old
                // text selection behavior
                setTextboxText(suggestion.getReplacementString());
                selectedOptionKey = newSelectedOptionKey;
            }
            //}
            currentSuggestion = suggestion;
            setSelectedItemIcon(suggestion.getIconUri());
        }

        // Collect captions so we can calculate minimum width for textarea
        if (captions.length() > 0) {
            captions += "|";
        }
        captions += Util.escapeHTML(suggestion.getReplacementString());
    }

    if ((popupOpenerClicked) && uidl.hasVariable("selected")
            && uidl.getStringArrayVariable("selected").length == 0) {
        VConsole.log("select nulled");
        // select nulled
        selectedOptionKey = null;
    }

    suggestionPopup.showSuggestions(currentSuggestions, currentPage, totalMatches);
    VConsole.log("showing suggestions");
    if (!popupOpenerClicked && lastIndex != -1) {
        // we're paging w/ arrows
        VConsole.log("pagin with arrows");
        MenuItem activeMenuItem;
        if (lastIndex == 0) {
            // going up, select last item
            int lastItem = pageLength - 1;
            List<MenuItem> items = suggestionPopup.menu.getItems();
            /*
             * The first page can contain less than 10 items if the null
             * selection item is filtered away
             */
            if (lastItem >= items.size()) {
                lastItem = items.size() - 1;
            }
            activeMenuItem = items.get(lastItem);
            suggestionPopup.menu.selectItem(activeMenuItem);
        } else {
            // going down, select first item
            VConsole.log("select first item");
            activeMenuItem = suggestionPopup.menu.getItems().get(0);
            suggestionPopup.menu.selectItem(activeMenuItem);
        }

        setTextboxText(activeMenuItem.getText());
        tb.setSelectionRange(lastFilter.length(),
                Math.abs(activeMenuItem.getText().length() - lastFilter.length()));

        lastIndex = -1; // reset
    }
    //TODO: is this necessary?
    if (currentSuggestion != null)
        suggestionPopup.menu.doPostFilterSelectedItemAction();

    // Calculate minumum textarea width
    suggestionPopupMinWidth = minWidth(captions);

    popupOpenerClicked = false;

    if (!initDone) {
        updateRootWidth();
    }

    // Focus dependent style names are lost during the update, so we add
    // them here back again
    if (focused) {
        addStyleDependentName("focus");
    }

    initDone = true;
}

From source file:org.vaadin.addons.locationtextfield.client.ui.VLocationTextField2.java

License:Apache License

@SuppressWarnings("deprecation")
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    boolean firstPaint = this.client == null;
    this.paintableId = uidl.getId();
    this.client = client;

    readonly = uidl.hasAttribute("readonly");
    enabled = !uidl.hasAttribute("disabled");

    tb.setEnabled(enabled);//from   w  w w .j  a  v  a  2s. c  o m
    updateReadOnly();

    if (client.updateComponent(this, uidl, true)) {
        return;
    }

    this.enableDebug = uidl.getBooleanAttribute(ATTR_DEBUG_ENABLED);

    // Inverse logic here to make the default case (text input enabled)
    // work without additional UIDL messages
    boolean noTextInput = uidl.hasAttribute(ATTR_NO_TEXT_INPUT) && uidl.getBooleanAttribute(ATTR_NO_TEXT_INPUT);
    setTextInputEnabled(!noTextInput);

    // not a FocusWidget -> needs own tabindex handling
    if (uidl.hasAttribute("tabindex")) {
        tb.setTabIndex(uidl.getIntAttribute("tabindex"));
    }

    immediate = uidl.hasAttribute("immediate");

    nullSelectionAllowed = uidl.hasAttribute("nullselect");

    nullSelectItem = uidl.hasAttribute("nullselectitem") && uidl.getBooleanAttribute("nullselectitem");

    currentPage = uidl.getIntVariable("page");

    if (uidl.hasAttribute("pagelength")) {
        pageLength = uidl.getIntAttribute("pagelength");
    }

    handleTextUpdate(uidl);

    if (uidl.hasAttribute(ATTR_INPUTPROMPT)) {
        // input prompt changed from server
        inputPrompt = uidl.getStringAttribute(ATTR_INPUTPROMPT);
    } else {
        inputPrompt = "";
    }

    suggestionPopup.updateStyleNames(uidl);

    currentSuggestions.clear();

    /*
     * Clear the current suggestions as the server response always
     * includes the new ones. Exception is when filtering, then we need
     * to retain the value if the user does not select any of the
     * options matching the filter.
     */
    currentSuggestion = null;
    /*
     * Also ensure no old items in menu. Unless cleared the old values
     * may cause odd effects on blur events. Suggestions in menu might
     * not necessary exist in select at all anymore.
     */
    suggestionPopup.menu.clearItems();

    final UIDL options = uidl.getChildUIDL(0);
    if (uidl.hasAttribute("totalMatches")) {
        totalMatches = uidl.getIntAttribute("totalMatches");
    } else {
        totalMatches = 0;
    }

    // used only to calculate minimum popup width
    String captions = Util.escapeHTML(inputPrompt);

    for (final Iterator<?> i = options.getChildIterator(); i.hasNext();) {
        final UIDL optionUidl = (UIDL) i.next();
        final FilterSelectSuggestion suggestion = new FilterSelectSuggestion(optionUidl);
        currentSuggestions.add(suggestion);
        if (optionUidl.hasAttribute("selected")) {
            if (popupOpenerClicked) {
                String newSelectedOptionKey = Integer.toString(suggestion.getOptionKey());
                if (!newSelectedOptionKey.equals(selectedOptionKey)
                        || suggestion.getReplacementString().equals(tb.getText())) {
                    // Update text field if we've got a new selection
                    // Also update if we've got the same text to retain old
                    // text selection behavior
                    setPromptingOff(suggestion.getReplacementString());
                    selectedOptionKey = newSelectedOptionKey;
                }
            }
            currentSuggestion = suggestion;
            setSelectedItemIcon(suggestion.getIconUri());
        }

        // Collect captions so we can calculate minimum width for textarea
        if (captions.length() > 0) {
            captions += "|";
        }
        captions += Util.escapeHTML(suggestion.getReplacementString());
    }

    if (popupOpenerClicked && uidl.hasVariable("selected")
            && uidl.getStringArrayVariable("selected").length == 0) {
        // select nulled

        setSelectedItemIcon(null);
        selectedOptionKey = null;
    } else if (!popupOpenerClicked) {
        if (!focused) {
            /*
            * client.updateComponent overwrites all styles so we must
            * ALWAYS set the prompting style at this point, even though
            * we think it has been set already...
            */
            prompting = false;
            setPromptingOn();
        } else {
            // we have focus in field, prompting can't be set on,
            // instead just clear the input
            //tb.setValue("");
        }
    }

    suggestionPopup.showSuggestions(currentSuggestions, currentPage, totalMatches);
    if (!popupOpenerClicked && selectPopupItemWhenResponseIsReceived != Select.NONE) {
        // we're paging w/ arrows
        if (selectPopupItemWhenResponseIsReceived == Select.LAST) {
            suggestionPopup.menu.selectLastItem();
        } else {
            suggestionPopup.menu.selectFirstItem();
        }

        // This is used for paging so we update the keyboard selection
        // variable as well.
        MenuItem activeMenuItem = suggestionPopup.menu.getSelectedItem();
        suggestionPopup.menu.setKeyboardSelectedItem(activeMenuItem);

        // Update text field to contain the correct text
        setTextboxText(activeMenuItem.getText());
        tb.setSelectionRange(lastFilter.length(), activeMenuItem.getText().length() - lastFilter.length());

        selectPopupItemWhenResponseIsReceived = Select.NONE; // reset
    }
    if (currentSuggestion != null) {
        suggestionPopup.menu.doPostFilterSelectedItemAction();
    }

    // Calculate minumum textarea width
    suggestionPopupMinWidth = minWidth(captions);

    popupOpenerClicked = false;

    if (!initDone) {
        updateRootWidth();
    }

    // Popup opener width may have changed due to a style change (#8801)
    if (!readonly && popupWidth != Util.getRequiredWidth(popupOpener)) {
        popupWidth = Util.getRequiredWidth(popupOpener);
        updateRootWidth();
    }

    // Focus dependent style names are lost during the update, so we add
    // them here back again
    if (focused) {
        addStyleDependentName("focus");
    }

    initDone = true;

    // Work-around for a display bug where, if the field's value is set before the first paint the popup menu does not open in
    // the correct location in certain layouts (e.g. GridLayout).  Simply refreshing what we already have fixes the problem.
    if (firstPaint) {
        this.client.updateVariable(this.paintableId, FILTER, this.lastFilter, false);
        this.client.updateVariable(this.paintableId, "page", this.currentPage, true);
    }
}