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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests;
  17. import com.vaadin.ui.Button;
  18. import com.vaadin.ui.Button.ClickEvent;
  19. import com.vaadin.ui.Button.ClickListener;
  20. import com.vaadin.ui.Label;
  21. import com.vaadin.ui.LegacyWindow;
  22. import com.vaadin.ui.TextField;
  23. import com.vaadin.ui.VerticalLayout;
  24. import com.vaadin.ui.Window;
  25. /**
  26. * Simple program that demonstrates "modal windows" that block all access other
  27. * windows.
  28. *
  29. * @author Vaadin Ltd.
  30. * @since 4.0.1
  31. * @see com.vaadin.server.VaadinSession
  32. * @see com.vaadin.ui.Window
  33. * @see com.vaadin.ui.Label
  34. */
  35. public class ModalWindow extends com.vaadin.server.LegacyApplication
  36. implements ClickListener {
  37. private Window test;
  38. private Button reopen;
  39. @Override
  40. public void init() {
  41. // Create main window
  42. final LegacyWindow main = new LegacyWindow("ModalWindow demo");
  43. setMainWindow(main);
  44. main.addComponent(new Label("ModalWindow demo"));
  45. // Main window textfield
  46. final TextField f = new TextField();
  47. f.setTabIndex(1);
  48. main.addComponent(f);
  49. // Main window button
  50. final Button b = new Button("Test Button in main window");
  51. b.addListener(this);
  52. b.setTabIndex(2);
  53. main.addComponent(b);
  54. reopen = new Button("Open modal subwindow");
  55. reopen.addListener(this);
  56. reopen.setTabIndex(3);
  57. main.addComponent(reopen);
  58. }
  59. @Override
  60. public void buttonClick(ClickEvent event) {
  61. if (event.getButton() == reopen) {
  62. openSubWindow();
  63. }
  64. getMainWindow().addComponent(
  65. new Label("Button click: " + event.getButton().getCaption()));
  66. }
  67. private void openSubWindow() {
  68. // Modal window
  69. VerticalLayout layout = new VerticalLayout();
  70. layout.setMargin(true);
  71. test = new Window("Modal window", layout);
  72. test.setModal(true);
  73. getMainWindow().addWindow(test);
  74. layout.addComponent(new Label(
  75. "You have to close this window before accessing others."));
  76. // Textfield for modal window
  77. final TextField f = new TextField();
  78. f.setTabIndex(4);
  79. layout.addComponent(f);
  80. f.focus();
  81. // Modal window button
  82. final Button b = new Button("Test Button in modal window");
  83. b.setTabIndex(5);
  84. b.addListener(this);
  85. layout.addComponent(b);
  86. }
  87. }