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.

SubWindowFocusAndBlurListeners.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.vaadin.tests.components.window;
  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.ui.Button;
  7. import com.vaadin.ui.ComponentContainer;
  8. import com.vaadin.ui.Notification;
  9. import com.vaadin.ui.UI;
  10. import com.vaadin.ui.VerticalLayout;
  11. import com.vaadin.ui.Window;
  12. import com.vaadin.v7.ui.TextField;
  13. public class SubWindowFocusAndBlurListeners extends TestBase {
  14. @Override
  15. protected String getDescription() {
  16. return "Focus and blur listeners should work. Note the "
  17. + "side efect (focusing) when callintg bring to front.";
  18. }
  19. @Override
  20. protected Integer getTicketNumber() {
  21. return 5039;
  22. }
  23. @Override
  24. protected void setup() {
  25. VerticalLayout layout = new VerticalLayout();
  26. layout.setMargin(true);
  27. final Window window = new Window("Focus test window", layout);
  28. layout.setSizeUndefined();
  29. layout.addComponent(new TextField());
  30. window.addFocusListener(event -> Notification.show("Focused window"));
  31. window.addBlurListener(event -> Notification.show("Blurred window"));
  32. window.addActionHandler(new Handler() {
  33. private Action[] s = { new ShortcutAction("^Save") };
  34. @Override
  35. public Action[] getActions(Object target, Object sender) {
  36. return s;
  37. }
  38. @Override
  39. public void handleAction(Action action, Object sender,
  40. Object target) {
  41. Notification.show("Action!");
  42. }
  43. });
  44. UI main = getLayout().getUI();
  45. main.addWindow(window);
  46. ((ComponentContainer) main.getContent()).addComponent(new TextField());
  47. Button button = new Button("Bring to front (should focus too)",
  48. event -> window.bringToFront());
  49. ((ComponentContainer) main.getContent()).addComponent(button);
  50. Window window2 = new Window("Another window for testing");
  51. main.addWindow(window2);
  52. window2.setPositionX(50);
  53. }
  54. }