diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-09-05 15:42:02 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-09-05 15:42:02 +0300 |
commit | de3ac989c85451767510917822463353bcab71cd (patch) | |
tree | 48a991db5d3a700e99e37d53df4fa7902bbb780b /uitest | |
parent | 8bdaf8732e660d1b9595c9d503999022320b0314 (diff) | |
download | vaadin-framework-de3ac989c85451767510917822463353bcab71cd.tar.gz vaadin-framework-de3ac989c85451767510917822463353bcab71cd.zip |
Change LegacyApplication to be a UIProvider (#9402)
Diffstat (limited to 'uitest')
22 files changed, 131 insertions, 159 deletions
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java index 3d63c7dfb9..3372651e5c 100644 --- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java +++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java @@ -30,16 +30,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.vaadin.Application; +import com.vaadin.Application.LegacyApplication; import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.ApplicationConfiguration; -import com.vaadin.server.VaadinServlet; +import com.vaadin.server.LegacyVaadinServlet; +import com.vaadin.server.UIProvider; import com.vaadin.server.WrappedHttpServletRequest; import com.vaadin.server.WrappedRequest; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.UI; @SuppressWarnings("serial") -public class ApplicationRunnerServlet extends VaadinServlet { +public class ApplicationRunnerServlet extends LegacyVaadinServlet { /** * The name of the application class currently used. Only valid within one @@ -104,10 +106,14 @@ public class ApplicationRunnerServlet extends VaadinServlet { } @Override - protected Application getNewApplication(HttpServletRequest request) - throws ServletException { + protected Class<? extends LegacyApplication> getApplicationClass() + throws ClassNotFoundException { + return getClassToRun().asSubclass(LegacyApplication.class); + } - // Creates a new application instance + @Override + protected Application createApplication(HttpServletRequest request) + throws ServletException { try { final Class<?> classToRun = getClassToRun(); if (UI.class.isAssignableFrom(classToRun)) { @@ -121,8 +127,13 @@ public class ApplicationRunnerServlet extends VaadinServlet { } }); return application; - } else if (Application.class.isAssignableFrom(classToRun)) { - return (Application) classToRun.newInstance(); + } else if (LegacyApplication.class.isAssignableFrom(classToRun)) { + return super.createApplication(request); + } else if (UIProvider.class.isAssignableFrom(classToRun)) { + Application application = new Application(); + application + .addUIProvider((UIProvider) classToRun.newInstance()); + return application; } else { throw new ServletException(classToRun.getCanonicalName() + " is neither an Application nor a UI"); diff --git a/uitest/src/com/vaadin/tests/Parameters.java b/uitest/src/com/vaadin/tests/Parameters.java index b16d4ef65b..f5ab18cfe3 100644 --- a/uitest/src/com/vaadin/tests/Parameters.java +++ b/uitest/src/com/vaadin/tests/Parameters.java @@ -30,8 +30,8 @@ import com.vaadin.ui.Label; import com.vaadin.ui.Layout.MarginHandler; import com.vaadin.ui.Link; import com.vaadin.ui.Panel; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Table; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; /** @@ -56,7 +56,7 @@ public class Parameters extends com.vaadin.Application.LegacyApplication setMainWindow(main); // This class acts both as URI handler and parameter handler - addRequestHandler(this); + Application.getCurrent().addRequestHandler(this); final VerticalLayout layout = new VerticalLayout(); final Label info = new Label("To test URI and Parameter Handlers, " diff --git a/uitest/src/com/vaadin/tests/TestBench.java b/uitest/src/com/vaadin/tests/TestBench.java index 67e1180d75..bae677001a 100644 --- a/uitest/src/com/vaadin/tests/TestBench.java +++ b/uitest/src/com/vaadin/tests/TestBench.java @@ -37,8 +37,8 @@ import com.vaadin.ui.Label; import com.vaadin.ui.Layout; import com.vaadin.ui.Link; import com.vaadin.ui.Panel; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Tree; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; /** @@ -225,7 +225,7 @@ public class TestBench extends com.vaadin.Application.LegacyApplication try { final Application.LegacyApplication app = (Application.LegacyApplication) c .newInstance(); - app.init(); + app.doInit(); Layout lo = (Layout) app.getMainWindow().getContent(); lo.setParent(null); return lo; diff --git a/uitest/src/com/vaadin/tests/TreeFilesystem.java b/uitest/src/com/vaadin/tests/TreeFilesystem.java index f2a0d97b08..2e7b215ad7 100644 --- a/uitest/src/com/vaadin/tests/TreeFilesystem.java +++ b/uitest/src/com/vaadin/tests/TreeFilesystem.java @@ -18,14 +18,15 @@ package com.vaadin.tests; import java.io.File; +import com.vaadin.Application; import com.vaadin.data.Item; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.util.SampleDirectory; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Tree; import com.vaadin.ui.Tree.ExpandEvent; +import com.vaadin.ui.UI.LegacyWindow; /** * Browsable file explorer using Vaadin Tree component. Demonstrates: how to add @@ -61,7 +62,8 @@ public class TreeFilesystem extends com.vaadin.Application.LegacyApplication tree.addListener(this); // Get sample directory - final File sampleDir = SampleDirectory.getDirectory(this, main); + final File sampleDir = SampleDirectory.getDirectory( + Application.getCurrent(), main); // populate tree's root node with example directory if (sampleDir != null) { populateNode(sampleDir.getAbsolutePath(), null); diff --git a/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java b/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java index 672c518ea8..8107ea702d 100644 --- a/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java +++ b/uitest/src/com/vaadin/tests/TreeFilesystemContainer.java @@ -18,6 +18,7 @@ package com.vaadin.tests; import java.io.File; +import com.vaadin.Application; import com.vaadin.data.util.FilesystemContainer; import com.vaadin.data.util.FilesystemContainer.FileItem; import com.vaadin.tests.util.SampleDirectory; @@ -26,8 +27,8 @@ import com.vaadin.ui.Component.Listener; import com.vaadin.ui.Field; import com.vaadin.ui.Label; import com.vaadin.ui.Panel; -import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.Tree; +import com.vaadin.ui.UI.LegacyWindow; import com.vaadin.ui.VerticalLayout; /** @@ -77,7 +78,8 @@ public class TreeFilesystemContainer extends propertyPanel.setEnabled(false); // Get sample directory - final File sampleDir = SampleDirectory.getDirectory(this, w); + final File sampleDir = SampleDirectory.getDirectory( + Application.getCurrent(), w); // Populate tree with FilesystemContainer final FilesystemContainer fsc = new FilesystemContainer(sampleDir, true); filesystem.setContainerDataSource(fsc); diff --git a/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java b/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java index a7d2b03415..2f81c08ae6 100644 --- a/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java +++ b/uitest/src/com/vaadin/tests/appengine/GAESyncTest.java @@ -2,6 +2,7 @@ package com.vaadin.tests.appengine; import com.google.apphosting.api.DeadlineExceededException; import com.vaadin.Application; +import com.vaadin.Application.LegacyApplication; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.server.ClassResource; @@ -50,10 +51,10 @@ public class GAESyncTest extends Application.LegacyApplication { private static final long serialVersionUID = -6521351715072191625l; TextField tf; Label l; - Application app; + LegacyApplication app; GridLayout gl; - private IntrWindow(Application app) { + private IntrWindow(LegacyApplication app) { this.app = app; tf = new TextField("Echo thingie"); diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html index 47e766e76a..ea8c0c93b6 100644 --- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html +++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.html @@ -18,7 +18,7 @@ </tr> <tr> <td>assertText</td> - <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td> + <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td> <td>UI id: 0</td> </tr> <tr> @@ -28,7 +28,7 @@ </tr> <tr> <td>assertText</td> - <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td> + <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td> <td>UI id: 0</td> </tr> <tr> @@ -43,10 +43,9 @@ </tr> <tr> <td>assertText</td> - <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/ChildComponentContainer[1]/VLabel[0]</td> + <td>vaadin=runcomvaadintestsapplicationRefreshStatePreserve::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[1]</td> <td>UI id: 0</td> </tr> - </tbody></table> </body> </html> diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java index 8962f5de9a..13ceceab6c 100644 --- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,35 +1,18 @@ package com.vaadin.tests.application; -import com.vaadin.Application; import com.vaadin.annotations.PreserveOnRefresh; -import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; -import com.vaadin.tests.components.AbstractTestApplication; +import com.vaadin.tests.components.AbstractTestUI; 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) { - getContent().addComponent( - new Label("window.name: " - + request.getBrowserDetails().getWindowName())); - getContent().addComponent(new Label("UI id: " + getUIId())); - } - } +@PreserveOnRefresh +public class RefreshStatePreserve extends AbstractTestUI { @Override - public void init() { - super.init(); - addUIProvider(new AbstractUIProvider() { - @Override - public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) { - return RefreshStateUI.class; - } - }); + protected void setup(WrappedRequest request) { + addComponent(new Label("window.name: " + + request.getBrowserDetails().getWindowName())); + addComponent(new Label("UI id: " + getUIId())); } @Override diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html index b7fbca4c04..0d3a746152 100644 --- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html +++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.html @@ -29,7 +29,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_15</td> - <td>1. null app in class init</td> + <td>1. some app in class init</td> </tr> <tr> <td>assertText</td> @@ -39,7 +39,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_13</td> - <td>3. null app in app constructor</td> + <td>3. some app in app constructor</td> </tr> <tr> <td>assertText</td> @@ -49,7 +49,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_11</td> - <td>5. this app in app init</td> + <td>5. some app in app init</td> </tr> <tr> <td>assertText</td> @@ -59,7 +59,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_9</td> - <td>7. this app in root init</td> + <td>7. some app in root init</td> </tr> <tr> <td>assertText</td> @@ -69,7 +69,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_7</td> - <td>9. this app in root paint</td> + <td>9. some app in root paint</td> </tr> <tr> <td>assertText</td> @@ -79,7 +79,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_5</td> - <td>11. this app in background thread</td> + <td>11. some app in background thread</td> </tr> <tr> <td>assertText</td> @@ -89,7 +89,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_3</td> - <td>13. this app in resource handler</td> + <td>13. some app in resource handler</td> </tr> <tr> <td>assertText</td> @@ -99,7 +99,7 @@ <tr> <td>assertText</td> <td>vaadin=runcomvaadintestsapplicationThreadLocalInstances::PID_SLog_row_1</td> - <td>15. this app in button listener</td> + <td>15. some app in button listener</td> </tr> <tr> <td>assertText</td> diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java index bad5b53478..1eda9e54fe 100644 --- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java +++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java @@ -1,24 +1,24 @@ package com.vaadin.tests.application; import com.vaadin.Application; -import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.DownloadStream; import com.vaadin.server.PaintException; import com.vaadin.server.WrappedRequest; -import com.vaadin.tests.components.AbstractTestApplication; +import com.vaadin.tests.components.AbstractTestCase; import com.vaadin.tests.integration.FlagSeResource; import com.vaadin.tests.util.Log; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Embedded; import com.vaadin.ui.UI; +import com.vaadin.ui.UI.LegacyWindow; -public class ThreadLocalInstances extends AbstractTestApplication { +public class ThreadLocalInstances extends AbstractTestCase { private static final Application staticInitApplication = Application .getCurrent(); private static final UI staticInitRoot = UI.getCurrent(); - private final UI mainWindow = new UI() { + private final LegacyWindow mainWindow = new LegacyWindow() { boolean paintReported = false; @Override @@ -71,25 +71,13 @@ public class ThreadLocalInstances extends AbstractTestApplication { } @Override - public void init() { + protected void init() { reportCurrentStatus("app init"); - addUIProvider(new AbstractUIProvider() { - @Override - public UI createInstance(Application application, - Class<? extends UI> type, WrappedRequest request) { - return mainWindow; - } - - @Override - public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) { - return mainWindow.getClass(); - } - }); + setMainWindow(mainWindow); } @Override - protected String getTestDescription() { + protected String getDescription() { return "Tests the precence of Application.getCurrentApplication() and UI.getCurrentRoot() from different contexts"; } @@ -113,7 +101,7 @@ public class ThreadLocalInstances extends AbstractTestApplication { } else if (value == reference) { return "this"; } else { - return value.toString(); + return "some"; } } diff --git a/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java b/uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java index db17c67fdd..3d380c7835 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractTestApplication.java +++ b/uitest/src/com/vaadin/tests/components/AbstractTestUIProvider.java @@ -1,16 +1,17 @@ package com.vaadin.tests.components; import com.vaadin.Application; +import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.ApplicationContext; import com.vaadin.server.WebBrowser; -public abstract class AbstractTestApplication extends Application { +public abstract class AbstractTestUIProvider extends AbstractUIProvider { protected abstract String getTestDescription(); protected abstract Integer getTicketNumber(); protected WebBrowser getBrowser() { - ApplicationContext context = getContext(); + ApplicationContext context = Application.getCurrent().getContext(); WebBrowser webBrowser = context.getBrowser(); return webBrowser; } diff --git a/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java b/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java index 9b29ae1bab..327ed0f86b 100644 --- a/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java +++ b/uitest/src/com/vaadin/tests/components/abstractfield/AbstractComponentDataBindingTest.java @@ -4,6 +4,7 @@ import java.util.HashSet; import java.util.Locale; import java.util.Set; +import com.vaadin.Application; import com.vaadin.data.Container; import com.vaadin.data.Item; import com.vaadin.data.Property.ValueChangeEvent; @@ -54,7 +55,7 @@ public abstract class AbstractComponentDataBindingTest extends TestBase } protected void updateLocale(Locale locale) { - setLocale(locale); + Application.getCurrent().setLocale(locale); for (Component c : fields) { removeComponent(c); } diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java index 84c14763ab..f640b3f9c4 100644 --- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java +++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java @@ -1,26 +1,17 @@ package com.vaadin.tests.components.loginform; -import com.vaadin.Application; -import com.vaadin.server.AbstractUIProvider; -import com.vaadin.server.WrappedRequest; +import com.vaadin.Application.LegacyApplication; import com.vaadin.ui.LoginForm; import com.vaadin.ui.LoginForm.LoginEvent; import com.vaadin.ui.LoginForm.LoginListener; -import com.vaadin.ui.UI; import com.vaadin.ui.UI.LegacyWindow; @SuppressWarnings("serial") -public class LoginFormWithMultipleWindows extends Application { +public class LoginFormWithMultipleWindows extends LegacyApplication { @Override public void init() { - addUIProvider(new AbstractUIProvider() { - @Override - public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) { - return LoginFormWindow.class; - } - }); + setMainWindow(new LoginFormWindow()); } public static class LoginFormWindow extends LegacyWindow { diff --git a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java index f33037f171..b141dc0990 100644 --- a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java +++ b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java @@ -1,16 +1,15 @@ package com.vaadin.tests.components.ui; import com.vaadin.Application; -import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.ExternalResource; import com.vaadin.server.WrappedRequest; import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.tests.components.AbstractTestApplication; +import com.vaadin.tests.components.AbstractTestUIProvider; import com.vaadin.ui.Label; import com.vaadin.ui.Link; import com.vaadin.ui.UI; -public class LazyInitUIs extends AbstractTestApplication { +public class LazyInitUIs extends AbstractTestUIProvider { // @EagerInit private static class EagerInitUI extends UI { @@ -21,21 +20,15 @@ public class LazyInitUIs extends AbstractTestApplication { } @Override - public void init() { - addUIProvider(new AbstractUIProvider() { - - @Override - public UI createInstance(Application application, - Class<? extends UI> type, WrappedRequest request) { - return getUI(request); - } + public UI createInstance(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(); - } - }); + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return getUI(request).getClass(); } private UI getUI(WrappedRequest request) { @@ -59,14 +52,14 @@ public class LazyInitUIs extends AbstractTestApplication { addComponent(getRequestInfo("NormalUI", request)); Link lazyCreateLink = new Link("Open lazyCreate UI", - new ExternalResource(getURL() - + "?lazyCreate#lazyCreate")); + new ExternalResource(Application.getCurrent() + .getURL() + "?lazyCreate#lazyCreate")); lazyCreateLink.setTargetName("_blank"); addComponent(lazyCreateLink); Link lazyInitLink = new Link("Open eagerInit UI", - new ExternalResource(getURL() - + "?eagerInit#eagerInit")); + new ExternalResource(Application.getCurrent() + .getURL() + "?eagerInit#eagerInit")); lazyInitLink.setTargetName("_blank"); addComponent(lazyInitLink); } diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java index fe2fe16d93..9a66e9ad0a 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java @@ -1,34 +1,40 @@ package com.vaadin.tests.components.ui; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + import com.vaadin.Application; -import com.vaadin.server.AbstractUIProvider; import com.vaadin.server.WrappedRequest; -import com.vaadin.tests.components.AbstractTestApplication; +import com.vaadin.tests.components.AbstractTestUIProvider; import com.vaadin.ui.Label; import com.vaadin.ui.UI; -public class UIsInMultipleTabs extends AbstractTestApplication { - private int numberOfUIsOpened; +public class UIsInMultipleTabs extends AbstractTestUIProvider { + // No cleanup -> will leak, but shouldn't matter for tests + private static ConcurrentHashMap<Application, AtomicInteger> numberOfUIsOpened = new ConcurrentHashMap<Application, AtomicInteger>(); public static class TabUI extends UI { @Override protected void init(WrappedRequest request) { - UIsInMultipleTabs application = (UIsInMultipleTabs) getApplication(); - String message = "This is UI number " - + ++application.numberOfUIsOpened; + Application application = Application.getCurrent(); + AtomicInteger count = numberOfUIsOpened.get(application); + if (count == null) { + numberOfUIsOpened.putIfAbsent(application, new AtomicInteger()); + // Get our added instance or another instance that was added by + // another thread between previous get and putIfAbsent + count = numberOfUIsOpened.get(application); + } + int currentCount = count.incrementAndGet(); + String message = "This is UI number " + currentCount; addComponent(new Label(message)); } } - public UIsInMultipleTabs() { - addUIProvider(new AbstractUIProvider() { - @Override - public Class<? extends UI> getUIClass(Application application, - WrappedRequest request) { - return TabUI.class; - } - }); + @Override + public Class<? extends UI> getUIClass(Application application, + WrappedRequest request) { + return TabUI.class; } @Override diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java b/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java index 8da94feb7f..4470404105 100644 --- a/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java +++ b/uitest/src/com/vaadin/tests/layouts/layouttester/GridLayoutTests.java @@ -2,7 +2,7 @@ package com.vaadin.tests.layouts.layouttester; import java.util.Date; -import com.vaadin.Application; +import com.vaadin.Application.LegacyApplication; import com.vaadin.server.Resource; import com.vaadin.server.SystemError; import com.vaadin.server.ThemeResource; @@ -32,7 +32,7 @@ public class GridLayoutTests extends AbstractLayoutTests { private AbstractComponent rc1, col1, col2, col3, row1, row2, row3, x3, x22; - public GridLayoutTests(Application application) { + public GridLayoutTests(LegacyApplication application) { super(); } diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java b/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java index 0042f0ba11..eb0976dfb9 100644 --- a/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java +++ b/uitest/src/com/vaadin/tests/layouts/layouttester/HorizontalLayoutTests.java @@ -1,6 +1,6 @@ package com.vaadin.tests.layouts.layouttester; -import com.vaadin.Application; +import com.vaadin.Application.LegacyApplication; import com.vaadin.server.Resource; import com.vaadin.server.SystemError; import com.vaadin.server.ThemeResource; @@ -26,7 +26,7 @@ import com.vaadin.ui.themes.Reindeer; public class HorizontalLayoutTests extends AbstractLayoutTests { - public HorizontalLayoutTests(Application application) { + public HorizontalLayoutTests(LegacyApplication application) { super(); } diff --git a/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java b/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java index 3e668289fe..f6cf3a4bae 100644 --- a/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java +++ b/uitest/src/com/vaadin/tests/layouts/layouttester/VerticalLayoutTests.java @@ -1,6 +1,6 @@ package com.vaadin.tests.layouts.layouttester; -import com.vaadin.Application; +import com.vaadin.Application.LegacyApplication; import com.vaadin.server.Resource; import com.vaadin.server.SystemError; import com.vaadin.server.ThemeResource; @@ -26,7 +26,7 @@ import com.vaadin.ui.VerticalLayout; public class VerticalLayoutTests extends AbstractLayoutTests { - public VerticalLayoutTests(Application application) { + public VerticalLayoutTests(LegacyApplication application) { super(); } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java index 8c2a816e1c..05da2506e8 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java @@ -31,35 +31,29 @@ import com.vaadin.ui.UI; * @author Vaadin Ltd * @since 7.0.0 */ -public class DifferentFeaturesForDifferentClients extends Application { +public class DifferentFeaturesForDifferentClients extends AbstractUIProvider { @Override - public void init() { - super.init(); - addUIProvider(new AbstractUIProvider() { - @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; - } - } + 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; + } + } - // Must override as default implementation isn't allowed to - // instantiate our non-public classes - @Override - public UI createInstance(Application application, - Class<? extends UI> type, WrappedRequest request) { - try { - return type.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - }); + // Must override as default implementation isn't allowed to + // instantiate our non-public classes + @Override + public UI createInstance(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/tickets/Ticket1589.java b/uitest/src/com/vaadin/tests/tickets/Ticket1589.java index 37f9197285..7cbe8cb6cf 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket1589.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket1589.java @@ -28,7 +28,7 @@ public class Ticket1589 extends Application.LegacyApplication { MyDynamicResource res = new MyDynamicResource(); - addRequestHandler(res); + Application.getCurrent().addRequestHandler(res); w.addComponent(new Link( "Test (without Content-Disposition, should suggest generatedFile.png when saving, browser default for actual disposition)", diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket1921.java b/uitest/src/com/vaadin/tests/tickets/Ticket1921.java index ac5f990915..17314c3fb6 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket1921.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket1921.java @@ -42,7 +42,7 @@ public class Ticket1921 extends Application.LegacyApplication implements newState(); - addRequestHandler(this); + Application.getCurrent().addRequestHandler(this); } public void newState() { diff --git a/uitest/src/com/vaadin/tests/tickets/Ticket2292.java b/uitest/src/com/vaadin/tests/tickets/Ticket2292.java index ce7960a169..f3b5b68491 100644 --- a/uitest/src/com/vaadin/tests/tickets/Ticket2292.java +++ b/uitest/src/com/vaadin/tests/tickets/Ticket2292.java @@ -44,7 +44,7 @@ public class Ticket2292 extends com.vaadin.Application.LegacyApplication Link l = new Link("l", icon); main.addComponent(l); - addRequestHandler(this); + Application.getCurrent().addRequestHandler(this); } @Override |