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

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

Introduction

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

Prototype

public ValueBoxBase<String> getValueBox() 

Source Link

Document

Get the ValueBoxBase associated with this suggest box.

Usage

From source file:cc.kune.gspace.client.share.ShareToOthersPanel.java

License:Open Source License

@Inject
public ShareToOthersPanel(final I18nUITranslationService i18n,
        final ShareToOthersDropController dropController) {
    this.dropController = dropController;
    final FlowPanel flow = new FlowPanel();
    flow.addStyleName("k-share-others");

    multivalueSBox = SearchBoxFactory.create(i18n, false, true, SEARCH_TEXTBOX_ID,
            new OnEntitySelectedInSearch() {
                @Override//from w  ww  .ja va  2s.  c om
                public void onSeleted(final String shortName) {
                    if (addListener != null) {
                        addListener.onAdd(shortName);
                    }
                }
            });
    final SuggestBox suggestBox = multivalueSBox.getSuggestBox();
    final ValueBoxBase<String> searchTextBox = suggestBox.getValueBox();
    final Label suggestBoxIntro = new Label(I18n.t("drag and drop to add people or"));
    final Label suggestTextWhenEmpty = new Label(I18n.t("search to add"));

    flow.add(suggestBoxIntro);
    flow.add(multivalueSBox);
    flow.add(suggestTextWhenEmpty);

    multivalueSBox.addStyleName("k-share-searchbox");
    suggestTextWhenEmpty.addStyleName("k-share-searchbox-text");
    suggestTextWhenEmpty.addStyleName("k-clean");

    initWidget(flow);

    // Search box settings
    suggestTextWhenEmpty.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(final ClickEvent event) {
            suggestBox.setFocus(true);
        }
    });
    searchTextBox.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(final FocusEvent event) {
            // searchLabel.setVisible(false);
            suggestTextWhenEmpty.getElement().getStyle().setVisibility(Visibility.HIDDEN);
        }
    });
    searchTextBox.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(final BlurEvent event) {
            if (searchTextBox.getValue().isEmpty()) {
                suggestTextWhenEmpty.getElement().getStyle().setVisibility(Visibility.VISIBLE);
            }
        }
    });

    // Tooltips
    Tooltip.to(suggestBox, I18n.t(NOT_LIST_TOOLTIP));
    Tooltip.to(suggestTextWhenEmpty, I18n.t(NOT_LIST_TOOLTIP));
    Tooltip.to(suggestBoxIntro, I18n.t(NOT_LIST_TOOLTIP));

    // D&D
    dropController.init(flow);
}

From source file:de.uni_koeln.spinfo.maalr.webapp.ui.common.client.ConfigurableSearchArea.java

License:Apache License

private Widget buildOracle(final UiField field) {
    MultiWordSuggestOracle oracle = new MultiWordSuggestOracle() {

        @Override//  w w  w . j  av a  2s . co  m
        public void requestSuggestions(final Request request, final Callback callback) {
            service.getSuggestions(field.getId(), request.getQuery(), request.getLimit(),
                    new AsyncCallback<List<String>>() {

                        @Override
                        public void onFailure(Throwable caught) {
                        }

                        @Override
                        public void onSuccess(List<String> result) {
                            Response response = new Response();
                            List<Suggestion> suggestions = new ArrayList<Suggestion>();
                            for (String string : result) {
                                suggestions.add(new MultiWordSuggestion(string, string));
                            }
                            response.setSuggestions(suggestions);
                            callback.onSuggestionsReady(request, response);
                        }
                    });

        }

    };
    final SuggestBox box = new SuggestBox(oracle);
    box.setValue(field.getInitialValue());

    box.getValueBox().addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            String old = oracleHistory.get(field.getId());
            if (old != null) {
                box.getValueBox().setText(old);
            }
            box.getValueBox().selectAll();
            box.showSuggestionList();
        }
    });

    box.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                box.getValueBox().selectAll();
                event.stopPropagation();
                event.preventDefault();
                box.setFocus(true);
                fireDelayedUpdate();
            }
        }
    });

    box.addKeyUpHandler(new KeyUpHandler() {

        @Override
        public void onKeyUp(KeyUpEvent event) {
            if (box.getValue() == null || box.getValue().trim().length() == 0) {
                currentValues.remove(field.getId());
            } else {
                currentValues.put(field.getId(), box.getValue());
            }
            oracleHistory.put(field.getId(), box.getValue());
            //fireDelayedUpdate();
        }

    });
    box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {

        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            String string = event.getSelectedItem().getReplacementString();
            if (box.getValue() == null || box.getValue().trim().length() == 0) {
                currentValues.remove(field.getId());
            } else {
                currentValues.put(field.getId(), string);
            }
            fireDelayedUpdate();
        }
    });
    return box;
}