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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.itmill.toolkit.demo.featurebrowser;
  5. import java.net.URL;
  6. import com.itmill.toolkit.terminal.ExternalResource;
  7. import com.itmill.toolkit.ui.Button;
  8. import com.itmill.toolkit.ui.CustomComponent;
  9. import com.itmill.toolkit.ui.Label;
  10. import com.itmill.toolkit.ui.OrderedLayout;
  11. import com.itmill.toolkit.ui.Window;
  12. import com.itmill.toolkit.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. + "\"subwindows\". </p><p> A subwindow is rendered as a \"inline\" popup window"
  20. + " within the (native) browser window to which it was added. You can create"
  21. + " a subwindow 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 OrderedLayout main = new OrderedLayout();
  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. main.addComponent(new Button("Create a new subwindow",
  41. new Button.ClickListener() {
  42. public void buttonClick(ClickEvent event) {
  43. final Window w = new Window("Subwindow");
  44. final Label l = new Label(txt);
  45. l.setContentMode(Label.CONTENT_XHTML);
  46. w.addComponent(l);
  47. getApplication().getMainWindow().addWindow(w);
  48. }
  49. }));
  50. main.addComponent(new Button("Create a new modal window",
  51. new Button.ClickListener() {
  52. public void buttonClick(ClickEvent event) {
  53. final Window w = new Window("Modal window");
  54. w.setModal(true);
  55. final Label l = new Label(txt);
  56. l.setContentMode(Label.CONTENT_XHTML);
  57. w.addComponent(l);
  58. getApplication().getMainWindow().addWindow(w);
  59. }
  60. }));
  61. main.addComponent(new Button(
  62. "Open a application-level window, with shared state",
  63. new Button.ClickListener() {
  64. public void buttonClick(ClickEvent event) {
  65. if (windowUrl == null) {
  66. final Window w = new Window("Subwindow");
  67. final Label l = new Label(txt);
  68. l.setContentMode(Label.CONTENT_XHTML);
  69. w.addComponent(l);
  70. getApplication().addWindow(w);
  71. windowUrl = w.getURL();
  72. }
  73. getApplication().getMainWindow().open(
  74. new ExternalResource(windowUrl), "_new");
  75. }
  76. }));
  77. main.addComponent(new Button(
  78. "Create a new application-level window, with it's own state",
  79. new Button.ClickListener() {
  80. public void buttonClick(ClickEvent event) {
  81. final Window w = new Window("Subwindow");
  82. getApplication().addWindow(w);
  83. final Label l = new Label(
  84. "Each opened window has its own"
  85. + " name, and is accessed trough its own uri.");
  86. l.setCaption("Window " + w.getName());
  87. w.addComponent(l);
  88. getApplication().getMainWindow().open(
  89. new ExternalResource(w.getURL()), "_new");
  90. }
  91. }));
  92. }
  93. }