Example usage for com.google.gwt.user.client.ui SuggestBox SuggestBox

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

Introduction

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

Prototype

public SuggestBox(SuggestOracle oracle, ValueBoxBase<String> box, SuggestionDisplay suggestDisplay) 

Source Link

Document

Constructor for SuggestBox .

Usage

From source file:com.gafactory.core.client.ui.suggestions.SuggestedEditor.java

License:Open Source License

public SuggestedEditor(Renderer<T> renderer, BaseDataProxy<T> dataProxy, ValueProvider<T, String> searchField) {
    this.renderer = renderer;

    if (dataProxy == null) {
        oracle = new MultiWordSuggestOracle();
    } else {//  w ww .jav  a 2 s  . c  o  m
        oracle = new BaseSuggestOracle<T>(dataProxy, renderer, searchField);

    }

    final TextBox box = new TextBox();
    suggestBox = new SuggestBox(oracle, box, new SuggestionDisplayImpl());
    box.setStyleName("form-control");

    box.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            scheduleShowSuggestList();

        }
    });

    box.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
                if (getValue() != null) {
                    setValue(null);
                    scheduleShowSuggestList();
                }
            }
        }
    });

    suggestBox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<SuggestOracle.Suggestion> event) {
            if (event.getSelectedItem() instanceof Suggestion) {
                Suggestion<T> selectedItem = (Suggestion) event.getSelectedItem();
                setValue(selectedItem.getValue(), true);
            } else {
                final String replacementString = event.getSelectedItem().getReplacementString();
                setValue(replacementMap.get(replacementString), true);
            }

            SelectionEvent.fire(SuggestedEditor.this, value);

        }
    });

    InputGroup inputGroup = createGroup(suggestBox);

    initWidget(inputGroup);
}

From source file:com.google.gerrit.client.admin.GroupReferenceBox.java

License:Apache License

public GroupReferenceBox() {
    suggestions = new DefaultSuggestionDisplay();
    textBox = new NpTextBox();
    oracle = new AccountGroupSuggestOracle();
    suggestBox = new SuggestBox( //
            new RPCSuggestOracle(oracle), //
            textBox, //
            suggestions);//from w  w  w . j a  v  a  2 s. c om
    initWidget(suggestBox);

    textBox.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            submitOnSelection = false;

            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                if (suggestions.isSuggestionListShowing()) {
                    submitOnSelection = true;
                } else {
                    SelectionEvent.fire(GroupReferenceBox.this, getValue());
                }
            }
        }
    });
    suggestBox.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
                suggestBox.setText("");
                CloseEvent.fire(GroupReferenceBox.this, GroupReferenceBox.this);
            }
        }
    });
    suggestBox.addSelectionHandler(new SelectionHandler<Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            if (submitOnSelection) {
                submitOnSelection = false;
                SelectionEvent.fire(GroupReferenceBox.this, getValue());
            }
        }
    });
}

From source file:com.google.gerrit.client.SearchPanel.java

License:Apache License

SearchPanel() {
    final FlowPanel body = new FlowPanel();
    initWidget(body);/*  w w  w .j ava 2s.  c  o m*/
    setStyleName(Gerrit.RESOURCES.css().searchPanel());

    searchBox = new HintTextBox();
    final MySuggestionDisplay suggestionDisplay = new MySuggestionDisplay();
    searchBox.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(final KeyPressEvent event) {
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                if (!suggestionDisplay.isSuggestionSelected) {
                    doSearch();
                }
            }
        }
    });

    final SuggestBox suggestBox = new SuggestBox(new SearchSuggestOracle(), searchBox, suggestionDisplay);
    searchBox.setStyleName("gwt-TextBox");
    searchBox.setVisibleLength(70);
    searchBox.setHintText(Gerrit.C.searchHint());

    final Button searchButton = new Button(Gerrit.C.searchButton());
    searchButton.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            doSearch();
        }
    });

    body.add(suggestBox);
    body.add(searchButton);
}

From source file:com.google.gerrit.client.ui.RemoteSuggestBox.java

License:Apache License

