List of usage examples for com.google.gwt.query.client GQuery keypress
public GQuery keypress(int key)
From source file:org.bonitasoft.web.toolkit.client.ui.component.AutoCompleteTextInput.java
License:Open Source License
private void setEvents() { final GQuery input = $(inputElement); // ON TEXT CHANGE input.keypress(new Function() { @Override//from w w w . j a v a 2 s . c om public boolean f(final Event e) { // Window.alert(e.getKeyCode() + " - " + e.getCharCode()); switch (e.getKeyCode()) { case KeyCodes.KEY_ENTER: e.stopPropagation(); return false; case KeyCodes.KEY_ESCAPE: AutoCompleteTextInput.this.reset(); break; case KeyCodes.KEY_DELETE: case KeyCodes.KEY_BACKSPACE: case 0: // Character default: AutoCompleteTextInput.this.resetValue(); // ClearTimeout if another key is pressed before the end of previous timeout if (input.data(AUTOCOMPLETE_ONCHANGE_TIMER) != null) { final Timer t = (Timer) input.data(AUTOCOMPLETE_ONCHANGE_TIMER); t.cancel(); input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER); } final Timer t = new Timer() { @Override public void run() { input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER); AutoCompleteTextInput.this.refresh(); } }; input.data("AUTOCOMPLETE_ONCHANGE_TIMER", t); t.schedule(500); break; } return true; } }); // ON TEXT BLUR input.blur(new Function() { @Override public void f() { if (input.data(AUTOCOMPLETE_ONCHANGE_TIMER) != null) { final Timer t = (Timer) input.data(AUTOCOMPLETE_ONCHANGE_TIMER); t.cancel(); input.removeData(AUTOCOMPLETE_ONCHANGE_TIMER); } boolean isFocused = childrenFocused(dropdown.getElement()); // && $(AutoCompleteTextInput.this.dropdown.getElement()).find(":focus").size() == 0) { if (!$(inputElement).is(".completed") && !isFocused) { AutoCompleteTextInput.this.reset(); dropdown.close(); } } }); }