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.

WindowingExample.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.automatedtests.featurebrowser;
  5. import java.net.URL;
  6. import com.vaadin.terminal.ExternalResource;
  7. import com.vaadin.ui.Button;
  8. import com.vaadin.ui.CustomComponent;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.VerticalLayout;
  11. import com.vaadin.ui.Window;
  12. import com.vaadin.ui.Button.ClickEvent;
  13. /**
  14. * @author marc
  15. *
  16. */
  17. public class WindowingExample extends CustomComponent {
  18. public static final String txt = "<p>There are two main types of windows: application-level windows, and "
  19. + "\"sub windows\".</p><p>A sub window is rendered as a \"inline\" popup window"
  20. + " within the (native) browser window to which it was added. You can create"
  21. + " a sub window by creating a new Window and adding it to a application-level window, for instance"
  22. + " your main window. </p><p> In contrast, you create a application-level window by"
  23. + " creating a new Window and adding it to the Application. Application-level"
  24. + " windows are not shown by default - you need to open a browser window for"
  25. + " the url representing the window. You can think of the application-level"
  26. + " windows as separate views into your application - and a way to create a"
  27. + " \"native\" browser window.</p><p>Depending on your needs, it's also"
  28. + " possible to create a new window instance (with it's own internal state)"
  29. + " for each new (native) browser window, or you can share the same instance"
  30. + " (and state) between several browser windows (the latter is most useful"
  31. + " for read-only views).</p>";
  32. private URL windowUrl = null;
  33. public WindowingExample() {
  34. final VerticalLayout main = new VerticalLayout();
  35. main.setMargin(true);
  36. setCompositionRoot(main);
  37. final Label l = new Label(txt);
  38. l.setContentMode(Label.CONTENT_XHTML);
  39. main.addComponent(l);
  40. Button b = new Button("Create a new subwindow",
  41. new Button.ClickListener() {
  42. public void buttonClick(ClickEvent event) {
  43. final Window w = new Window("Subwindow");
  44. w.setWidth("50%");
  45. final Label l = new Label(txt);
  46. l.setContentMode(Label.CONTENT_XHTML);
  47. w.addComponent(l);
  48. getApplication().getMainWindow().addWindow(w);
  49. }
  50. });
  51. b.setStyleName(Button.STYLE_LINK);
  52. main.addComponent(b);
  53. b = new Button("Create a new modal window", new Button.ClickListener() {
  54. public void buttonClick(ClickEvent event) {
  55. final Window w = new Window("Modal window");
  56. w.setWidth("50%");
  57. w.setModal(true);
  58. final Label l = new Label(txt);
  59. l.setContentMode(Label.CONTENT_XHTML);
  60. w.addComponent(l);
  61. getApplication().getMainWindow().addWindow(w);
  62. }
  63. });
  64. b.setStyleName(Button.STYLE_LINK);
  65. main.addComponent(b);
  66. b = new Button("Open a application-level window, with shared state",
  67. new Button.ClickListener() {
  68. public void buttonClick(ClickEvent event) {
  69. if (windowUrl == null) {
  70. final Window w = new Window("Subwindow");
  71. final Label l = new Label(txt);
  72. l.setContentMode(Label.CONTENT_XHTML);
  73. w.addComponent(l);
  74. getApplication().addWindow(w);
  75. windowUrl = w.getURL();
  76. }
  77. getApplication().getMainWindow().open(
  78. new ExternalResource(windowUrl), "_new");
  79. }
  80. });
  81. b.setStyleName(Button.STYLE_LINK);
  82. main.addComponent(b);
  83. b = new Button(
  84. "Create a new application-level window, with it's own state",
  85. new Button.ClickListener() {
  86. public void buttonClick(ClickEvent event) {
  87. final Window w = new Window("Subwindow");
  88. getApplication().addWindow(w);
  89. final Label l = new Label(
  90. "Each opened window has its own"
  91. + " name, and is accessed trough its own uri.");
  92. l.setCaption("Window " + w.getName());
  93. w.addComponent(l);
  94. getApplication().getMainWindow().open(
  95. new ExternalResource(w.getURL()), "_new");
  96. }
  97. });
  98. b.setStyleName(Button.STYLE_LINK);
  99. main.addComponent(b);
  100. }
  101. }