diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-31 12:02:51 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-31 19:00:00 +0300 |
commit | 8679f49c5e036d39d34a9fca8a907c4d19df21c9 (patch) | |
tree | 9979d5cf330043523e7d68221133bbcd5b3300f5 /uitest | |
parent | cf9ab5aea84d2be1686c5f46edd9522cd0750baf (diff) | |
download | vaadin-framework-8679f49c5e036d39d34a9fca8a907c4d19df21c9.tar.gz vaadin-framework-8679f49c5e036d39d34a9fca8a907c4d19df21c9.zip |
Refactor UI bootstrap (#9443)
Diffstat (limited to 'uitest')
9 files changed, 86 insertions, 57 deletions
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index e05979ede0..bceecaf35a 100644 --- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.AbstractApplicationServlet; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedHttpServletRequest; @@ -116,8 +115,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { @Override public Class<? extends UI> getUIClass( - Application application, WrappedRequest request) - throws UIRequiresMoreInformationException { + Application application, WrappedRequest request) { return (Class<? extends UI>) classToRun; } }); diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java index 3013659ed7..8962f5de9a 100644 --- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,7 +1,7 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; @@ -9,6 +9,7 @@ import com.vaadin.ui.Label; import com.vaadin.ui.UI; public class RefreshStatePreserve extends AbstractTestApplication { + @PreserveOnRefresh public static class RefreshStateUI extends UI { @Override public void init(WrappedRequest request) { @@ -22,12 +23,10 @@ public class RefreshStatePreserve extends AbstractTestApplication { @Override public void init() { super.init(); - setUiPreserved(true); addUIProvider(new AbstractUIProvider() { @Override public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) - throws UIRequiresMoreInformationException { + WrappedRequest request) { return RefreshStateUI.class; } }); diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java index 0e7dd1b242..89cbf5d3ff 100644 --- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java +++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java @@ -1,9 +1,9 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.DownloadStream; import com.vaadin.server.PaintException; +import com.vaadin.server.UIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.tests.integration.FlagSeResource; @@ -73,12 +73,19 @@ public class ThreadLocalInstances extends AbstractTestApplication { @Override public void init() { reportCurrentStatus("app init"); - } + addUIProvider(new UIProvider() { + @Override + public UI instantiateUI(Application application, + Class<? extends UI> type, WrappedRequest request) { + return mainWindow; + } - @Override - protected UI getUI(WrappedRequest request) - throws UIRequiresMoreInformationException { - return mainWindow; + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return mainWindow.getClass(); + } + }); } @Override diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java index ac4c3c8ea3..84c14763ab 100644 --- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java +++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java @@ -1,6 +1,7 @@ package com.vaadin.tests.components.loginform; import com.vaadin.Application; +import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.ui.LoginForm; import com.vaadin.ui.LoginForm.LoginEvent; @@ -12,11 +13,17 @@ import com.vaadin.ui.UI.LegacyWindow; public class LoginFormWithMultipleWindows extends Application { @Override - protected UI getUI(WrappedRequest request) { - return new LoginFormWindow(); + public void init() { + addUIProvider(new AbstractUIProvider() { + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return LoginFormWindow.class; + } + }); } - public class LoginFormWindow extends LegacyWindow { + public static class LoginFormWindow extends LegacyWindow { public LoginFormWindow() { super(); diff --git a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java index 34bf8f6715..4cd786593a 100644 --- a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java +++ b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java @@ -1,10 +1,10 @@ package com.vaadin.tests.components.ui; -import com.vaadin.UIRequiresMoreInformationException; +import com.vaadin.Application; import com.vaadin.annotations.EagerInit; import com.vaadin.server.ExternalResource; +import com.vaadin.server.UIProvider; import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; @@ -22,23 +22,33 @@ public class LazyInitUIs extends AbstractTestApplication { } @Override - public UI getUI(WrappedRequest request) - throws UIRequiresMoreInformationException { + public void init() { + addUIProvider(new UIProvider() { + + @Override + public UI instantiateUI(Application application, + Class<? extends UI> type, WrappedRequest request) { + return getUI(request); + } + + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return getUI(request).getClass(); + } + }); + } + + private UI getUI(WrappedRequest request) { if (request.getParameter("lazyCreate") != null) { // UI created on second request - BrowserDetails browserDetails = request.getBrowserDetails(); - if (browserDetails == null - || browserDetails.getUriFragment() == null) { - throw new UIRequiresMoreInformationException(); - } else { - UI uI = new UI() { - @Override - protected void init(WrappedRequest request) { - addComponent(getRequestInfo("LazyCreateUI", request)); - } - }; - return uI; - } + UI uI = new UI() { + @Override + protected void init(WrappedRequest request) { + addComponent(getRequestInfo("LazyCreateUI", request)); + } + }; + return uI; } else if (request.getParameter("eagerInit") != null) { // UI inited on first request return new EagerInitUI(); diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java index 022db1bf3e..fe2fe16d93 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java @@ -1,7 +1,6 @@ package com.vaadin.tests.components.ui; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; @@ -26,8 +25,7 @@ public class UIsInMultipleTabs extends AbstractTestApplication { addUIProvider(new AbstractUIProvider() { @Override public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) - throws UIRequiresMoreInformationException { + WrappedRequest request) { return TabUI.class; } }); diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java index a96b8957c6..cfb24c732f 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java @@ -16,9 +16,10 @@ package com.vaadin.tests.minitutorials.v7a1; +import com.vaadin.annotations.PreserveOnRefresh; import com.vaadin.server.WrappedRequest; -import com.vaadin.ui.UI; import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; /** * Mini tutorial code for @@ -28,6 +29,7 @@ import com.vaadin.ui.TextField; * @author Vaadin Ltd * @since 7.0.0 */ +@PreserveOnRefresh public class CreatingPreserveState extends UI { private static int windowCounter = 0; @@ -36,7 +38,6 @@ public class CreatingPreserveState extends UI { TextField tf = new TextField("Window #" + (++windowCounter)); tf.setImmediate(true); getContent().addComponent(tf); - getApplication().setUiPreserved(true); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java index ba3042c48e..54cf8a94e0 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java @@ -17,10 +17,9 @@ package com.vaadin.tests.minitutorials.v7a1; import com.vaadin.Application; -import com.vaadin.UIRequiresMoreInformationException; +import com.vaadin.server.UIProvider; import com.vaadin.server.WebBrowser; import com.vaadin.server.WrappedRequest; -import com.vaadin.server.WrappedRequest.BrowserDetails; import com.vaadin.ui.Label; import com.vaadin.ui.UI; @@ -35,21 +34,32 @@ import com.vaadin.ui.UI; public class DifferentFeaturesForDifferentClients extends Application { @Override - protected UI getUI(WrappedRequest request) - throws UIRequiresMoreInformationException { - BrowserDetails browserDetails = request.getBrowserDetails(); - // This is a limitation of 7.0.0.alpha1 that there is no better way to - // check if WebBrowser has been fully initialized - if (browserDetails.getUriFragment() == null) { - throw new UIRequiresMoreInformationException(); - } + public void init() { + super.init(); + addUIProvider(new UIProvider() { + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + // could also use browser version etc. + if (request.getHeader("user-agent").contains("mobile")) { + return TouchRoot.class; + } else { + return DefaultRoot.class; + } + } - // could also use screen size, browser version etc. - if (browserDetails.getWebBrowser().isTouchDevice()) { - return new TouchRoot(); - } else { - return new DefaultRoot(); - } + // Must override as default implementation isn't allowed to + // instantiate our non-public classes + @Override + public UI instantiateUI(Application application, + Class<? extends UI> type, WrappedRequest request) { + try { + return type.newInstance(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }); } } diff --git a/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java b/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java index 9f3019b21c..1f50110330 100644 --- a/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java +++ b/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java @@ -42,9 +42,8 @@ public class TestAddonContextListener implements AddonContextListener { } private boolean shouldModify(BootstrapResponse response) { - UI uI = response.getUI(); - boolean shouldModify = uI != null - && uI.getClass() == BootstrapModifyUI.class; + Class<? extends UI> uiClass = response.getUiClass(); + boolean shouldModify = uiClass == BootstrapModifyUI.class; return shouldModify; } |