/** * Sets an event handler for an {@code Element}. All previous event handlers of this type of event are removed. * @param element The element to bind the event handler for * @param eventType The event type (e.g. {@code ClickEvent.getType()}) * @param handler The handler that handler the event */ public static <H extends EventHandler> void setEventHandler(final Element element, DomEvent.Type<H> eventType, H handler) { if (element == null) { return; } HandlerManager hm = handlerManagers.get(element); if (hm == null) { handlerManagers.put(element, hm = new HandlerManager(element)); DOM.setEventListener(element, new EventListener() { @Override public void onBrowserEvent(Event event) { DomEvent.fireNativeEvent(event, handlerManagers.get(element), element); } }); } DOM.sinkBitlessEvent(element, eventType.getName()); while (hm.getHandlerCount(eventType) > 0) { hm.removeHandler(eventType, hm.getHandler(eventType, 0)); } hm.addHandler(eventType, handler); }
@UiHandler("paletteChooser") void onPaletteChooserMouseWheel(MouseWheelEvent event) { // determine new index based on scroll direction int newIndex = paletteChooser.getSelectedIndex(); if (event.getDeltaY() < 0) { newIndex--; } else { newIndex++; } // set new index (if it's valid) and trigger change event (is not automatically triggered) if (newIndex >= 0 && newIndex < paletteChooser.getItemCount()) { paletteChooser.setSelectedIndex(newIndex); DomEvent.fireNativeEvent(Document.get().createChangeEvent(), paletteChooser); } }
private void finishEdit(DomEvent<?> event, boolean save) { int index = getItemIndexFromEvent(event); Task task = getItem(index, true); TaskAdapterView view = getItemView(index); if (save) { if (view.getNameInput().getValue().trim().length() == 0) { removeTask(index); } else { task.setName(view.getNameInput().getValue()); view.getName().setInnerText(task.getName()); Dao.onTasksChanged(); } } view.getEditButton().removeClassName("hidden"); view.getRemoveButton().removeClassName("hidden"); view.getName().removeClassName("hidden"); view.getNameInput().addClassName("hidden"); }
@SuppressWarnings("unchecked") @Override public void setValue(final AdministratedApplicationConfig value, final boolean fireEvents) { for (int i = 0; i < connectorListBox.getItemCount(); i++) { if(connectorListBox.getValue(i).equals(value.getBlockchainSource().name())) { connectorListBox.setSelectedIndex(i); DomEvent.fireNativeEvent(Document.get().createChangeEvent(), connectorListBox); break; } } currentEditor.setValue(value); applicationTitle.setText(value.getApplicationTitle()); applicationSubtitle.setText(value.getApplicationSubTitle()); donationAddress.setText(value.getHostDonationAddress()); }
public void prepare() { canvas = new GWTCanvas(width, height); popupPanel.setWidget(canvas); for (Entry<EventHandler, DomEvent.Type<EventHandler>> entry : eventHandlers.entrySet()) { canvas.addDomHandler(entry.getKey(), entry.getValue()); } }
@Test public void testTextBox() throws Exception { TextBox tb = new TextBox(); RootPanel.get().add(tb); final List events = new ArrayList(); tb.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { events.add(event); } }); DomEvent.fireNativeEvent(Document.get().createChangeEvent(), tb); assertEquals(1, events.size()); }
protected void broadcastBlurEvent() { final NativeEvent blur = Document.get().createBlurEvent(); for (int i = 0; i < RootPanel.get().getWidgetCount(); i++) { final Widget w = RootPanel.get().getWidget(i); DomEvent.fireNativeEvent(blur, w); } }
private void onMouseOrTouchUp(DomEvent event, int x, int y, boolean isTouch) { s_logger.log(Level.INFO, "up"); if( !m_isMouseDown ) { return; } m_wasMouseJustDown = m_isMouseDown; // should always be the case; m_isMouseDown = false; this.setMousePoint(x, y, m_mouseEvent.getPoint()); m_mouseEvent.set(E_MouseEventType.MOUSE_UP, 0, Element.as(event.getNativeEvent().getEventTarget()), isTouch); dispatchEvent(m_mouseEvent); Event.releaseCapture(m_container.getElement()); event.preventDefault(); }
private void onMouseOrTouchDown(DomEvent event, int x, int y, boolean isTouch) { m_isTouching = isTouch; s_logger.log(Level.INFO, "down"); m_isMouseDown = true; m_hasMouseStrayedWhileDown = false; setMousePoint(x, y, m_mouseDownPoint); m_mouseEvent.getPoint().copy(m_mouseDownPoint); m_mouseEvent.set(E_MouseEventType.MOUSE_DOWN, 0, Element.as(event.getNativeEvent().getEventTarget()), isTouch); dispatchEvent(m_mouseEvent); Event.setCapture(m_container.getElement()); event.preventDefault(); }
protected void broadcastBlurEvent() { final NativeEvent blur = Document.get().createBlurEvent(); for ( int i = 0; i < RootPanel.get().getWidgetCount(); i++ ) { final Widget w = RootPanel.get().getWidget( i ); DomEvent.fireNativeEvent( blur, w ); } }
@Override public void call(String moduleName, AsyncCallback<Void> callback) { LOG.info("ModuleReadyFeatureProvider.call: moduleName=" + moduleName); for (ModuleBean moduleBean : moduleUnreadyList) if (Utils.equals(moduleName, moduleBean.getName())) { moduleReadyList.add(moduleBean); moduleUnreadyList.remove(moduleBean); if (moduleUnreadyList.isEmpty()) { timeoutTimer.cancel(); DomEvent.fireNativeEvent(Document.get().createLoadEvent(), this); } return; } throw new IllegalArgumentException("Module with name '" + moduleName + "' isn't expected"); }
private void processNewPackage(String newPackageName) { if (newPackageName != null && !"".equals(newPackageName.trim())) { boolean exists = false; newPackageName = newPackageName.trim(); int count = packageList.getItemCount(); if (count > 0) { for (int i = 0; i < count; i++) { if ((exists = newPackageName.equals(packageList.getValue(i)))) break; } } if (exists) { packageList.setSelectedValue(newPackageName); } else { packageList.addItem(newPackageName, newPackageName); packageList.setSelectedValue(newPackageName); DomEvent.fireNativeEvent(Document.get().createChangeEvent(), packageList); } } }
@Override public void onBrowserEvent(Event event) { // If we're not yet dragging, only trigger mouse events if the event occurs // in the caption wrapper if (this.resizable) { switch (event.getTypeInt()) { case Event.ONMOUSEDOWN: case Event.ONMOUSEUP: case Event.ONMOUSEMOVE: case Event.ONMOUSEOVER: case Event.ONMOUSEOUT: if (this.dragMode >= 0 || calcDragMode(event.getClientX(),event.getClientY()) >= 0) { // paste'n'copy from Widget.onBrowserEvent switch (DOM.eventGetType(event)) { case Event.ONMOUSEOVER: // Only fire the mouse over event if it's coming from outside this // widget. case Event.ONMOUSEOUT: // Only fire the mouse out event if it's leaving this // widget. Element related = event.getRelatedEventTarget().cast(); if (related != null && getElement().isOrHasChild(related)) { return; } break; } DomEvent.fireNativeEvent(event, this, this.getElement()); return; } if (this.dragMode<0) this.updateCursor(this.dragMode); } } super.onBrowserEvent(event); }
@Override protected void init() { super.init(); getWidget()._delegate.cellClickListener = new TableCellClickListener() { @Override public void onClick(String columnKey, int rowKey) { getRpcProxy(CubaTableServerRpc.class).onClick(columnKey, String.valueOf(rowKey)); } }; tooltipHandlerRegistration = Event.addNativePreviewHandler(new Event.NativePreviewHandler() { @Override public void onPreviewNativeEvent(Event.NativePreviewEvent event) { if (event.getTypeInt() != Event.ONMOUSEMOVE || !Element.is(event.getNativeEvent().getEventTarget())) { return; } Element element = Element.as(event.getNativeEvent().getEventTarget()); if ("div".equalsIgnoreCase(element.getTagName())) { String className = element.getClassName(); if (className != null && (className.contains("v-table-caption-container") || className.contains("v-table-footer-container"))) { DomEvent.fireNativeEvent(event.getNativeEvent(), getWidget()); } } } }); }
<H extends EventHandler> HandlerRegistration addHandler( final H handler, DomEvent.Type<H> type) { return addDomHandler(handler, type); }
@Override public final DomEvent.Type<MouseComeLeaveHandler> getAssociatedType() { return TYPE; }
/** * Returns the item index that is related to an event fired from within an item view. If the event is not * fired from a sub-view of the item or the view is no longer attached in the hierarchy, it returns -1. * @param event The event from the event handler. * @return The item index associated with the event or -1 if the event was not fired from this {@code ViewAdapter}. */ public int getItemIndexFromEvent(DomEvent<?> event) { Element e = event.getNativeEvent().getCurrentEventTarget().cast(); while (e != null && e.getParentElement() != parentElement) { e = e.getParentElement(); } if (e == null) { return -1; } Integer index = rootElementsToIndexMap.get(e); return (index == null ? -1 : index); }
/** * This gets called by the JSNI code for every event that we want to handle. * @param elementId the unique ID of the HFRichTextEditor. Used to locate the source of the event. * @param event the NativeEvent that we will fire into the GWT event handling loop */ public static void handleNativeEvent(String elementId, Object event) { if (event instanceof NativeEvent) { HFRichTextEditor editorInstance = getActiveEditor(elementId); if (editorInstance != null) { DomEvent.fireNativeEvent((NativeEvent) event, editorInstance); } } }
@Override public void add(final Widget child) { String tagName = child.getElement().getTagName(); if (child instanceof ListItem || tagName.toLowerCase().startsWith("li")) { child.getElement().getStyle().setDisplay(Style.Display.BLOCK); add(child, (Element) getElement()); } else { ListItem li = new ListItem(child); // Checks if there are sub dropdown components if (child instanceof MaterialLink) { MaterialLink link = (MaterialLink) child; for (int i = 0; i < link.getWidgetCount(); i++) { if (link.getWidget(i) instanceof MaterialDropDown) { registerHandler(link.addClickHandler(DomEvent::stopPropagation)); link.stopTouchStartEvent(); } } } if (child instanceof HasWaves) { li.setWaves(((HasWaves) child).getWaves()); ((HasWaves) child).setWaves(null); } li.getElement().getStyle().setDisplay(Style.Display.BLOCK); add(li, (Element) getElement()); } }
public void fireFocusEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createFocusEvent(), widget); }
public void fireBlurEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createBlurEvent(), widget); }
public void fireClickEvent(HasHandlers widget) { DomEvent.fireNativeEvent( Document.get().createClickEvent(1, 1, 1, 1, 1, false, false, false, false), widget ); }
public void fireDoubleClickEvent(HasHandlers widget) { DomEvent.fireNativeEvent( Document.get().createDblClickEvent(1, 1, 1, 1, 1, false, false, false, false), widget ); }
public void fireKeyDownEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createKeyDownEvent(false, false, false, false, 1), widget); }
public void fireKeyPressEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createKeyPressEvent(false, false, false, false, 1), widget); }
public void fireGestureStartEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createHtmlEvent(BrowserEvents.GESTURESTART, false, false), widget); }
public void fireGestureChangeEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createHtmlEvent(BrowserEvents.GESTURECHANGE, false, false), widget); }
public void fireGestureEndEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createHtmlEvent(BrowserEvents.GESTUREEND, false, false), widget); }
public void fireTouchCancelEvent(HasHandlers widget) { DomEvent.fireNativeEvent(Document.get().createHtmlEvent(BrowserEvents.TOUCHCANCEL, false, false), widget); }
public HandlerRegistration addConstraintMatchBlurHandler(final BlurHandler blurHandler) { HandlerRegistration registration = constraintMatchTextBox.addBlurHandler(blurHandler); DomEvent.fireNativeEvent(Document.get().createBlurEvent(), constraintMatchTextBox); return registration; }
/** {@inheritDoc} */ @Override public void onBrowserEvent(Event event) { switch (event.getTypeInt()) { case Event.ONCLICK: onClick(event); break; case Event.ONDBLCLICK: onDoubleClick(event); break; case Event.ONSCROLL: onScroll(event); break; case Event.ONFOCUS: onFocus(event); break; case Event.ONBLUR: onBlur(event); break; case Event.ONCONTEXTMENU: if (disableNativeContextMenu) { event.preventDefault(); } onRightClick(event); break; } view.onEvent(event); // we are not calling super so must fire dom events DomEvent.fireNativeEvent(event, this, this.getElement()); }
public void setValue(T value) { T a = getValue(); T b = bound(value); if (!isEqual(a, b)) { this.box.setValue(b); DomEvent.fireNativeEvent(Document.get().createChangeEvent(), box); } }
public void setType(String type) { int index = 0; for (int i = 0; i < this.type.getItemCount(); i++) { if (type.equals(this.type.getValue(i))) index = i; } this.type.setItemSelected(index, true); DomEvent.fireNativeEvent(Document.get().createChangeEvent(), this.type); }
private void fireChangeEvent() { DomEvent.fireNativeEvent(Document.get().createChangeEvent(), this); }
private void fireFocusEvent() { DomEvent.fireNativeEvent(Document.get().createFocusEvent(), this); }
private void fireBlurEvent() { DomEvent.fireNativeEvent(Document.get().createBlurEvent(), this); }
public ConfigViewImpl() { initWidget(UI_BINDER.createAndBindUi(this)); for (final BlockchainSource source : compatibleSources) { connectorListBox.addItem(M.messages().configConnectorOption(source), source.name()); } DomEvent.fireNativeEvent(Document.get().createChangeEvent(), connectorListBox); StyleUtil.setPlaceHolder(createPassword, M.messages().configPasswordPlaceHolder()); StyleUtil.setPlaceHolder(password, M.messages().configPasswordPlaceHolder()); StyleUtil.setPlaceHolder(createPasswordRepeat, M.messages().configPasswordRepeatPlaceHolder()); }
static void dispatchEvent(Event event, boolean hasFocus) { if (instance != null) { instance.hasFocus = hasFocus; DomEvent.fireNativeEvent(event, instance); } }