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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.tests;
  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.Label;
  9. import com.vaadin.ui.TextField;
  10. import com.vaadin.ui.Window;
  11. /**
  12. * Simple program that demonstrates "modal windows" that block all access other
  13. * windows.
  14. *
  15. * @author IT Mill Ltd.
  16. * @since 4.0.1
  17. * @see com.vaadin.Application
  18. * @see com.vaadin.ui.Window
  19. * @see com.vaadin.ui.Label
  20. */
  21. public class ModalWindow extends com.vaadin.Application implements
  22. ClickListener {
  23. private Window test;
  24. private Button reopen;
  25. @Override
  26. public void init() {
  27. // Create main window
  28. final Window main = new Window("ModalWindow demo");
  29. setMainWindow(main);
  30. main.addComponent(new Label("ModalWindow demo"));
  31. // Main window textfield
  32. final TextField f = new TextField();
  33. f.setTabIndex(1);
  34. main.addComponent(f);
  35. // Main window button
  36. final Button b = new Button("Test Button in main window");
  37. b.addListener(this);
  38. b.setTabIndex(2);
  39. main.addComponent(b);
  40. reopen = new Button("Open modal subwindow");
  41. reopen.addListener(this);
  42. reopen.setTabIndex(3);
  43. main.addComponent(reopen);
  44. }
  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. test = new Window("Modal window");
  55. test.setModal(true);
  56. getMainWindow().addWindow(test);
  57. test.addComponent(new Label(
  58. "You have to close this window before accessing others."));
  59. // Textfield for modal window
  60. final TextField f = new TextField();
  61. f.setTabIndex(4);
  62. test.addComponent(f);
  63. f.focus();
  64. // Modal window button
  65. final Button b = new Button("Test Button in modal window");
  66. b.setTabIndex(5);
  67. b.addListener(this);
  68. test.addComponent(b);
  69. }
  70. }