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

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

Introduction

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

Prototype

public void setFocus(boolean focused) 

Source Link

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   ww  w  .j a v a 2s .  c  o m
                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:com.ephesoft.dcma.gwt.rv.client.view.TableExtractionView.java

License:Open Source License

public void setFocus() {
    FlexTable selectedView = tableNameVsViewMap.get(selectedDataTableName);
    SuggestBox suggestBox = (SuggestBox) selectedView.getWidget(selectedRowNumber, 0);
    suggestBox.setFocus(true);
}

From source file:com.phideltcmu.recruiter.client.ui.popup.AdminAdd.java

License:Creative Commons License

private void fillSuggest(List<InternalUser> list, final SuggestBox suggestbox) {
    MultiWordSuggestOracle oracle = (MultiWordSuggestOracle) suggestbox.getSuggestOracle();
    // Populate the suggestion oracle
    for (InternalUser person : list) {
        oracle.add(person.getName());/* w ww. j av a 2 s  . c o  m*/
    }

    // When a suggestion is selected, switch to that client
    suggestbox.addSelectionHandler(new SelectionHandler<SuggestOracle.Suggestion>() {
        @Override
        public void onSelection(SelectionEvent<SuggestOracle.Suggestion> suggestionSelectionEvent) {
        }
    });

    // If the user hits enter in the search box, inspect the company
    suggestbox.addKeyUpHandler(new KeyUpHandler() {
        private int keyUpCount = 0;

        @Override
        public void onKeyUp(KeyUpEvent event) {
            // Bug in GWT 2.0.3. KeyUpEvent gets fired twice...

            keyUpCount++;

            if (keyUpCount % 2 == 0) {
                return;
            }
            if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                suggestbox.setFocus(false);
            }
        }
    });
    this.display();
}

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/*  www.j  a  v a2  s.c om*/
        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.
 *///from  ww  w . ja v  a 2s  .  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);
}