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.

FocusableFlexTable.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.terminal.gwt.client.ui;
  5. import com.google.gwt.event.dom.client.BlurEvent;
  6. import com.google.gwt.event.dom.client.BlurHandler;
  7. import com.google.gwt.event.dom.client.FocusEvent;
  8. import com.google.gwt.event.dom.client.FocusHandler;
  9. import com.google.gwt.event.dom.client.HasBlurHandlers;
  10. import com.google.gwt.event.dom.client.HasFocusHandlers;
  11. import com.google.gwt.event.dom.client.HasKeyDownHandlers;
  12. import com.google.gwt.event.dom.client.HasKeyPressHandlers;
  13. import com.google.gwt.event.dom.client.KeyDownEvent;
  14. import com.google.gwt.event.dom.client.KeyDownHandler;
  15. import com.google.gwt.event.dom.client.KeyPressEvent;
  16. import com.google.gwt.event.dom.client.KeyPressHandler;
  17. import com.google.gwt.event.shared.HandlerRegistration;
  18. import com.google.gwt.user.client.ui.FlexTable;
  19. import com.google.gwt.user.client.ui.impl.FocusImpl;
  20. import com.vaadin.terminal.gwt.client.Focusable;
  21. /**
  22. * Adds keyboard focus to {@link FlexPanel}.
  23. */
  24. public class FocusableFlexTable extends FlexTable implements HasFocusHandlers,
  25. HasBlurHandlers, HasKeyDownHandlers, HasKeyPressHandlers, Focusable {
  26. /**
  27. * Default constructor.
  28. */
  29. public FocusableFlexTable() {
  30. // make focusable, as we don't need access key magic we don't need to
  31. // use FocusImpl.createFocusable
  32. getElement().setTabIndex(0);
  33. }
  34. /*
  35. * (non-Javadoc)
  36. *
  37. * @see
  38. * com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.
  39. * google.gwt.event.dom.client.FocusHandler)
  40. */
  41. public HandlerRegistration addFocusHandler(FocusHandler handler) {
  42. return addDomHandler(handler, FocusEvent.getType());
  43. }
  44. /*
  45. * (non-Javadoc)
  46. *
  47. * @see
  48. * com.google.gwt.event.dom.client.HasBlurHandlers#addBlurHandler(com.google
  49. * .gwt.event.dom.client.BlurHandler)
  50. */
  51. public HandlerRegistration addBlurHandler(BlurHandler handler) {
  52. return addDomHandler(handler, BlurEvent.getType());
  53. }
  54. /*
  55. * (non-Javadoc)
  56. *
  57. * @see
  58. * com.google.gwt.event.dom.client.HasKeyDownHandlers#addKeyDownHandler(
  59. * com.google.gwt.event.dom.client.KeyDownHandler)
  60. */
  61. public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
  62. return addDomHandler(handler, KeyDownEvent.getType());
  63. }
  64. /*
  65. * (non-Javadoc)
  66. *
  67. * @see
  68. * com.google.gwt.event.dom.client.HasKeyPressHandlers#addKeyPressHandler
  69. * (com.google.gwt.event.dom.client.KeyPressHandler)
  70. */
  71. public HandlerRegistration addKeyPressHandler(KeyPressHandler handler) {
  72. return addDomHandler(handler, KeyPressEvent.getType());
  73. }
  74. /**
  75. * Sets the keyboard focus to the panel
  76. *
  77. * @param focus
  78. * Should the panel have keyboard focus. If true the keyboard
  79. * focus will be moved to the
  80. */
  81. public void setFocus(boolean focus) {
  82. if (focus) {
  83. FocusImpl.getFocusImplForPanel().focus(getElement());
  84. } else {
  85. FocusImpl.getFocusImplForPanel().blur(getElement());
  86. }
  87. }
  88. /*
  89. * (non-Javadoc)
  90. *
  91. * @see com.vaadin.terminal.gwt.client.Focusable#focus()
  92. */
  93. public void focus() {
  94. setFocus(true);
  95. }
  96. }