public AriaSuggestBox(AriaTextBox box, SuggestOracle oracle) { iOracle = oracle; iText = box; iText.setStyleName("gwt-SuggestBox"); initWidget(iText); addEventsToTextBox(); iSuggestionMenu = new SuggestionMenu(); iPopupScroll = new ScrollPanel(iSuggestionMenu); iPopupScroll.addStyleName("scroll"); iSuggestionPopup = new PopupPanel(true, false); iSuggestionPopup.setPreviewingAllNativeEvents(true); iSuggestionPopup.setStyleName("unitime-SuggestBoxPopup"); iSuggestionPopup.setWidget(iPopupScroll); iSuggestionPopup.addAutoHidePartner(getElement()); iSuggestionCallback = new SuggestionCallback() { @Override public void onSuggestionSelected(Suggestion suggestion) { if (!suggestion.getReplacementString().isEmpty()) { setStatus(ARIA.suggestionSelected(status(suggestion))); } iCurrentText = suggestion.getReplacementString(); setText(suggestion.getReplacementString()); hideSuggestionList(); fireSuggestionEvent(suggestion); } }; iOracleCallback = new SuggestOracle.Callback() { @Override public void onSuggestionsReady(Request request, Response response) { if (response.getSuggestions() == null || response.getSuggestions().isEmpty()) { if (iSuggestionPopup.isShowing()) iSuggestionPopup.hide(); } else { iSuggestionMenu.clearItems(); SuggestOracle.Suggestion first = null; for (SuggestOracle.Suggestion suggestion: response.getSuggestions()) { iSuggestionMenu.addItem(new SuggestionMenuItem(suggestion)); if (first == null) first = suggestion; } iSuggestionMenu.selectItem(0); ToolBox.setMinWidth(iSuggestionMenu.getElement().getStyle(), (iText.getElement().getClientWidth() - 4) + "px"); iSuggestionPopup.showRelativeTo(iText); iSuggestionMenu.scrollToView(); if (response.getSuggestions().size() == 1) { if (first.getReplacementString().isEmpty()) setStatus(status(first)); else setStatus(ARIA.showingOneSuggestion(status(first))); } else { setStatus(ARIA.showingMultipleSuggestions(response.getSuggestions().size(), request.getQuery(), status(first))); } } } }; Roles.getTextboxRole().setAriaAutocompleteProperty(iText.getElement(), AutocompleteValue.NONE); iSuggestionPopup.getElement().setAttribute("id", DOM.createUniqueId()); Roles.getTextboxRole().setAriaOwnsProperty(iText.getElement(), Id.of(iSuggestionPopup.getElement())); }
public void showSuggestions(String text) { if (text.isEmpty()) iOracle.requestDefaultSuggestions(new Request(null), iOracleCallback); else iOracle.requestSuggestions(new Request(text), iOracleCallback); }
public SuggestCallback(Request request, Callback callback) { iRequest = request; iCallback = callback; }
public void requestRemoteSuggestions(Request request, AsyncCallback<List<T>> callback);