您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LazyInitUIs.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package com.vaadin.tests.components.ui;
  2. import com.vaadin.server.ExternalResource;
  3. import com.vaadin.server.Page;
  4. import com.vaadin.server.UIClassSelectionEvent;
  5. import com.vaadin.server.UICreateEvent;
  6. import com.vaadin.server.UIProviderEvent;
  7. import com.vaadin.server.VaadinRequest;
  8. import com.vaadin.shared.ui.ContentMode;
  9. import com.vaadin.tests.components.AbstractTestUIProvider;
  10. import com.vaadin.ui.Label;
  11. import com.vaadin.ui.Link;
  12. import com.vaadin.ui.UI;
  13. import com.vaadin.ui.VerticalLayout;
  14. public class LazyInitUIs extends AbstractTestUIProvider {
  15. // @EagerInit
  16. private static class EagerInitUI extends UI {
  17. @Override
  18. public void init(VaadinRequest request) {
  19. VerticalLayout layout = new VerticalLayout();
  20. layout.setMargin(true);
  21. setContent(layout);
  22. layout.addComponent(getRequestInfo("EagerInitUI", request));
  23. }
  24. }
  25. @Override
  26. public UI createInstance(UICreateEvent event) {
  27. return getUI(event);
  28. }
  29. @Override
  30. public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
  31. return getUI(event).getClass();
  32. }
  33. private UI getUI(UIProviderEvent event) {
  34. VaadinRequest request = event.getRequest();
  35. if (request.getParameter("lazyCreate") != null) {
  36. // UI created on second request
  37. UI uI = new UI() {
  38. @Override
  39. protected void init(VaadinRequest request) {
  40. VerticalLayout layout = new VerticalLayout();
  41. layout.setMargin(true);
  42. setContent(layout);
  43. layout.addComponent(
  44. getRequestInfo("LazyCreateUI", request));
  45. }
  46. };
  47. return uI;
  48. } else if (request.getParameter("eagerInit") != null) {
  49. // UI inited on first request
  50. return new EagerInitUI();
  51. } else {
  52. // The standard UI
  53. UI uI = new UI() {
  54. @Override
  55. protected void init(VaadinRequest request) {
  56. VerticalLayout layout = new VerticalLayout();
  57. layout.setMargin(true);
  58. setContent(layout);
  59. layout.addComponent(getRequestInfo("NormalUI", request));
  60. String location = getPage().getLocation().toString();
  61. Link lazyCreateLink = new Link("Open lazyCreate UI",
  62. new ExternalResource(location.replaceFirst(
  63. "(\\?|#|$).*", "?lazyCreate#lazyCreate")));
  64. lazyCreateLink.setTargetName("_blank");
  65. layout.addComponent(lazyCreateLink);
  66. Link lazyInitLink = new Link("Open eagerInit UI",
  67. new ExternalResource(location.replaceFirst(
  68. "(\\?|#|$).*", "?eagerInit#eagerInit")));
  69. lazyInitLink.setTargetName("_blank");
  70. layout.addComponent(lazyInitLink);
  71. }
  72. };
  73. return uI;
  74. }
  75. }
  76. public static Label getRequestInfo(String name, VaadinRequest request) {
  77. String info = name;
  78. info += "<br />pathInfo: " + request.getPathInfo();
  79. info += "<br />parameters: " + request.getParameterMap().keySet();
  80. info += "<br />uri fragment: "
  81. + Page.getCurrent().getLocation().getFragment();
  82. return new Label(info, ContentMode.HTML);
  83. }
  84. @Override
  85. protected String getTestDescription() {
  86. return "BrowserDetails should be available in Application.getUI if UIRequiresMoreInformation has been thrown and in UI.init if the UI has the @UIInitRequiresBrowserDetals annotation";
  87. }
  88. @Override
  89. protected Integer getTicketNumber() {
  90. return Integer.valueOf(7883); // + #7882 + #7884
  91. }
  92. }