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.

ModalWindow.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package com.vaadin.tests;
  2. import com.vaadin.ui.Button;
  3. import com.vaadin.ui.Button.ClickEvent;
  4. import com.vaadin.ui.Button.ClickListener;
  5. import com.vaadin.ui.Label;
  6. import com.vaadin.ui.LegacyWindow;
  7. import com.vaadin.ui.VerticalLayout;
  8. import com.vaadin.ui.Window;
  9. import com.vaadin.v7.ui.TextField;
  10. /**
  11. * Simple program that demonstrates "modal windows" that block all access other
  12. * windows.
  13. *
  14. * @author Vaadin Ltd.
  15. * @since 4.0.1
  16. * @see com.vaadin.server.VaadinSession
  17. * @see com.vaadin.ui.Window
  18. * @see com.vaadin.ui.Label
  19. */
  20. public class ModalWindow extends com.vaadin.server.LegacyApplication
  21. implements ClickListener {
  22. private Window test;
  23. private Button reopen;
  24. @Override
  25. public void init() {
  26. // Create main window
  27. final LegacyWindow main = new LegacyWindow("ModalWindow demo");
  28. setMainWindow(main);
  29. main.addComponent(new Label("ModalWindow demo"));
  30. // Main window textfield
  31. final TextField f = new TextField();
  32. f.setTabIndex(1);
  33. main.addComponent(f);
  34. // Main window button
  35. final Button b = new Button("Test Button in main window");
  36. b.addClickListener(this);
  37. b.setTabIndex(2);
  38. main.addComponent(b);
  39. reopen = new Button("Open modal subwindow");
  40. reopen.addClickListener(this);
  41. reopen.setTabIndex(3);
  42. main.addComponent(reopen);
  43. }
  44. @Override
  45. public void buttonClick(ClickEvent event) {
  46. if (event.getButton() == reopen) {
  47. openSubWindow();
  48. }
  49. getMainWindow().addComponent(
  50. new Label("Button click: " + event.getButton().getCaption()));
  51. }
  52. private void openSubWindow() {
  53. // Modal window
  54. VerticalLayout layout = new VerticalLayout();
  55. layout.setMargin(true);
  56. test = new Window("Modal window", layout);
  57. test.setModal(true);
  58. getMainWindow().addWindow(test);
  59. layout.addComponent(new Label(
  60. "You have to close this window before accessing others."));
  61. // Textfield for modal window
  62. final TextField f = new TextField();
  63. f.setTabIndex(4);
  64. layout.addComponent(f);
  65. f.focus();
  66. // Modal window button
  67. final Button b = new Button("Test Button in modal window");
  68. b.setTabIndex(5);
  69. b.addClickListener(this);
  70. layout.addComponent(b);
  71. }
  72. }