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.

ShortCutListenerModification.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.vaadin.tests.components.button;
  2. import com.vaadin.event.ShortcutAction.KeyCode;
  3. import com.vaadin.event.ShortcutAction.ModifierKey;
  4. import com.vaadin.tests.components.TestBase;
  5. import com.vaadin.ui.Button;
  6. import com.vaadin.ui.Button.ClickEvent;
  7. import com.vaadin.ui.Button.ClickListener;
  8. import com.vaadin.ui.Component;
  9. import com.vaadin.ui.Notification;
  10. import com.vaadin.ui.VerticalLayout;
  11. import com.vaadin.ui.Window;
  12. @SuppressWarnings("serial")
  13. public class ShortCutListenerModification extends TestBase
  14. implements ClickListener {
  15. @Override
  16. protected String getDescription() {
  17. return "Modifiying listeners in shortcuthandler should succeed. Hitting CTRL-C should close windows one by one.";
  18. }
  19. @Override
  20. protected Integer getTicketNumber() {
  21. return 5350;
  22. }
  23. @Override
  24. protected void setup() {
  25. Button prev = null;
  26. for (int j = 0; j < 20; j++) {
  27. VerticalLayout layout = new VerticalLayout();
  28. layout.setMargin(true);
  29. Window window = new Window();
  30. window.setContent(layout);
  31. getMainWindow().addWindow(window);
  32. Button button1 = new Button("b1 (CTRL-C)");
  33. Button button2 = new Button("b2 (CTRL-V)");
  34. button1.addClickListener(this);
  35. button2.addClickListener(this);
  36. button1.setClickShortcut(KeyCode.C, ModifierKey.CTRL);
  37. button2.setClickShortcut(KeyCode.V, ModifierKey.CTRL);
  38. layout.addComponent(button1);
  39. layout.addComponent(button2);
  40. button1.focus();
  41. button1.setData(prev);
  42. prev = button1;
  43. }
  44. }
  45. @Override
  46. public void error(com.vaadin.server.ErrorEvent event) {
  47. super.error(event);
  48. getMainWindow().showNotification("Failed!",
  49. Notification.TYPE_ERROR_MESSAGE);
  50. }
  51. @Override
  52. public void buttonClick(ClickEvent event) {
  53. Component c = event.getButton();
  54. while (!(c instanceof Window)) {
  55. c = c.getParent();
  56. }
  57. ((Window) c).close();
  58. Button prev = (Button) event.getButton().getData();
  59. if (prev != null) {
  60. prev.focus();
  61. }
  62. }
  63. }