public RemoteSuggestBox(SuggestOracle oracle) {
    remoteSuggestOracle = new RemoteSuggestOracle(oracle);
    remoteSuggestOracle.setServeSuggestions(true);
    display = new DefaultSuggestionDisplay();

    textBox = new HintTextBox();
    textBox.addKeyDownHandler(new KeyDownHandler() {
        @Override/*  ww w .  j a  va 2 s.co  m*/
        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);
}

From source file:com.tasktop.c2c.server.common.web.client.widgets.chooser.AbstractValueChooser.java

License:Open Source License

public static SuggestBox createSuggestBox(SuggestOracle oracle, final boolean hideOnScroll,
        final boolean hideOnResize) {
    final SuggestBoxProxy proxy = new SuggestBoxProxy();
    SuggestBox suggestBox = new SuggestBox(oracle, new TextBox(), new SuggestBox.DefaultSuggestionDisplay() {
        @Override//from   ww w .  j  a  v  a2 s .c o m
        protected PopupPanel createPopup() {
            final PopupPanel popupPanel = super.createPopup();
            CommonGinjector.get.instance().getEventBus().addHandler(ScrollEvent.getType(), new ScrollHandler() {
                @Override
                public void onScroll(ScrollEvent event) {
                    if (popupPanel.isShowing()) {
                        if (proxy.getSuggestBox() != null && !hideOnScroll) {
                            popupPanel.showRelativeTo(proxy.getSuggestBox());
                        } else {
                            popupPanel.hide();
                        }
                    }
                }
            });
            Window.addResizeHandler(new ResizeHandler() {
                @Override
                public void onResize(ResizeEvent event) {
                    if (popupPanel.isShowing()) {
                        if (proxy.getSuggestBox() != null && !hideOnResize) {
                            popupPanel.showRelativeTo(proxy.getSuggestBox());
                        } else {
                            popupPanel.hide();
                        }
                    }
                }
            });
            return popupPanel;
        }
    });
    proxy.setSuggestBox(suggestBox);
    if (oracle instanceof SuggestBoxAware) {
        ((SuggestBoxAware) oracle).setSuggestBox(suggestBox);
    }
    return suggestBox;
}

From source file:org.bonitasoft.forms.client.view.widget.AsyncSuggestBoxWidget.java

License:Open Source License

/**
 * Create AsyncSuggestBox/*from   w ww  . java 2s .com*/
 * 
 * @param formAsyncSuggestBoxData
 * @param fieldValue
 */
protected void createWidget(final ReducedFormWidget formAsyncSuggestBoxData, final FormFieldValue fieldValue) {
    this.widgetType = formAsyncSuggestBoxData.getType();
    final TextBox textBox = new TextBox();
    textBox.setReadOnly(formAsyncSuggestBoxData.isReadOnly());
    final DefaultSuggestionDisplay suggestionDisplay = new DefaultSuggestionDisplay();
    final String popupStyle = formAsyncSuggestBoxData.getItemsStyle();
    if (popupStyle != null && popupStyle.length() > 0) {
        suggestionDisplay.setPopupStyleName(popupStyle);
    }
    final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
    for (final ReducedFormFieldAvailableValue availableValue : formAsyncSuggestBoxData.getAvailableValues()) {
        oracle.add(availableValue.getValue());
    }
    this.asyncSuggestBox = new SuggestBox(oracle, textBox, suggestionDisplay);
    int refreshDelay = formAsyncSuggestBoxData.getDelayMillis();
    if (refreshDelay <= 0) {
        refreshDelay = DEFAULT_REFRESH_DELAY;
    }
    this.asyncSuggestBox.addKeyUpHandler(new AsyncSuggestBoxKeyUpHandler(refreshDelay));
    this.asyncSuggestBox.addKeyPressHandler(new AsyncSuggestBoxKeyPressHandler());
    this.asyncSuggestBox.setValue(getStringValue(fieldValue));
    if (formAsyncSuggestBoxData.getMaxItems() > 0) {
        this.asyncSuggestBox.setLimit(formAsyncSuggestBoxData.getMaxItems() - 1);
    }
    this.flowPanel.add(this.asyncSuggestBox);
}

From source file:org.bonitasoft.forms.client.view.widget.FormFieldWidget.java

License:Open Source License

/**
 * Create a {@link SuggestBox} widget//from  w ww .  jav  a2 s  . c o  m
 *
 * @param widgetData
 *        the widget data object
 * @param fieldValue
 *        the widget value
 * @return a {@link SuggestBox}
 */
@SuppressWarnings("unchecked")
protected SuggestBox createSuggestBox(final ReducedFormWidget widgetData, final FormFieldValue fieldValue) {
    final TextBox textBox = new TextBox();
    textBox.setEnabled(!widgetData.isReadOnly());
    final DefaultSuggestionDisplay suggestionDisplay = new DefaultSuggestionDisplay();
    final String popupStyle = widgetData.getItemsStyle();
    if (popupStyle != null && popupStyle.length() > 0) {
        suggestionDisplay.setPopupStyleName(popupStyle);
    }
    suggestionsMap = new TreeMap<String, String>();
    final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();

    // this fix the reordering of numbers
    final Comparator<String> numberComparator = new Comparator<String>() {

        @Override
        public int compare(final String o1, final String o2) {

            if (stringIsDouble(o1) && stringIsDouble(o2)) {
                return Double.valueOf(o1).compareTo(Double.valueOf(o2));
            }
            return o1.compareTo(o2);
        }

        private boolean stringIsDouble(final String str) {
            return str.matches("^(([0-9]*)|(([0-9]*)[\\.,\\,]([0-9]*)))$");
        }

    };
    oracle.setComparator(numberComparator);

    String labelValue = null;
    final String fieldValueStr = getStringValue(fieldValue);
    widgetData.getAvailableValues();
    for (final ReducedFormFieldAvailableValue availableValue : widgetData.getAvailableValues()) {
        final String label = availableValue.getLabel();
        final String value = availableValue.getValue();
        suggestionsMap.put(label, value);
        oracle.add(label);
        if (value != null && value.equals(fieldValueStr)) {
            labelValue = label;
        }
    }
    final SuggestBox suggestBox = new SuggestBox(oracle, textBox, suggestionDisplay);
    suggestBox.addValueChangeHandler(this);
    suggestBox.addSelectionHandler(this);
    if (labelValue != null) {
        suggestBox.setValue(labelValue);
    } else {
        suggestBox.setValue(fieldValueStr);
    }
    if (widgetData.getMaxItems() > 0) {
        suggestBox.setLimit(widgetData.getMaxItems() - 1);
    }
    return suggestBox;
}

From source file:org.rest.client.ui.desktop.widget.HeadersFormRow.java

License:Apache License

/**
 * Generate suggestion box - a text field with suggestions.
 * @return SuggestBox with headers autocomplete support.
 *//*  w w  w  .  j  a  v  a 2s .  c o m*/
private SuggestBox getSuggestBox() {
    SuggestBox suggestBox = null;
    //depends if DB has initialized successfully 
    if (suggestOracle != null) {
        try {
            DefaultSuggestionDisplay suggestionsDisplay = new DefaultSuggestionDisplay();
            suggestionsDisplay.setAnimationEnabled(true);
            suggestBox = new SuggestBox(suggestOracle, new TextBox(), suggestionsDisplay);
        } catch (Exception e) {
            suggestBox = new SuggestBox();
        }
    } else {
        suggestBox = new SuggestBox();
    }
    return suggestBox;
}

From source file:org.rest.client.ui.desktop.widget.RequestUrlWidget.java

License:Apache License

public RequestUrlWidget() {

    UrlHistoryStoreWebSql historyStore = RestClient.getClientFactory().getUrlHistoryStore();

    //create URL simple field (suggestion box)
    suggestOracle = new UrlsSuggestOracle(historyStore);
    suggestionsDisplay = new UrlsSuggestionDisplay();
    suggestionsDisplay.setAnimationEnabled(false);
    urlField = new SuggestBox(suggestOracle, new TextBox(), suggestionsDisplay);
    urlField.getElement().setAttribute("placeholder", "URL");
    urlField.setAutoSelectEnabled(false);

    //init widget
    initWidget(GWT.<Binder>create(Binder.class).createAndBindUi(this));

    detailedHostField.getElement().setAttribute("placeholder", "HOST");
    detailedHostField.getElement().setAttribute("id", "detailedHostField");
    detailedPathField.getElement().setAttribute("placeholder", "PATH");
    detailedPathField.getElement().setAttribute("id", "detailedPathField");
    detailedHashField.getElement().setAttribute("placeholder", "HASH");
    detailedHashField.getElement().setAttribute("id", "detailedHashField");

    setParamsContainerEvents();// ww  w .j a va 2  s . c  om
    observeToggleButton(this);
    observeAddParamButton(this);
    observeSettingsMenu(this);

    Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
        @Override
        public void execute() {

        }
    });
}