List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler
FocusHandler
From source file:com.googlesource.gerrit.plugins.emoticons.client.OnEditEnabler.java
License:Apache License
public void listenTo(final TextBoxBase tb) { strings.put(tb, tb.getText().trim()); tb.addKeyPressHandler(this); // Is there another way to capture middle button X11 pastes in browsers // which do not yet support ONPASTE events (Firefox)? tb.addMouseUpHandler(this); // Resetting the "original text" on focus ensures that we are // up to date with non-user updates of the text (calls to // setText()...) and also up to date with user changes which // occured after enabling "widget". tb.addFocusHandler(new FocusHandler() { @Override// w w w. j a v a 2 s. co m public void onFocus(FocusEvent event) { strings.put(tb, tb.getText().trim()); } }); // CTRL-V Pastes in Chrome seem only detectable via BrowserEvents or // KeyDownEvents, the latter is better. tb.addKeyDownHandler(this); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.popupbutton.CubaPopupButtonWidget.java
License:Apache License
@Override protected void onPopupOpened() { super.onPopupOpened(); if (customLayout) { return;//from w ww . j a v a 2 s .c o m } // find button, assign .v-selected style for (Widget popupChild : getPopup()) { if (popupChild instanceof VAbstractOrderedLayout) { VAbstractOrderedLayout content = (VAbstractOrderedLayout) popupChild; for (Widget slot : content) { Widget contentChild = ((Slot) slot).getWidget(); if (contentChild instanceof VButton) { VButton button = (VButton) contentChild; if (button.isEnabled() && !button.getStyleName().contains(SELECTED_ITEM_STYLE)) { button.addStyleName(SELECTED_ITEM_STYLE); button.setFocus(true); break; } } } } } // add focus handler for (Widget popupChild : getPopup()) { if (popupChild instanceof VAbstractOrderedLayout) { VAbstractOrderedLayout content = (VAbstractOrderedLayout) popupChild; for (Widget slot : content) { Widget contentChild = ((Slot) slot).getWidget(); VButton button = null; if (contentChild instanceof CubaFileUploadWidget) { button = ((CubaFileUploadWidget) contentChild).getSubmitButton(); } else if (contentChild instanceof VUpload) { button = ((VUpload) contentChild).submitButton; } else if (contentChild instanceof VButton) { button = (VButton) contentChild; } if (button != null) { final VButton finalButton = button; button.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { childWidgetFocused(finalButton); } }); // sink mouse over DOM.sinkEvents(button.getElement(), Event.ONMOUSEOVER | DOM.getEventsSunk(button.getElement())); } } } } }
From source file:com.mecatran.otp.gwt.client.view.AddressAutoCompleteBox.java
License:Open Source License
public AddressAutoCompleteBox() { oracle = new GeocodingOracle(); suggestBox = new SuggestBox(oracle); suggestBox.setAutoSelectEnabled(false); suggestBox.setText(""); suggestBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override//w w w . j a v a 2 s .c om public void onValueChange(ValueChangeEvent<String> event) { if (location != null) location.setLocation(null); // TODO ??? } }); suggestBox.addSelectionHandler(new SelectionHandler<Suggestion>() { @Override public void onSelection(SelectionEvent<Suggestion> event) { GeocodedAddressSuggestion geocodedSuggestion = (GeocodedAddressSuggestion) event.getSelectedItem(); location = geocodedSuggestion.getLocation(); listener.onLocationSelected(location); } }); suggestBox.getValueBox().addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { listener.onFocus(); } }); HorizontalPanel rootPanel = new HorizontalPanel(); rootPanel.add(suggestBox); initWidget(rootPanel); }
From source file:com.mecatran.otp.gwt.client.view.AddressProposalBox.java
License:Open Source License
public AddressProposalBox() { geocodeTimer = new Timer() { @Override//from w ww.ja va 2s. c om public void run() { if (!modifiedSinceGeocoding) return; modifiedSinceGeocoding = false; if (!textBox.getText().isEmpty() && location.getLocation() == null) { geocode(); } } }; location = new LocationBean(); VerticalPanel rootPanel = new VerticalPanel(); HorizontalPanel inputPanel = new HorizontalPanel(); rootPanel.add(inputPanel); inputPanel.setCellWidth(inputPanel, "100%"); textBox = new TextBox(); textBox.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { location.setAddress(textBox.getText()); location.setLocation(null); if (textBox.getText().isEmpty()) listener.onLocationSelected(location); } }); textBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { modifiedSinceGeocoding = true; location.setLocation(null); geocodeTimer.cancel(); if (textBox.getText().length() > 10) { geocodeTimer.schedule(3000); } } }); textBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { listener.onFocus(); } }); textBox.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { geocodeTimer.cancel(); geocodeTimer.schedule(100); } }); inputPanel.add(textBox); clearButton = new Button("X"); inputPanel.setCellWidth(inputPanel, "auto"); clearButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { geocodeTimer.cancel(); textBox.setText(""); location.setAddress(""); location.setLocation(null); listener.onLocationSelected(location); } }); inputPanel.add(clearButton); proposalPanel = new VerticalPanel(); initWidget(rootPanel); }
From source file:com.mecatran.otp.gwt.client.view.TimePicker.java
License:Open Source License
/** * Default Constructor./*from www .j a v a2 s . com*/ * * @param time * Hour that will show the widget * @param precision * Indicates if widget precision */ public TimePicker(Date time, TIME_PRECISION precision) { timeValue = time; container = new VerticalPanel(); int hour = time.getHours(); int minutes = time.getMinutes(); if (precision == TIME_PRECISION.QUARTER_HOUR) { minutesSteps = 15; } else { minutesSteps = 1; } hoursBox = new ValueTextBox(hour, 0, 24); hoursBox.setMinDigits(2); hoursBox.setSteps(0); minutesBox = new ValueTextBox(minutes, 0, 59); minutesBox.setMinDigits(2); minutesBox.setSteps(0); Label separator = new Label(":"); hoursBox.setWidth("30px"); minutesBox.setWidth("30px"); hoursBox.setStyleName(getStyleTimePickerEntry()); separator.setStyleName(getStyleTimePickerEntry()); minutesBox.setStyleName(getStyleTimePickerEntry()); timePanel = new HorizontalPanel(); timePanel.setStyleName(getStyleTimePicker()); timePanel.add(hoursBox); timePanel.add(separator); timePanel.add(minutesBox); setReadOnly(readOnly); timePanel.setCellVerticalAlignment(separator, HasVerticalAlignment.ALIGN_MIDDLE); container.add(timePanel); initWidget(container); hoursBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { fireValueChange(); } }); hoursBox.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (isReadOnly()) { return; } int keyCode = event.getNativeEvent().getKeyCode(); int hour = Integer.parseInt(hoursBox.getValue()); int oldHour = timeValue.getHours(); boolean stepKey = false; switch (keyCode) { case KeyCodes.KEY_UP: stepKey = true; timeValue.setHours(timeValue.getHours() + 1); break; case KeyCodes.KEY_DOWN: stepKey = true; timeValue.setHours(timeValue.getHours() - 1); break; } updateTimeValue(stepKey, oldHour, hour); } }); hoursBox.addMouseWheelHandler(new MouseWheelHandler() { public void onMouseWheel(MouseWheelEvent event) { int hour = Integer.parseInt(hoursBox.getValue()); int oldHour = timeValue.getHours(); if (event.isNorth()) { timeValue.setHours(timeValue.getHours() + 1); } else { timeValue.setHours(timeValue.getHours() - 1); } updateTimeValue(true, oldHour, hour); } }); hoursBox.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { fireBlurEvent(); } }); minutesBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { fireValueChange(); } }); minutesBox.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (isReadOnly()) { return; } int keyCode = event.getNativeEvent().getKeyCode(); int minutes = Integer.parseInt(minutesBox.getValue()); boolean stepKey = false; int oldMinutes = timeValue.getMinutes(); switch (keyCode) { case KeyCodes.KEY_UP: stepKey = true; increaseValue(); return; case KeyCodes.KEY_DOWN: stepKey = true; decreaseValue(); return; } if (!stepKey && (oldMinutes != minutes)) { int hour = Integer.parseInt(hoursBox.getValue()); timeValue.setHours(hour); timeValue.setMinutes(minutes); fireValueChange(); } } }); minutesBox.addMouseWheelHandler(new MouseWheelHandler() { public void onMouseWheel(MouseWheelEvent event) { if (event.isNorth()) { increaseValue(); } else { decreaseValue(); } } }); minutesBox.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { fireBlurEvent(); } }); // Trying to force that the whole value is selected when receiving the // focus hoursBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { hoursBox.setFocus(true); hoursBox.selectAll(); } }); minutesBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { minutesBox.setFocus(true); minutesBox.selectAll(); } }); // Making sure the cursor is always in the last position so the editing // works as expected hoursBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { hoursBox.setCursorPos(hoursBox.getText().length()); } }); minutesBox.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { minutesBox.setCursorPos(minutesBox.getText().length()); } }); }
From source file:com.mynotes.client.activity.NotesActivity.java
License:Open Source License
public void bind() { noteKeyPressHandlerRegistration = display.getNoteKeyDownHandlers().addKeyDownHandler(new KeyDownHandler() { @Override/*from w w w. j av a2s . c o m*/ public void onKeyDown(KeyDownEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { addNote(); } } }); noteFocusHandlerRegistration = display.getNoteFocusHandlers().addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { display.setVisibleNoteAdvise(false); display.setVisibleNotePressEnter(false); } }); noteBlurHandlerRegistration = display.getNoteBlurHandlers().addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { String text = display.getNoteText(); if (text.trim().isEmpty()) { display.setVisibleNoteAdvise(true); } else { display.setVisibleNotePressEnter(true); } } }); deleteAnchorClickHandlerRegistration = display.getDeleteAnchor().addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { deleteSelectedNotes(); } }); }
From source file:com.onetwopoll.gwt.framework.widget.EditableLabel.java
License:GNU Affero Public License
private void init() { initWidget(uiBinder.createAndBindUi(this)); deckPanel.showWidget(0);/* w ww . j ava2 s. co m*/ focusPanel.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { switchToEdit(); } }); editLabel.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { switchToEdit(); } }); editBox.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent event) { switchToLabel(); } }); editBox.addKeyPressHandler(new KeyPressHandler() { @Override public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ENTER) { switchToLabel(); } else if (event.getCharCode() == KeyCodes.KEY_ESCAPE) { editBox.setText(editLabel.getText()); // reset to the original value } } }); }
From source file:com.ponysdk.ui.terminal.ui.PTWidget.java
License:Apache License
private void addDomHandler(final PTInstruction addHandler, final Widget widget, final int domHandlerType, final UIService uiService) { final DomHandlerType h = DomHandlerType.values()[domHandlerType]; switch (h) {//from w w w. j a v a 2 s . com case CLICK: widget.addDomHandler(new ClickHandler() { @Override public void onClick(final ClickEvent event) { triggerOnClick(addHandler, widget, domHandlerType, uiService, event); } }, ClickEvent.getType()); break; case MOUSE_OVER: widget.addDomHandler(new MouseOverHandler() { @Override public void onMouseOver(final MouseOverEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, MouseOverEvent.getType()); break; case BLUR: widget.addDomHandler(new BlurHandler() { @Override public void onBlur(final BlurEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, BlurEvent.getType()); break; case FOCUS: widget.addDomHandler(new FocusHandler() { @Override public void onFocus(final FocusEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, FocusEvent.getType()); break; case MOUSE_OUT: widget.addDomHandler(new MouseOutHandler() { @Override public void onMouseOut(final MouseOutEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, MouseOutEvent.getType()); break; case MOUSE_DOWN: widget.addDomHandler(new MouseDownHandler() { @Override public void onMouseDown(final MouseDownEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, MouseDownEvent.getType()); break; case MOUSE_UP: widget.addDomHandler(new MouseUpHandler() { @Override public void onMouseUp(final MouseUpEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, MouseUpEvent.getType()); break; case KEY_PRESS: widget.addDomHandler(new KeyPressHandler() { @Override public void onKeyPress(final KeyPressEvent event) { triggerOnKeyPress(addHandler, domHandlerType, uiService, event); } }, KeyPressEvent.getType()); break; case KEY_UP: if (widget instanceof TextBoxBase) { final TextBoxBase textBox = (TextBoxBase) widget; textBox.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(final KeyUpEvent event) { final PTInstruction changeHandlerInstruction = new PTInstruction(); changeHandlerInstruction.setObjectID(addHandler.getObjectID()); changeHandlerInstruction.put(TYPE.KEY, TYPE.KEY_.EVENT); changeHandlerInstruction.put(HANDLER.KEY, HANDLER.KEY_.STRING_VALUE_CHANGE_HANDLER); changeHandlerInstruction.put(PROPERTY.VALUE, textBox.getText()); final PTInstruction eventInstruction = buildEventInstruction(addHandler, domHandlerType); eventInstruction.put(PROPERTY.VALUE, event.getNativeEvent().getKeyCode()); if (addHandler.containsKey(PROPERTY.KEY_FILTER)) { final JSONArray jsonArray = addHandler.get(PROPERTY.KEY_FILTER).isArray(); for (int i = 0; i < jsonArray.size(); i++) { final JSONNumber keyCode = jsonArray.get(i).isNumber(); if (keyCode.doubleValue() == event.getNativeEvent().getKeyCode()) { uiService.stackEvent(changeHandlerInstruction); uiService.stackEvent(eventInstruction); uiService.flushEvents(); break; } } } else { uiService.stackEvent(changeHandlerInstruction); uiService.stackEvent(eventInstruction); uiService.flushEvents(); } } }); } else { widget.addDomHandler(new KeyUpHandler() { @Override public void onKeyUp(final KeyUpEvent event) { final PTInstruction eventInstruction = buildEventInstruction(addHandler, domHandlerType); eventInstruction.put(PROPERTY.VALUE, event.getNativeEvent().getKeyCode()); if (eventInstruction.containsKey(PROPERTY.KEY_FILTER)) { final JSONArray jsonArray = addHandler.get(PROPERTY.KEY_FILTER).isArray(); for (int i = 0; i < jsonArray.size(); i++) { final JSONNumber keyCode = jsonArray.get(i).isNumber(); if (keyCode.doubleValue() == event.getNativeEvent().getKeyCode()) { uiService.triggerEvent(eventInstruction); break; } } } else { uiService.triggerEvent(eventInstruction); } } }, KeyUpEvent.getType()); } break; case DRAG_START: widget.getElement().setDraggable(Element.DRAGGABLE_TRUE); widget.addBitlessDomHandler(new DragStartHandler() { @Override public void onDragStart(final DragStartEvent event) { event.setData("text", Long.toString(addHandler.getObjectID())); event.getDataTransfer().setDragImage(uiObject.getElement(), 10, 10); triggerDomEvent(addHandler, domHandlerType, uiService); } }, DragStartEvent.getType()); break; case DRAG_END: widget.addBitlessDomHandler(new DragEndHandler() { @Override public void onDragEnd(final DragEndEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, DragEndEvent.getType()); break; case DRAG_ENTER: widget.addBitlessDomHandler(new DragEnterHandler() { @Override public void onDragEnter(final DragEnterEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, DragEnterEvent.getType()); break; case DRAG_LEAVE: widget.addBitlessDomHandler(new DragLeaveHandler() { @Override public void onDragLeave(final DragLeaveEvent event) { triggerDomEvent(addHandler, domHandlerType, uiService); } }, DragLeaveEvent.getType()); break; case DROP: widget.addBitlessDomHandler(new DragOverHandler() { @Override public void onDragOver(final DragOverEvent event) { // required by GWT api // triggerDomEvent(addHandler, domHandlerType, uiService); } }, DragOverEvent.getType()); widget.addBitlessDomHandler(new DropHandler() { @Override public void onDrop(final DropEvent event) { event.preventDefault(); final String dragWidgetID = event.getData("text"); final PTInstruction eventInstruction = buildEventInstruction(addHandler, domHandlerType); if (dragWidgetID != null) eventInstruction.put(PROPERTY.DRAG_SRC, Long.parseLong(dragWidgetID)); uiService.triggerEvent(eventInstruction); } }, DropEvent.getType()); break; default: log.info("Handler not supported #" + h); break; } }
From source file:com.qualogy.qafe.gwt.client.component.SpreadsheetCell.java
License:Apache License
public void addListeners(FocusLabel focusLabel) { focusLabel.addFocusHandler(new FocusHandler() { public void onFocus(FocusEvent event) { setFocusStyle(true);/*from w w w. j a va 2 s .c o m*/ } }); focusLabel.addBlurHandler(new BlurHandler() { public void onBlur(BlurEvent event) { if (mode == DISPLAY) { // label is loosing focus to text box setFocusStyle(false); } } }); focusLabel.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { toEditMode(); } }); focusLabel.addKeyPressHandler(new KeyPressHandler() { public void onKeyPress(KeyPressEvent event) { if (mode == DISPLAY) { switch (event.getCharCode()) { case KeyCodes.KEY_TAB: break; default: toEditMode(); } } } }); }
From source file:com.qualogy.qafe.gwt.client.ui.renderer.events.EventFactory.java
License:Apache License
public static FocusHandler createFocusListener(final EventListenerGVO ev, final List<InputVariableGVO> input) { return new FocusHandler() { public void onFocus(FocusEvent event) { CallbackHandler.createCallBack(event.getSource(), QAMLConstants.EVENT_ONFOCUS, ev, input); }/*w w w . j a v a2s. c om*/ }; }