Search in sources :

Example 1 with Suggestion

use of com.google.gwt.user.client.ui.SuggestOracle.Suggestion in project ovirt-engine by oVirt.

the class EnterIgnoringNativePreviewHandler method onPreviewNativeEvent.

@Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
    NativeEvent nativeEvent = event.getNativeEvent();
    if (nativeEvent.getKeyCode() == KeyCodes.KEY_ENTER && event.getTypeInt() == Event.ONKEYPRESS && !event.isCanceled()) {
        // swallow the enter key otherwise the whole dialog would get submitted
        nativeEvent.preventDefault();
        nativeEvent.stopPropagation();
        event.cancel();
        // process the event here directly
        Suggestion currentSelection = listModelTypeAheadListBox.getCurrentSelection();
        if (currentSelection != null) {
            String replacementString = currentSelection.getReplacementString();
            try {
                listModelTypeAheadListBox.setValue(listModelTypeAheadListBox.asEntity(replacementString), true);
            } catch (IllegalArgumentException e) {
            // do not set the value if it is not a correct one
            }
        }
        listModelTypeAheadListBox.hideSuggestions();
    }
}
Also used : Suggestion(com.google.gwt.user.client.ui.SuggestOracle.Suggestion) MultiWordSuggestion(com.google.gwt.user.client.ui.MultiWordSuggestOracle.MultiWordSuggestion) NativeEvent(com.google.gwt.dom.client.NativeEvent)

Example 2 with Suggestion

use of com.google.gwt.user.client.ui.SuggestOracle.Suggestion in project opennms by OpenNMS.

the class FilterPanel method onApplicationSelect.

/**
 * <p>onApplicationSelect</p>
 *
 * @param event a {@link com.google.gwt.event.logical.shared.SelectionEvent} object.
 */
@UiHandler("applicationNameSuggestBox")
public void onApplicationSelect(final SelectionEvent<Suggestion> event) {
    Suggestion item = event.getSelectedItem();
    m_eventBus.fireEvent(new ApplicationSelectedEvent(item.getReplacementString()));
}
Also used : Suggestion(com.google.gwt.user.client.ui.SuggestOracle.Suggestion) ApplicationSelectedEvent(org.opennms.features.poller.remote.gwt.client.events.ApplicationSelectedEvent) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 3 with Suggestion

use of com.google.gwt.user.client.ui.SuggestOracle.Suggestion in project perun by CESNET.

the class SuggestBox method addEventsToTextBox.

private void addEventsToTextBox() {
    class TextBoxEvents extends HandlesAllKeyEvents implements ValueChangeHandler<String> {

        public void onKeyDown(KeyDownEvent event) {
            switch(event.getNativeKeyCode()) {
                case KeyCodes.KEY_DOWN:
                    display.moveSelectionDown();
                    break;
                case KeyCodes.KEY_UP:
                    display.moveSelectionUp();
                    break;
                case KeyCodes.KEY_ENTER:
                case KeyCodes.KEY_TAB:
                    Suggestion suggestion = display.getCurrentSelection();
                    if (suggestion == null) {
                        display.hideSuggestions();
                    } else {
                        setNewSelection(suggestion);
                    }
                    break;
            }
            delegateEvent(SuggestBox.this, event);
        }

        public void onKeyPress(KeyPressEvent event) {
            delegateEvent(SuggestBox.this, event);
        }

        public void onKeyUp(KeyUpEvent event) {
            // After every user key input, refresh the popup's suggestions.
            refreshSuggestions();
            delegateEvent(SuggestBox.this, event);
        }

        public void onValueChange(ValueChangeEvent<String> event) {
            delegateEvent(SuggestBox.this, event);
        }
    }
    TextBoxEvents events = new TextBoxEvents();
    events.addKeyHandlersTo(box);
    box.addValueChangeHandler(events);
}
Also used : Suggestion(com.google.gwt.user.client.ui.SuggestOracle.Suggestion) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) KeyDownEvent(com.google.gwt.event.dom.client.KeyDownEvent) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) KeyUpEvent(com.google.gwt.event.dom.client.KeyUpEvent) HandlesAllKeyEvents(com.google.gwt.event.dom.client.HandlesAllKeyEvents) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)

Aggregations

Suggestion (com.google.gwt.user.client.ui.SuggestOracle.Suggestion)3 NativeEvent (com.google.gwt.dom.client.NativeEvent)1 HandlesAllKeyEvents (com.google.gwt.event.dom.client.HandlesAllKeyEvents)1 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)1 KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)1 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 MultiWordSuggestion (com.google.gwt.user.client.ui.MultiWordSuggestOracle.MultiWordSuggestion)1 ApplicationSelectedEvent (org.opennms.features.poller.remote.gwt.client.events.ApplicationSelectedEvent)1