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

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

Introduction

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

Prototype

public void showSuggestionList() 

Source Link

Document

Show the current list of suggestions.

Usage

From source file:com.sun.labs.aura.music.wsitm.client.ui.widget.AbstractSearchWidget.java

License:Open Source License

private SuggestBox getNewSuggestBox(PopSortedMultiWordSuggestOracle oracle) {
    final SuggestBox box = new SuggestBox(oracle);
    box.setLimit(15);/*from ww w . j  a  va2 s  .c  o  m*/
    box.setAutoSelectEnabled(false);
    box.addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            // If enter key pressed, submit the form
            if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                DeferredCommand.addCommand(new Command() {
                    @Override
                    public void execute() {
                        search();
                    }
                });
                // If escape key pressed, hide the suggestbox
            } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
                box.hideSuggestionList();
            } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_DOWN) {
                if (!box.isSuggestionListShowing()) {
                    box.showSuggestionList();
                }
            } else if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_LEFT
                    || event.getNativeEvent().getKeyCode() == KeyCodes.KEY_RIGHT) {
                box.hideSuggestionList();
            }
        }
    });
    if (searchBoxStyleName != null && searchBoxStyleName.length() > 0) {
        box.addStyleName(searchBoxStyleName);
    }
    box.addFocusListener(focusListener);
    box.setText(DEFAULT_TXT);
    return box;
}

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//ww  w.  j  a v  a2s  . c o 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;
}

From source file:gwt.material.design.addins.client.ui.MaterialAutoComplete.java

License:Apache License

/**
 * Generate and build the List Items to be set on Auto Complete box.
 *///  w w  w  . j  a v a2 s.c  o m
private void generateAutoComplete(MaterialSuggestionOracle suggestions) {
    list.setStyleName("multiValueSuggestBox-list");
    this.suggestions = suggestions;
    final ListItem item = new ListItem();

    item.setStyleName("multiValueSuggestBox-input-token");
    final SuggestBox box = new SuggestBox(suggestions, itemBox);
    String autocompleteId = DOM.createUniqueId();
    itemBox.getElement().setId(autocompleteId);

    item.add(box);
    list.add(item);

    itemBox.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            switch (event.getNativeKeyCode()) {
            case KeyCodes.KEY_ENTER:
                addItem(itemBox, list);
                break;

            case KeyCodes.KEY_BACKSPACE:
                if (itemBox.getValue().trim().isEmpty()) {
                    if (itemsHighlighted.isEmpty()) {
                        if (itemValues.size() > 0) {
                            ListItem li = (ListItem) list.getWidget(list.getWidgetCount() - 2);
                            MaterialChip p = (MaterialChip) li.getWidget(0);
                            if (itemValues.contains(p.getText())) {
                                itemValues.remove(p.getText());
                            }
                            list.remove(li);
                        }
                    }
                }

            case KeyCodes.KEY_DELETE:
                if (itemBox.getValue().trim().isEmpty()) {
                    for (ListItem li : itemsHighlighted) {
                        li.removeFromParent();
                        MaterialChip p = (MaterialChip) li.getWidget(0);
                        itemValues.remove(p.getText());
                    }
                    itemsHighlighted.clear();
                }
                itemBox.setFocus(true);
                break;
            }
        }
    });

    itemBox.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            box.showSuggestionList();
        }
    });

    box.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        public void onSelection(SelectionEvent<SuggestOracle.Suggestion> selectionEvent) {
            addItem(itemBox, list);
        }
    });

    panel.add(list);
    panel.getElement().setAttribute("onclick", "document.getElementById('" + autocompleteId + "').focus()");
    panel.add(lblError);
    box.setFocus(true);
}