List of usage examples for com.google.gwt.dom.client BrowserEvents KEYPRESS
String KEYPRESS
To view the source code for com.google.gwt.dom.client BrowserEvents KEYPRESS.
Click Source Link
From source file:cc.alcina.framework.gwt.client.widget.dialog.RelativePopupPanel.java
License:Apache License
/** * Preview the {@link NativePreviewEvent}. * /*from w w w . ja v a2 s. c o m*/ * @param event * the {@link NativePreviewEvent} */ private void previewNativeEvent(NativePreviewEvent event) { // If the event has been canceled or consumed, ignore it if (event.isCanceled() || (!previewAllNativeEvents && event.isConsumed())) { // We need to ensure that we cancel the event even if its been // consumed so // that popups lower on the stack do not auto hide if (modal) { event.cancel(); } return; } // Fire the event hook and return if the event is canceled onPreviewNativeEvent(event); if (event.isCanceled()) { return; } // If the event targets the popup or the partner, consume it Event nativeEvent = Event.as(event.getNativeEvent()); boolean eventTargetsPopupOrPartner = eventTargetsPopup(nativeEvent) || eventTargetsPartner(nativeEvent); if (eventTargetsPopupOrPartner) { event.consume(); } // Cancel the event if it doesn't target the modal popup. Note that the // event can be both canceled and consumed. if (modal) { switch (nativeEvent.getType()) { case BrowserEvents.KEYDOWN: case BrowserEvents.KEYPRESS: case BrowserEvents.KEYUP: if (nativeEvent.getAltKey() || nativeEvent.getMetaKey() || nativeEvent.getCtrlKey()) { return; } } event.cancel(); } // Switch on the event type int type = nativeEvent.getTypeInt(); switch (type) { case Event.ONMOUSEDOWN: case Event.ONTOUCHSTART: // Don't eat events if event capture is enabled, as this can // interfere with dialog dragging, for example. if (DOM.getCaptureElement() != null) { event.consume(); return; } if (!eventTargetsPopupOrPartner && autoHide) { EventTarget target = nativeEvent.getEventTarget(); // if (Element.is(target)) { // ClientUtils.dumpElementTree(Element.as(target)); // } hide(true); return; } break; case Event.ONMOUSEUP: case Event.ONMOUSEMOVE: case Event.ONCLICK: case Event.ONDBLCLICK: { // Don't eat events if event capture is enabled, as this can // interfere with dialog dragging, for example. if (DOM.getCaptureElement() != null) { event.consume(); return; } break; } case Event.ONFOCUS: { if (nativeEvent.getEventTarget().is(Element.class)) { Element target = nativeEvent.getEventTarget().cast(); if (modal && !eventTargetsPopupOrPartner && (target != null)) { blur(target); event.cancel(); return; } } break; } case Event.ONKEYPRESS: { if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE && isHideOnEscape()) { hide(false); event.cancel(); return; } break; } } }
From source file:com.vaadin.client.widget.grid.events.GridKeyPressEvent.java
License:Apache License
@Override protected String getBrowserEventType() { return BrowserEvents.KEYPRESS; }
From source file:com.vaadin.client.widgets.Grid.java
License:Apache License
/** * Creates a new instance./*from w w w . java 2s .c o m*/ */ public Grid() { initWidget(escalator); getElement().setTabIndex(0); cellFocusHandler = new CellFocusHandler(); setStylePrimaryName(STYLE_NAME); escalator.getHeader().setEscalatorUpdater(createHeaderUpdater()); escalator.getBody().setEscalatorUpdater(createBodyUpdater()); escalator.getFooter().setEscalatorUpdater(createFooterUpdater()); header.setGrid(this); HeaderRow defaultRow = header.appendRow(); header.setDefaultRow(defaultRow); footer.setGrid(this); editor.setGrid(this); setSelectionMode(SelectionMode.SINGLE); escalator.getBody().setSpacerUpdater(gridSpacerUpdater); escalator.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { fireEvent(new ScrollEvent()); } }); escalator.addRowVisibilityChangeHandler(new RowVisibilityChangeHandler() { @Override public void onRowVisibilityChange(RowVisibilityChangeEvent event) { if (dataSource != null && dataSource.size() != 0) { dataIsBeingFetched = true; dataSource.ensureAvailability(event.getFirstVisibleRow(), event.getVisibleRowCount()); } } }); // Default action on SelectionEvents. Refresh the body so changed // become visible. addSelectionHandler(new SelectionHandler<T>() { @Override public void onSelect(SelectionEvent<T> event) { refreshBody(); } }); // Sink header events and key events sinkEvents(getHeader().getConsumedEvents()); sinkEvents(Arrays.asList(BrowserEvents.KEYDOWN, BrowserEvents.KEYUP, BrowserEvents.KEYPRESS, BrowserEvents.DBLCLICK, BrowserEvents.MOUSEDOWN, BrowserEvents.CLICK)); // Make ENTER and SHIFT+ENTER in the header perform sorting addHeaderKeyUpHandler(new HeaderKeyUpHandler() { @Override public void onKeyUp(GridKeyUpEvent event) { if (event.getNativeKeyCode() != KeyCodes.KEY_ENTER) { return; } if (getHeader().getRow(event.getFocusedCell().getRowIndex()).isDefault()) { // Only sort for enter on the default header sorter.sort(event.getFocusedCell().getColumn(), event.isShiftKeyDown()); } } }); addDataAvailableHandler(new DataAvailableHandler() { @Override public void onDataAvailable(DataAvailableEvent event) { dataIsBeingFetched = false; } }); }
From source file:com.vaadin.client.widgets.Grid.java
License:Apache License
@Override public void onBrowserEvent(Event event) { if (!isEnabled()) { return;//from w w w . j a v a 2 s .c o m } String eventType = event.getType(); if (eventType.equals(BrowserEvents.FOCUS) || eventType.equals(BrowserEvents.BLUR)) { super.onBrowserEvent(event); return; } EventTarget target = event.getEventTarget(); if (!Element.is(target) || isOrContainsInSpacer(Element.as(target))) { return; } Element e = Element.as(target); RowContainer container = escalator.findRowContainer(e); Cell cell; if (container == null) { if (eventType.equals(BrowserEvents.KEYDOWN) || eventType.equals(BrowserEvents.KEYUP) || eventType.equals(BrowserEvents.KEYPRESS)) { cell = cellFocusHandler.getFocusedCell(); container = cellFocusHandler.containerWithFocus; } else { // Click might be in an editor cell, should still map. if (editor.editorOverlay != null && editor.editorOverlay.isOrHasChild(e)) { container = escalator.getBody(); int rowIndex = editor.getRow(); int colIndex = editor.getElementColumn(e); if (colIndex < 0) { // Click in editor, but not for any column. return; } TableCellElement cellElement = container.getRowElement(rowIndex).getCells().getItem(colIndex); cell = new Cell(rowIndex, colIndex, cellElement); } else { if (escalator.getElement().isOrHasChild(e)) { eventCell.set(new Cell(-1, -1, null), Section.BODY); // Fire native events. super.onBrowserEvent(event); } return; } } } else { cell = container.getCell(e); if (eventType.equals(BrowserEvents.MOUSEDOWN)) { cellOnPrevMouseDown = cell; } else if (cell == null && eventType.equals(BrowserEvents.CLICK)) { /* * Chrome has an interesting idea on click targets (see * cellOnPrevMouseDown javadoc). Firefox, on the other hand, has * the mousedown target as the click target. */ cell = cellOnPrevMouseDown; } } assert cell != null : "received " + eventType + "-event with a null cell target"; eventCell.set(cell, getSectionFromContainer(container)); // Editor can steal focus from Grid and is still handled if (isEditorEnabled() && handleEditorEvent(event, container)) { return; } // Fire GridKeyEvents and GridClickEvents. Pass the event to escalator. super.onBrowserEvent(event); if (!isElementInChildWidget(e)) { if (handleHeaderCellDragStartEvent(event, container)) { return; } // Sorting through header Click / KeyUp if (handleHeaderDefaultRowEvent(event, container)) { return; } if (handleRendererEvent(event, container)) { return; } if (handleCellFocusEvent(event, container)) { return; } } }
From source file:com.vaadin.v7.client.widgets.Grid.java
License:Apache License
/** * Creates a new instance./*from w w w . ja va 2 s . c om*/ */ public Grid() { initWidget(escalator); getElement().setTabIndex(0); cellFocusHandler = new CellFocusHandler(); setStylePrimaryName(STYLE_NAME); escalator.getHeader().setEscalatorUpdater(createHeaderUpdater()); escalator.getBody().setEscalatorUpdater(createBodyUpdater()); escalator.getFooter().setEscalatorUpdater(createFooterUpdater()); header.setGrid(this); HeaderRow defaultRow = header.appendRow(); header.setDefaultRow(defaultRow); footer.setGrid(this); editor.setGrid(this); setSelectionMode(SelectionMode.SINGLE); escalator.getBody().setSpacerUpdater(gridSpacerUpdater); escalator.addScrollHandler(new ScrollHandler() { @Override public void onScroll(ScrollEvent event) { fireEvent(new ScrollEvent()); } }); escalator.addRowVisibilityChangeHandler(new RowVisibilityChangeHandler() { @Override public void onRowVisibilityChange(RowVisibilityChangeEvent event) { if (dataSource != null && dataSource.size() != 0) { dataSource.ensureAvailability(event.getFirstVisibleRow(), event.getVisibleRowCount()); } } }); // Default action on SelectionEvents. Refresh the body so changed // become visible. addSelectionHandler(new SelectionHandler<T>() { @Override public void onSelect(SelectionEvent<T> event) { refreshBody(); } }); // Sink header events and key events sinkEvents(getHeader().getConsumedEvents()); sinkEvents(Arrays.asList(BrowserEvents.KEYDOWN, BrowserEvents.KEYUP, BrowserEvents.KEYPRESS, BrowserEvents.DBLCLICK, BrowserEvents.MOUSEDOWN, BrowserEvents.CLICK)); // Make ENTER and SHIFT+ENTER in the header perform sorting addHeaderKeyUpHandler(new HeaderKeyUpHandler() { @Override public void onKeyUp(GridKeyUpEvent event) { if (event.getNativeKeyCode() != KeyCodes.KEY_ENTER) { return; } if (getHeader().getRow(event.getFocusedCell().getRowIndex()).isDefault()) { // Only sort for enter on the default header sorter.sort(event.getFocusedCell().getColumn(), event.isShiftKeyDown()); } } }); browserEventHandlers.addAll(Arrays.asList( // Opening, closing and navigating in the editor new EditorEventHandler(), // Keyboard and click handlers, Escalator events new SuperEventHandler(), // Column reordering via header drag&drop new HeaderCellDragStartHandler(), // Column sorting via header click new HeaderDefaultRowEventHandler(), // Invoking event-aware renderers new RendererEventHandler(), // Moving cell focus by keyboard or mouse new CellFocusEventHandler())); }
From source file:com.vaadin.v7.client.widgets.Grid.java
License:Apache License
@Override public void onBrowserEvent(Event event) { if (!isEnabled()) { return;//w ww. j a va 2 s . c o m } String eventType = event.getType(); if (eventType.equals(BrowserEvents.FOCUS) || eventType.equals(BrowserEvents.BLUR)) { super.onBrowserEvent(event); return; } EventTarget target = event.getEventTarget(); if (!Element.is(target) || isOrContainsInSpacer(Element.as(target))) { return; } Element e = Element.as(target); RowContainer container = escalator.findRowContainer(e); Cell cell; if (container == null) { if (eventType.equals(BrowserEvents.KEYDOWN) || eventType.equals(BrowserEvents.KEYUP) || eventType.equals(BrowserEvents.KEYPRESS)) { cell = cellFocusHandler.getFocusedCell(); container = cellFocusHandler.containerWithFocus; } else { // Click might be in an editor cell, should still map. if (editor.editorOverlay != null && editor.editorOverlay.isOrHasChild(e)) { container = escalator.getBody(); int rowIndex = editor.getRow(); int colIndex = editor.getElementColumn(e); if (colIndex < 0) { // Click in editor, but not for any column. return; } TableCellElement cellElement = container.getRowElement(rowIndex).getCells().getItem(colIndex); cell = new Cell(rowIndex, colIndex, cellElement); } else { if (escalator.getElement().isOrHasChild(e)) { eventCell.set(new Cell(-1, -1, null), Section.BODY); // Fire native events. super.onBrowserEvent(event); } return; } } } else { cell = container.getCell(e); if (eventType.equals(BrowserEvents.MOUSEDOWN)) { cellOnPrevMouseDown = cell; } else if (cell == null && eventType.equals(BrowserEvents.CLICK)) { /* * Chrome has an interesting idea on click targets (see * cellOnPrevMouseDown javadoc). Firefox, on the other hand, has * the mousedown target as the click target. */ cell = cellOnPrevMouseDown; } } assert cell != null : "received " + eventType + "-event with a null cell target"; eventCell.set(cell, getSectionFromContainer(container)); GridEvent<T> gridEvent = new GridEvent<>(event, eventCell); for (GridEventHandler<T> handler : browserEventHandlers) { handler.onEvent(gridEvent); } }