You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GridKeyPressEvent.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.widget.grid.events;
  17. import com.google.gwt.dom.client.BrowserEvents;
  18. import com.vaadin.client.widget.grid.CellReference;
  19. import com.vaadin.client.widget.grid.events.AbstractGridKeyEventHandler.GridKeyPressHandler;
  20. import com.vaadin.client.widgets.Grid;
  21. import com.vaadin.client.widgets.Grid.AbstractGridKeyEvent;
  22. import com.vaadin.shared.ui.grid.GridConstants.Section;
  23. /**
  24. * Represents native key press event in Grid.
  25. *
  26. * @since 7.4
  27. * @author Vaadin Ltd
  28. */
  29. public class GridKeyPressEvent
  30. extends AbstractGridKeyEvent<GridKeyPressHandler> {
  31. public static final Type<GridKeyPressHandler> TYPE = new Type<GridKeyPressHandler>(
  32. BrowserEvents.KEYPRESS, new GridKeyPressEvent());
  33. /**
  34. * @since 7.7.9
  35. */
  36. public GridKeyPressEvent() {
  37. }
  38. /**
  39. * @deprecated This constructor's arguments are no longer used. Use the
  40. * no-args constructor instead.
  41. */
  42. @Deprecated
  43. public GridKeyPressEvent(Grid<?> grid, CellReference<?> targetCell) {
  44. }
  45. @Override
  46. public Type<GridKeyPressHandler> getAssociatedType() {
  47. return TYPE;
  48. }
  49. @Override
  50. protected void doDispatch(GridKeyPressHandler handler, Section section) {
  51. if ((section == Section.BODY && handler instanceof BodyKeyPressHandler)
  52. || (section == Section.HEADER
  53. && handler instanceof HeaderKeyPressHandler)
  54. || (section == Section.FOOTER
  55. && handler instanceof FooterKeyPressHandler)) {
  56. handler.onKeyPress(this);
  57. }
  58. }
  59. @Override
  60. protected String getBrowserEventType() {
  61. return BrowserEvents.KEYPRESS;
  62. }
  63. /**
  64. * Gets the char code for this event.
  65. *
  66. * @return the char code
  67. */
  68. public char getCharCode() {
  69. return (char) getUnicodeCharCode();
  70. }
  71. /**
  72. * Gets the Unicode char code (code point) for this event.
  73. *
  74. * @return the Unicode char code
  75. */
  76. public int getUnicodeCharCode() {
  77. return getNativeEvent().getCharCode();
  78. }
  79. @Override
  80. public String toDebugString() {
  81. return super.toDebugString() + "[" + getCharCode() + "]";
  82. }
  83. }