/** * Adds a {@link KeyPressHandler} to the specified widget which calls {@link Button#click()} on <code>targetButton</code> * when the Enter key is pressed. * @param widget widget to add the key handler to * @param targetButton target button to activate when the enter key is pressed */ public static void addEnterTarget( final HasKeyPressHandlers widget, final Button targetButton ) { widget.addKeyPressHandler( new KeyPressHandler() { @Override public void onKeyPress( final KeyPressEvent event ) { if ( event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER ) targetButton.click(); } } ); }
/** * Create a box that holds the current page. */ private void createCurPageBox() { // Setup the widget curPageBox.setWidth("3em"); curPageBox.setText("1"); curPageBox.setTextAlignment(TextBoxBase.ALIGN_RIGHT); // Disallow non-numeric pages KeyPressHandler handler = new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { int keyCode = event.getNativeEvent().getKeyCode(); char charCode = event.getCharCode(); if (keyCode == KeyCodes.KEY_ENTER) { PagingPanel.this.table.gotoPage(getPagingBoxValue(), false); } else if (charCode != 0 && !Character.isDigit(charCode)) { curPageBox.cancelKey(); } } }; // Add the handler curPageBox.addKeyPressHandler(handler); }
public void setKeyTyped(JavaScriptObject aValue) { if (keyTyped != aValue) { if (keyTypedReg != null) { keyTypedReg.removeHandler(); keyTypedReg = null; } keyTyped = aValue; if (keyTyped != null && component instanceof HasKeyPressHandlers) { keyTypedReg = ((HasKeyPressHandlers) component).addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (keyTyped != null) { event.stopPropagation(); executeEvent(keyTyped, EventsPublisher.publish(event)); } } }); } } }
public void bind() { RootPanel.get("container").add(getView().asWidget()); getView().asWidget().setVisible(false); view.getLoginButton().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { login(); } }); KeyPressHandler handler = new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { // Si on appuie sur "Entrée" if (KeyCodes.KEY_ENTER == event.getNativeEvent().getKeyCode()) login(); } }; getView().getLoginKeyPress().addKeyPressHandler(handler); getView().getPasswdKeyPress().addKeyPressHandler(handler); getView().asWidget().setVisible(true); }
public static KeyPressHandler createOnKeyPressListener(final EventListenerGVO ev, final List<InputVariableGVO> input) { return new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if (ev.getParameterList() != null) { Iterator<ParameterGVO> itr = ev.getParameterList().iterator(); while (itr.hasNext()) { ParameterGVO parameter = itr.next(); if (parameter != null) { if (KeyBoardHelper.isKeyInput(parameter.getName(), parameter.getValue(), Character.toString(event.getCharCode()))) { CallbackHandler.createCallBack(event.getSource(), QAMLConstants.EVENT_ONKEYPRESS, ev, input); } } } } } }; }
/** * Create a box that holds the current page. */ private void createCurPageBox() { // Setup the widget curPageBox.setWidth("3em"); curPageBox.setText("1"); curPageBox.setTextAlignment(TextBoxBase.ALIGN_RIGHT); // Disallow non-numeric pages KeyPressHandler handler = new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { char charCode = event.getCharCode(); if (charCode == KeyCodes.KEY_ENTER) { QPagingOptions.this.table.gotoPage(getPagingBoxValue(), false); } else if (!Character.isDigit(charCode) && (charCode != KeyCodes.KEY_TAB) && (charCode != KeyCodes.KEY_BACKSPACE) && (charCode != KeyCodes.KEY_DELETE) && (charCode != KeyCodes.KEY_ENTER) && (charCode != KeyCodes.KEY_HOME) && (charCode != KeyCodes.KEY_END) && (charCode != KeyCodes.KEY_LEFT) && (charCode != KeyCodes.KEY_UP) && (charCode != KeyCodes.KEY_RIGHT) && (charCode != KeyCodes.KEY_DOWN)) { curPageBox.cancelKey(); } } }; // Add the handler curPageBox.addKeyPressHandler(handler); }
private static KeyPressHandler createKeyPressHandler(final ComponentGVO componentGVO, final EventListenerGVO eventGVO, final NotifyHandler notifyHandler, final String windowId, final String context, final AbstractActivity activity) { return new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (eventGVO.getParameterList() == null) { return; } Iterator<ParameterGVO> itrParameter = eventGVO.getParameterList().iterator(); while (itrParameter.hasNext()) { ParameterGVO parameterGVO = itrParameter.next(); if (parameterGVO == null) { continue; } if (KeyBoardHelper.isKeyInput(parameterGVO.getName(), parameterGVO.getValue(), Character.toString(event.getCharCode()))) { UIObject widget = (UIObject)event.getSource(); List<InputVariableGVO> inputVariables = eventGVO.getInputvariablesList(); handleEvent(componentGVO, widget, eventGVO, event, QAMLConstants.EVENT_ONKEYPRESS, inputVariables, notifyHandler, windowId, context, activity); break; } } } }; }
/** * constructor. * * @param pcommitOnReturnHandler commit on return handler * @param pvalidateOnKeyUpHandler on key up handler * @param pvalidateOnVueChangeHandler on vue change handler * @param pvalueChangeHandler value change handler * @param pcheckTime enumeration which describes when to do the check * @param psubmitOnReturn submit form if return is pressed in a input field */ public BeanValidationInitializer(final KeyPressHandler pcommitOnReturnHandler, final KeyUpHandler pvalidateOnKeyUpHandler, final ValueChangeHandler<?> pvalidateOnVueChangeHandler, final ValueChangeHandler<?> pvalueChangeHandler, final CheckTimeEnum pcheckTime, final boolean psubmitOnReturn) { super(); this.commitOnReturnHandler = psubmitOnReturn ? pcommitOnReturnHandler : null; this.validateOnKeyUpHandler = pcheckTime == CheckTimeEnum.ON_KEY_UP ? pvalidateOnKeyUpHandler : null; this.validateOnVueChangeHandler = pcheckTime == CheckTimeEnum.ON_CHANGE || pcheckTime == CheckTimeEnum.ON_KEY_UP ? pvalidateOnVueChangeHandler : null; this.valueChangeHandler = pvalueChangeHandler; this.checkTime = pcheckTime; }
private void limitArea() { reportTextArea.getElement().setAttribute("maxlength", String.valueOf(MAX_REPORT_LENGTH)); reportTextArea.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { int size = reportTextArea.getText().length(); textLength.setText(String.valueOf(MAX_REPORT_LENGTH-size)); if(size == MAX_REPORT_LENGTH) { Animation a = new Animation() { @Override protected void onUpdate(double progress) { String rgbvalue = "rgb(" + ((int)((1-progress)*255)) + ",0,0)"; textLengthPanel.getElement().getStyle().setProperty("color", rgbvalue); } }; a.run(1000); } } }); }
public void setSubmitOnEnter(boolean submitOnEnter) { if (submitOnEnter) { if (submitOnEnterRegistration == null) submitOnEnterRegistration = addDomHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { if (validate()) { fireSubmitEvent(); } } } }, KeyPressEvent.getType()); } else if (submitOnEnterRegistration != null) { submitOnEnterRegistration.removeHandler(); submitOnEnterRegistration = null; } }
public NumberBox() { setStyleName("gwt-SuggestBox"); setWidth("100px"); getElement().getStyle().setTextAlign(TextAlign.RIGHT); addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (!isEnabled() || isReadOnly()) return; int keyCode = event.getNativeEvent().getKeyCode(); switch (keyCode) { case KeyCodes.KEY_BACKSPACE: case KeyCodes.KEY_DELETE: case KeyCodes.KEY_ESCAPE: case KeyCodes.KEY_RIGHT: case KeyCodes.KEY_LEFT: case KeyCodes.KEY_TAB: return; } if (isDecimal() && event.getCharCode() == '.' && !getValue().contains(".")) return; if (isNegative() && event.getCharCode() == '-' && !getValue().contains("-") && (getCursorPos() == 0 || getSelectionLength() == getValue().length())) return; if (Character.isDigit(event.getCharCode())) return; cancelKey( ); } } ); }
protected InfoPopupPanel(boolean autoHide, boolean modal){ super(autoHide, modal); //Register the popup in the list of popups eligible for closing on user-logout SiteManagerUI.getInstance().registerPopup( this ); //Set Animation ON this.setAnimationEnabled( true ); //Add the close by escape handler this.addDomHandler( new KeyPressHandler(){ public void onKeyPress( KeyPressEvent event ){ NativeEvent nativeEvent = event.getNativeEvent(); if( ( nativeEvent.getKeyCode() == KeyCodes.KEY_ESCAPE ) ) { hide(); } } }, KeyPressEvent.getType() ); //Set the width of the panel //this.setWidth("25%"); //Adding decorator panel inside the pop-up because //we want the panel to have rounded borders. decoratedPanel.setSize( "100%", "100%"); decoratedPanel.setStyleName( CommonResourcesContainer.INFO_POPUP_STYLE_NAME ); this.add( decoratedPanel ); }
@Override public HandlerRegistration addKeyPressHandler(final KeyPressHandler handler) { return this.addDomHandler(handler, KeyPressEvent.getType()); }
/** * Sets the KeyPress() event handler in many widgets * @param handler the handler * @param widgets the widgets */ public static void addKeyPressHandler(final KeyPressHandler handler,final HasKeyPressHandlers... widgets) { if (handler != null && widgets != null && widgets.length > 0) { for (HasKeyPressHandlers w : widgets) { if (w != null) w.addKeyPressHandler(handler); } } }
/** * Create a box that holds the current page. */ private void createCurPageBox() { // Setup the widget curPageBox.setWidth("3em"); curPageBox.setText("1"); curPageBox.setTextAlignment(TextBoxBase.ALIGN_RIGHT); // Disallow non-numeric pages KeyPressHandler handler = new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { char charCode = event.getCharCode(); if (charCode == KeyCodes.KEY_ENTER) { PagingOptions.this.imageGridPanel.getImageGrid().gotoPage(getPagingBoxValue(), false); } else if (!Character.isDigit(charCode) && (charCode != KeyCodes.KEY_TAB) && (charCode != KeyCodes.KEY_BACKSPACE) && (charCode != KeyCodes.KEY_DELETE) && (charCode != KeyCodes.KEY_ENTER) && (charCode != KeyCodes.KEY_HOME) && (charCode != KeyCodes.KEY_END) && (charCode != KeyCodes.KEY_LEFT) && (charCode != KeyCodes.KEY_UP) && (charCode != KeyCodes.KEY_RIGHT) && (charCode != KeyCodes.KEY_DOWN)) { curPageBox.cancelKey(); } } }; // Add the handler curPageBox.addKeyPressHandler(handler); }
public void markInvalid() { if (box instanceof TextBox) { ((TextBox)box).setFocus(true); box.addStyleName("invalid"); final Ref<HandlerRegistration> kpreg = new Ref<HandlerRegistration>(); kpreg.setSource(((TextBox)box).addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { box.removeStyleName("invalid"); kpreg.getSource().removeHandler(); } })); } }
public RefPatternBox() { super(Document.get().createTextInputElement(), RENDERER, PARSER); addKeyPressHandler(GlobalKey.STOP_PROPAGATION); addKeyPressHandler( new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == ' ') { event.preventDefault(); } } }); }
public AddOrganizationalUnitPopup() { setTitle(OrganizationalUnitManagerConstants.INSTANCE.AddOrganizationalUnitPopupTitle()); setBody(uiBinder.createAndBindUi(this)); add(footer); nameTextBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(final KeyPressEvent event) { nameGroup.setValidationState(ValidationState.NONE); nameHelpInline.setText(""); } }); }
@Override public final HandlerRegistration addKeyPressHandler(final KeyPressHandler phandler) { if (this.contents.getWidget() instanceof HasKeyPressHandlers) { return ((HasKeyPressHandlers) this.contents.getWidget()).addKeyPressHandler(phandler); } else { return null; } }
public NumericBoxWidget(final boolean decimal) { super(); addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { char keyCode = event.getCharCode(); if (!Character.isDigit(keyCode) // && Character.isLetter(keyCode) // && (keyCode != (char) KeyCodes.KEY_TAB) // && (keyCode != (char) KeyCodes.KEY_BACKSPACE) // && (keyCode != (char) KeyCodes.KEY_DELETE) // && (keyCode != (char) KeyCodes.KEY_ENTER) // && (keyCode != (char) KeyCodes.KEY_HOME) // && (keyCode != (char) KeyCodes.KEY_END) // && (keyCode != (char) KeyCodes.KEY_LEFT) // && (keyCode != (char) KeyCodes.KEY_UP) // && (keyCode != (char) KeyCodes.KEY_RIGHT) // && (keyCode != (char) KeyCodes.KEY_DOWN) // Fix for FF (which still sends event for Arrow/Delete/Backspace, etc) && (keyCode != (char) 0) && !(decimal && (keyCode == '.')) ) { // TextBox.cancelKey() suppresses the current keyboard event. cancelKey(); } } }); }
public DndListBox() { setMultipleSelect(true); this.setVisibleItemCount(5); AtomTools.log(Level.FINER, "DndListBox created", this); this.sinkEvents(Event.ONDBLCLICK); // this.getElement().getStyle().setProperty("border", "2px inset"); this.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { //GWT BUG: http://code.google.com/p/google-web-toolkit/issues/detail?id=5558 int unicode = event.getUnicodeCharCode(); char code = event.getCharCode(); NativeEvent nativeEvent = event.getNativeEvent(); int keyCode = nativeEvent.getKeyCode(); // AtomTools.log(Level.FINER, "login_passwordbox_keyPress; UnicodeCharCode=\""+unicode+"\" ; keyCode=\""+ keyCode +" ; CharCode=\""+String.valueOf(code)+"\"<endofline>", this); if(code == '\n' || code == '\r' || (unicode == 0 && keyCode == 13)) { if (representedObjects.size() > 0 && DndListBox.this.getSelectedIndex() != -1) App.openDetailView(representedObjects.get(DndListBox.this.getSelectedIndex()), null, false); } } }); // this.addMouseDownHandler(new MouseDownHandler() { // // @Override // public void onMouseDown(MouseDownEvent event) { // AtomTools.log(Level.FINER, "MouseDownEvent: '" + event + "'", this); // } // }); }
@Before public void init() { GwtMockito.initMocks(this); textBox = GWT.create(VariableNameTextBox.class); doCallRealMethod().when(textBox).setRegExp(anyString(), anyString(), anyString()); doCallRealMethod().when(textBox).setInvalidValues(anySet(), anyBoolean(), anyString()); doCallRealMethod().when(textBox).isValidValue(anyString(), anyBoolean()); doCallRealMethod().when(textBox).setText(anyString()); doCallRealMethod().when(textBox).testForInvalidValue(anyString()); doCallRealMethod().when(textBox).makeValidValue(anyString()); doCallRealMethod().when(textBox).getInvalidCharsInName(anyString()); doCallRealMethod().when(textBox).isValidChar(anyChar()); doCallRealMethod().when(textBox).setup(); doCallRealMethod().when(textBox).addBlurHandler(any(BlurHandler.class)); doCallRealMethod().when(textBox).addKeyPressHandler(any(KeyPressHandler.class)); textBox.setRegExp(ALPHA_NUM_REGEXP, ERROR_REMOVED, ERROR_TYPED); INVALID_VALUES.clear(); INVALID_VALUES.add("abc"); INVALID_VALUES.add("CdE"); INVALID_VALUES.add("a#$%1"); textBox.setInvalidValues(INVALID_VALUES, caseSensitive, ERROR_MESSAGE); }
public void setupKeys() { RootPanel.get().addDomHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { char c = event.getCharCode(); if(GWT.isProdMode() && c=='z') { Browser.console(event); String url = Window.Location.getHref(); url += url.contains("?") ? '&' : '?'; Window.Location.replace(url+"gwt.codesvr="+Window.Location.getHostName()+":9997"); } } }, KeyPressEvent.getType()); }
@Override public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return iText.addKeyPressHandler(handler); }
@Override public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return iFilter.addKeyPressHandler(handler); }
@Override public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return iFilter.getWidget().addKeyPressHandler(handler); }
public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return addDomHandler(handler, KeyPressEvent.getType()); }
public NavBar(final Table table) { super(); initWidget(BINDER.createAndBindUi(this)); this.table = table; Images images = GWT.create(Images.class); DOM.setInnerHTML(newerButton.getElement(), AbstractImagePrototype.create(images.previousPage()).getHTML()); DOM.setInnerHTML(olderButton.getElement(), AbstractImagePrototype.create(images.nextPage()).getHTML()); DOM.setInnerHTML(upButton.getElement(), AbstractImagePrototype.create(images.upRecord()).getHTML()); DOM.setInnerHTML(downButton.getElement(), AbstractImagePrototype.create(images.downRecord()).getHTML()); //countString = new String(); newerButton.setTitle(LocaleDictionary.get().getConstantValue(LocaleCommonConstants.TITLE_PREVIOUS)); olderButton.setTitle(LocaleDictionary.get().getConstantValue(LocaleCommonConstants.TITLE_NEXT)); upButton.setTitle(LocaleDictionary.get().getConstantValue(LocaleCommonConstants.UP_RECORD)); downButton.setTitle(LocaleDictionary.get().getConstantValue(LocaleCommonConstants.DOWN_RECORD)); searchPageTextBox = new TextBox(); pageNumberValidatableWidget = new ValidatableWidget<TextBox>(searchPageTextBox, true); pageNumberValidatableWidget.addValidator(new NumberValidator(searchPageTextBox, false, true)); searchPageTextBox.setText("1"); searchPageTextBox.setWidth("30px"); searchPageTextBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { String pageNo = searchPageTextBox.getText(); char keyCode = event.getCharCode(); pageNumberValidatableWidget.toggleValidDateBox(); if (keyCode == KeyCodes.KEY_ENTER && checkTextEntered(pageNo) && pageNumberValidatableWidget.validate()) { moveToEnteredPage(pageNo); } } }); searchPageTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> arg0) { pageNumberValidatableWidget.toggleValidDateBox(); } }); }
public static BaseDialog showInputDialog(Widget parent, String msg, String intialValue, int preferWidth, final ClickHandler okHandler, final ClickHandler cancelHandler) { final TextBox text = new TextBox(); text.setVisibleLength(preferWidth); if (!StringUtils.isEmpty(intialValue)) { text.setText(intialValue); } final BaseDialog dialog= new BaseDialog(parent, ButtonType.OK_CANCEL,"Input Dialog",true,null) { protected void inputComplete() { if (okHandler!=null) { okHandler.onClick(new ClickEvent() { @Override public Object getSource() { return text.getText(); } }); } } protected void inputCanceled() { if (cancelHandler!=null) cancelHandler.onClick(null); } }; text.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent ev) { final char keyCode= ev.getCharCode(); DeferredCommand.addCommand(new Command() { public void execute() { if (keyCode== KeyCodes.KEY_ENTER) { dialog.getButton(BaseDialog.ButtonID.OK).click(); } } }); } }); VerticalPanel vp = new VerticalPanel(); vp.setSpacing(5); vp.add(new HTML("<h3>" + msg + "</h3>")); vp.add(text); dialog.setWidget(vp); dialog.setVisible(true); text.setFocus(true); return dialog; }
public static BaseDialog showInputDialog(Widget parent, String title, final SimpleInputField field, final ClickHandler okHandler, final ClickHandler cancelHandler) { TextBox text= null; final BaseDialog dialog= new BaseDialog(parent, ButtonType.OK_CANCEL,title,true,null) { protected void inputComplete() { if (okHandler!=null) { okHandler.onClick(new ClickEvent() { @Override public Object getSource() { return field.getValue(); } }); } } protected void inputCanceled() { if (cancelHandler!=null) cancelHandler.onClick(null); } @Override protected boolean validateInput() throws ValidationException { if (!field.validate()) { throw new ValidationException(field.getField().getFieldDef().getErrMsg()); } return true; } }; if (field.getField() instanceof TextBoxInputField) { text= ((TextBoxInputField)field.getField()).getTextBox(); text.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent ev) { final char keyCode= ev.getCharCode(); DeferredCommand.addCommand(new Command() { public void execute() { if (keyCode== KeyCodes.KEY_ENTER) { dialog.getButton(BaseDialog.ButtonID.OK).click(); } } }); } }); } VerticalPanel vp = new VerticalPanel(); vp.setSpacing(5); vp.add(field); dialog.setWidget(vp); dialog.setVisible(true); if (text!=null) text.setFocus(true); return dialog; }
public void addKeyPressOnCreation(KeyPressHandler keyPressHandler) { this.keyPressHandler = keyPressHandler; }
@Override public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return addDomHandler(handler, KeyPressEvent.getType()); }
@Override public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return addHandler(handler, KeyPressEvent.getType()); }
@Override public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) { return super.addHandler(handler, KeyPressEvent.getType()); }