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.

ButtonEnterWithWindowShortcut.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.vaadin.tests.components.button;
  2. import com.vaadin.event.Action;
  3. import com.vaadin.event.Action.Handler;
  4. import com.vaadin.event.ShortcutAction;
  5. import com.vaadin.tests.components.TestBase;
  6. import com.vaadin.tests.util.Log;
  7. import com.vaadin.ui.Button;
  8. public class ButtonEnterWithWindowShortcut extends TestBase {
  9. Log log = new Log(5);
  10. @Override
  11. protected void setup() {
  12. getMainWindow().addActionHandler(new Handler() {
  13. private static final long serialVersionUID = -4976129418325394913L;
  14. @Override
  15. public void handleAction(Action action, Object sender,
  16. Object target) {
  17. log.log(action.getCaption() + " pressed in window");
  18. }
  19. @Override
  20. public Action[] getActions(Object target, Object sender) {
  21. ShortcutAction enter = new ShortcutAction("enter",
  22. ShortcutAction.KeyCode.ENTER, null);
  23. ShortcutAction space = new ShortcutAction("space",
  24. ShortcutAction.KeyCode.SPACEBAR, null);
  25. return new Action[] { enter, space };
  26. }
  27. });
  28. Button button = new Button("Focus me and press enter",
  29. event -> log.log("button click listener fired"));
  30. button.focus();
  31. addComponent(log);
  32. addComponent(button);
  33. }
  34. @Override
  35. protected String getDescription() {
  36. return "Pressing enter or space with the button focused should trigger the button click listener and not the shortcut action on the window.";
  37. }
  38. @Override
  39. protected Integer getTicketNumber() {
  40. return Integer.valueOf(5433);
  41. }
  42. }