EnumEditorViewImpl(final List<String> enumValues, final List<String> enumDescriptions) { // Sets up a SuggestOracle that, when the textbox has focus, displays the // valid enum values and their descriptions. MultiWordSuggestOracle oracle = new MultiWordSuggestOracle(); List<Suggestion> suggestions = Lists.newArrayList(); for (int i = 0; i < enumValues.size(); i++) { suggestions.add(new EnumSuggestion( enumValues.get(i), enumDescriptions == null ? "" : enumDescriptions.get(i))); } oracle.setDefaultSuggestions(suggestions); this.suggestBox = new SuggestBox(oracle); suggestBox.getTextBox().addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { suggestBox.showSuggestionList(); } }); add(suggestBox); this.errorMessage = new Label("This parameter is invalid."); errorMessage.setVisible(false); add(errorMessage); }
@Test public void testAsyncOptionSelectedFromBootstrap() throws Exception { CapturingConfiguration config = new CapturingConfiguration(); Session sess = createSession(config); List<Object> args = new ArrayList<Object>(); args.add("M"); CommandBuilder cb = new CommandBuilder(sess, "SELECT x.id FROM Person x WHERE sex = ?", args); RootPanel.get().add(cb); Select s = cb.getSelect(); // only now give them the enumeration Collection<Suggestion> s2 = new ArrayList(); s2.add(new MultiWordSuggestion("M", "M")); s2.add(new MultiWordSuggestion("F", "F")); config.getEnumerateCallback().onSuccess(new Response(s2)); Comparison c = (Comparison) s.getCondition(); Parameter p = (Parameter) c.getRight(); SelectEditorWidget sew = (SelectEditorWidget) p.getEditorWidget(); assertEquals("M", sew.getValue()); }
private SuggestionMenuItem(final Suggestion suggestion) { super(suggestion.getDisplayString(), iOracle.isDisplayStringHTML(), new ScheduledCommand() { @Override public void execute() { iSuggestionCallback.onSuggestionSelected(suggestion); } }); setStyleName("item"); getElement().setAttribute("whiteSpace", "nowrap"); iSuggestion = suggestion; }
public void onFailure(final Throwable caught) { iValidCourseNames.clear(); final ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); if (iFreeTimeParser != null) { iFreeTimeParser.getData(iRequest.getQuery(), new AsyncCallback<List<FreeTime>>() { @Override public void onFailure(Throwable e) { if (iRequest.getQuery().toLowerCase().startsWith(CONSTANTS.freePrefix().toLowerCase())) { suggestions.add(new SimpleSuggestion(e)); // setStatus(e.getMessage()); } else { suggestions.add(new SimpleSuggestion(caught)); // setStatus(caught.getMessage()); } } @Override public void onSuccess(List<FreeTime> freeTimes) { suggestions.add(new SimpleSuggestion(freeTimes)); } }); } else { suggestions.add(new SimpleSuggestion(caught)); // setStatus(caught.getMessage()); } iCallback.onSuggestionsReady(iRequest, new Response(suggestions)); }
public void onSuccess(Collection<ClassAssignmentInterface.CourseAssignment> result) { ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); iValidCourseNames.clear(); for (ClassAssignmentInterface.CourseAssignment course: result) { SimpleSuggestion suggestion = new SimpleSuggestion(course, iShowCourses); suggestions.add(suggestion); iValidCourseNames.put(suggestion.getReplacementString().toLowerCase(), suggestion.getRequestedCourse()); } iCallback.onSuggestionsReady(iRequest, new Response(suggestions)); }
public void onSuccess(List<String[]> result) { ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); for (String[] suggestion: result) { suggestions.add(new SimpleSuggestion(suggestion[1], suggestion[0])); } iCallback.onSuggestionsReady(iRequest, new Response(suggestions)); }
private void setHandlerForSuggestBox(final SuggestBox suggestBox) { suggestBox.addSelectionHandler(new SelectionHandler<Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> arg0) { String value = suggestBox.getText(); for (int i = 0; i < documentTypes.getItemCount(); i++) { if (documentTypes.getItemText(i).equalsIgnoreCase(value)) { ScreenMaskUtility.maskScreen(); onDocumentTypeChange(documentTypes.getValue(i)); break; } } } }); validatableSuggestBox = new ValidatableWidget<SuggestBox>(suggestBox); validatableSuggestBox.getWidget().addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { validatableSuggestBox.toggleValidDateBox(); } }); List<String> altValues = new ArrayList<String>(); for (int i = 0; i < documentTypes.getItemCount(); i++) { altValues.add(documentTypes.getItemText(i)); } validatableSuggestBox.addValidator(new SuggestBoxValidator(suggestBox, altValues)); validatableSuggestBox.toggleValidDateBox(); }
@Override public void requestSuggestions(final Request request, final Callback callback) { if (geocoderProxy == null) return; geocoderProxy.geocode(request.getQuery(), new GeocoderListener() { @Override public void onGeocodingDone(List<LocationBean> locations) { Response response = new Response(); List<Suggestion> suggestions = new ArrayList<Suggestion>(); if (locations != null) { int n = 0; for (LocationBean location : locations) { if (n >= request.getLimit()) break; suggestions.add( new GeocodedAddressSuggestion(location)); n++; } if (locations.size() > n) response.setMoreSuggestionsCount( locations.size() - n); } response.setSuggestions(suggestions); callback.onSuggestionsReady(request, response); } }); }
@Override protected void showSuggestions(SuggestBox suggestBox, Collection<? extends Suggestion> suggestions, boolean isDisplayStringHTML, boolean isAutoSelectEnabled, SuggestionCallback callback) { getPopupPanel().getWidget().setWidth(suggestBox.getElement().getScrollWidth() + Unit.PX.getType()); getPopupPanel().getWidget().getElement().getStyle().setProperty("maxHeight", Math.max(DISPLAY_BOX_MIN_HEIGHT, suggestBox.getElement().getAbsoluteTop() - DISPLAY_BOX_TOP_PADDING) + Unit.PX.getType()); super.showSuggestions(suggestBox, suggestions, isDisplayStringHTML, isAutoSelectEnabled, callback); if (isSuggestionListShowing()) { popupHideTimer.cancel(); paletteShouldIgnoreMouseClicks = true; } }
private void addDefaultEventHandler(){ addSelectionHandler(new SelectionHandler<Suggestion>(){ public void onSelection(SelectionEvent<Suggestion> event) { currentSuggestion = (QMultiWordSuggestion)event.getSelectedItem(); }}); }
private List<SuggestOracle.Suggestion> wrapSuggestions( List<SuggestFieldSuggestion> in) { List<SuggestOracle.Suggestion> out = new ArrayList<SuggestOracle.Suggestion>(); for (final SuggestFieldSuggestion wrappedSuggestion : in) { out.add(new OracleSuggestionImpl(wrappedSuggestion)); } return out; }
private void handleOnKeyEvent() { Suggestion suggestion = getCurrentSelection(); if (suggestion == null) { /* * Allow for new items */ if (allowNewItem) { handleNewSuggestion(); } hideSuggestions(); } else { setNewSelection(suggestion); } }
/** * Set the new suggestion in the text box. * * @param curSuggestion * the new suggestion */ private void setNewSelection(Suggestion curSuggestion) { assert curSuggestion != null : "suggestion cannot be null"; currentText = curSuggestion.getReplacementString(); setText(currentText); hideSuggestions(); fireSuggestionEvent(curSuggestion); }
protected Suggestion getCurrentSelection() { if (!isSuggestionListShowing()) { return null; } SuggestionMenuItem item = menu.getSelectedItem(); return item == null ? null : ((SuggestionMenuItem) item) .getSuggestion(); }
public SuggestionMenuItem(Suggestion suggestion, boolean asHTML) { this(suggestion.getDisplayString(), asHTML); // Each suggestion should be placed in a single row in the // suggestion // menu. If the window is resized and the suggestion cannot fit on a // single row, it should be clipped (instead of wrapping around and // taking up a second row). getElement().getStyle().setProperty("whiteSpace", "nowrap"); getElement().getStyle().setProperty("overflow", "hidden"); setStyleName(STYLENAME_DEFAULT); setSuggestion(suggestion); }
@Override public void onSelection(SelectionEvent<Suggestion> event) { SuggestFieldSuggestion suggestion = ((OracleSuggestionImpl) event .getSelectedItem()).getWrappedSuggestion(); serverRpc.onSuggestionSelected(suggestion); if (getWidget().tokenMode) { getWidget().setCurrentSuggestion(null); } else { getWidget().setCurrentSuggestion(suggestion); } }
public DTOSuggestBox() { super(new DTOSuggestOracle<T>()); addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() { @SuppressWarnings("unchecked") @Override public void onSelection(SelectionEvent<Suggestion> event) { selected = ((DTOSuggestion<T>) event.getSelectedItem()).getDTO(); } }); }
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())); }
private String status(Suggestion suggestion) { return suggestion instanceof HasStatus ? ((HasStatus)suggestion).getStatusString() : suggestion.getDisplayString(); }
public Suggestion getSelectedSuggestion() { MenuItem selectedItem = getSelectedItem(); return selectedItem == null ? null : ((SuggestionMenuItem)selectedItem).getSuggestion(); }
public Suggestion getSuggestion() { return iSuggestion; }
@Override public HandlerRegistration addSelectionHandler(SelectionHandler<Suggestion> handler) { return addHandler(handler, SelectionEvent.getType()); }
private void fireSuggestionEvent(Suggestion selectedSuggestion) { SelectionEvent.fire(this, selectedSuggestion); }
public void onFailure(Throwable caught) { ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); // suggestions.add(new SimpleSuggestion("<font color='red'>"+caught.getMessage()+"</font>", "")); iCallback.onSuggestionsReady(iRequest, new Response(suggestions)); ToolBox.checkAccess(caught); }
@Override protected Suggestion getCurrentSelection() { Suggestion currentSelection = super.getCurrentSelection(); isSuggestionSelected = currentSelection != null; return currentSelection; }
public RemoteSuggestBox(SuggestOracle oracle) { remoteSuggestOracle = new RemoteSuggestOracle(oracle); remoteSuggestOracle.setServeSuggestions(true); display = new DefaultSuggestionDisplay(); textBox = new HintTextBox(); textBox.addKeyDownHandler( new KeyDownHandler() { @Override public void onKeyDown(KeyDownEvent e) { submitOnSelection = false; if (e.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) { CloseEvent.fire(RemoteSuggestBox.this, RemoteSuggestBox.this); } else if (e.getNativeKeyCode() == KeyCodes.KEY_ENTER) { if (display.isSuggestionListShowing()) { if (textBox.getValue().equals(remoteSuggestOracle.getLast())) { submitOnSelection = true; } else { display.hideSuggestions(); } } else { SelectionEvent.fire(RemoteSuggestBox.this, getText()); } } } }); suggestBox = new SuggestBox(remoteSuggestOracle, textBox, display); suggestBox.addSelectionHandler( new SelectionHandler<Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> event) { if (submitOnSelection) { SelectionEvent.fire(RemoteSuggestBox.this, getText()); } remoteSuggestOracle.cancelOutstandingRequest(); display.hideSuggestions(); } }); initWidget(suggestBox); }
@UiHandler("searchBox") void suggestionSelected(SelectionEvent<Suggestion> event) { presenter.handleSearch(event.getSelectedItem().getReplacementString()); }
public void onSuggestionSelected(Suggestion suggestion) { box.setFocus(true); setNewSelection(suggestion); }
void showSuggestions() { // invoke the callback Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { // Hide the popup if there are no suggestions to display. boolean anySuggestions = (suggestions != null && suggestions .size() > 0); if (!anySuggestions) { hideSuggestions(); return; } // Hide the popup before we manipulate the menu within it. // If we do not // do this, some browsers will redraw the popup as items are // removed // and added to the menu. if (popup.isAttached()) { popup.hide(); } menu.clearItems(); for (final Suggestion curSuggestion : wrapSuggestions(suggestions)) { final SuggestionMenuItem menuItem = new SuggestionMenuItem( curSuggestion, true); menuItem.setScheduledCommand(new ScheduledCommand() { public void execute() { suggestionCallback .onSuggestionSelected(curSuggestion); } }); menu.addItem(menuItem); } if (anySuggestions) { // Select the first item in the suggestion menu. menu.selectItem(0); } popup.removeAutoHidePartner(getElement()); popup.addAutoHidePartner(getElement()); popup.showPopup(); } }); }