import com.vaadin.server.RequestHandler;
import com.vaadin.server.ServletApplicationContext;
import com.vaadin.server.Terminal;
+import com.vaadin.server.Terminal.ErrorEvent;
+import com.vaadin.server.Terminal.ErrorListener;
import com.vaadin.server.UIProvider;
import com.vaadin.server.VaadinServlet;
import com.vaadin.server.VariableOwner;
* @since 7.0
*/
@Deprecated
- public static class LegacyApplication extends Application {
+ public static abstract class LegacyApplication extends AbstractUIProvider
+ implements ErrorListener {
/**
* Ignore initial / and then get everything up to the next /
*/
"mainWindow has already been set");
}
if (mainWindow.getApplication() == null) {
- mainWindow.setApplication(this);
- } else if (mainWindow.getApplication() != this) {
+ mainWindow.setApplication(Application.getCurrent());
+ } else if (mainWindow.getApplication() != Application.getCurrent()) {
throw new IllegalStateException(
"mainWindow is attached to another application");
}
this.mainWindow = mainWindow;
}
+ public void doInit() {
+ Application.getCurrent().setErrorHandler(this);
+ init();
+ }
+
+ protected abstract void init();
+
@Override
- public void start(ApplicationStartEvent event) {
- super.start(event);
- addUIProvider(new AbstractUIProvider() {
- @Override
- public Class<? extends UI> getUIClass(Application application,
- WrappedRequest request) {
- if (application == LegacyApplication.this) {
- UI uiInstance = getUIInstance(request);
- if (uiInstance != null) {
- return uiInstance.getClass();
- }
- }
- return null;
- }
+ public Class<? extends UI> getUIClass(Application application,
+ WrappedRequest request) {
+ UI uiInstance = getUIInstance(request);
+ if (uiInstance != null) {
+ return uiInstance.getClass();
+ }
+ return null;
+ }
- @Override
- public UI createInstance(Application application,
- Class<? extends UI> type, WrappedRequest request) {
- return getUIInstance(request);
- }
+ @Override
+ public UI createInstance(Application application,
+ Class<? extends UI> type, WrappedRequest request) {
+ return getUIInstance(request);
+ }
- @Override
- public String getThemeForUI(WrappedRequest request,
- Class<? extends UI> uiClass) {
- return theme;
- }
+ @Override
+ public String getThemeForUI(WrappedRequest request,
+ Class<? extends UI> uiClass) {
+ return theme;
+ }
- @Override
- public String getPageTitleForUI(WrappedRequest request,
- Class<? extends UI> uiClass) {
- UI uiInstance = getUIInstance(request);
- if (uiInstance != null) {
- return uiInstance.getCaption();
- } else {
- return super.getPageTitleForUI(request, uiClass);
- }
- }
- });
+ @Override
+ public String getPageTitleForUI(WrappedRequest request,
+ Class<? extends UI> uiClass) {
+ UI uiInstance = getUIInstance(request);
+ if (uiInstance != null) {
+ return uiInstance.getCaption();
+ } else {
+ return super.getPageTitleForUI(request, uiClass);
+ }
}
/**
* {@inheritDoc}
*/
@Override
- public UI getUIForRequest(WrappedRequest request) {
+ public UI getExistingUI(WrappedRequest request) {
UI uiInstance = getUIInstance(request);
if (uiInstance.getUIId() == -1) {
// Not initialized -> Let go through createUIInstance to make it
}
legacyUINames.put(uI.getName(), uI);
- uI.setApplication(this);
+ uI.setApplication(Application.getCurrent());
}
/**
public Collection<UI.LegacyWindow> getWindows() {
return Collections.unmodifiableCollection(legacyUINames.values());
}
+
+ @Override
+ public void terminalError(ErrorEvent event) {
+ Application.getCurrent().terminalError(event);
+ }
+
+ public ApplicationContext getContext() {
+ return Application.getCurrent().getContext();
+ }
+
+ protected void close() {
+ Application.getCurrent().close();
+ }
+
+ public boolean isRunning() {
+ return Application.getCurrent().isRunning();
+ }
+
+ public URL getURL() {
+ return Application.getCurrent().getURL();
+ }
}
/**
Integer uiId = getUIId(request);
synchronized (this) {
- BrowserDetails browserDetails = request.getBrowserDetails();
- boolean hasBrowserDetails = browserDetails != null
- && browserDetails.getUriFragment() != null;
-
uI = uIs.get(uiId);
- Class<? extends UI> uiClass = null;
-
- if (uI == null && hasBrowserDetails
- && !retainOnRefreshUIs.isEmpty()) {
- uiClass = getUIClass(request);
-
- // Check for a known UI
-
- @SuppressWarnings("null")
- String windowName = browserDetails.getWindowName();
- Integer retainedUIId = retainOnRefreshUIs.get(windowName);
-
- if (retainedUIId != null) {
- UI retainedUI = uIs.get(retainedUIId);
- // We've had the same UI instance in a window with this
- // name, but should we still use it?
- if (retainedUI.getClass() == uiClass) {
- uiId = retainedUIId;
- uI = retainedUI;
- } else {
- getLogger().info(
- "Not using retained UI in " + windowName
- + " because retained UI was of type "
- + retainedUIId.getClass() + " but "
- + uiClass
- + " is expected for the request.");
- }
- }
+
+ if (uI == null) {
+ uI = findExistingUi(request);
}
} // end synchronized block
return uI;
}
+ private UI findExistingUi(WrappedRequest request) {
+ // Check if some UI provider has an existing UI available
+ for (int i = uiProviders.size() - 1; i >= 0; i--) {
+ UIProvider provider = uiProviders.get(i);
+ UI existingUi = provider.getExistingUI(request);
+ if (existingUi != null) {
+ return existingUi;
+ }
+ }
+
+ BrowserDetails browserDetails = request.getBrowserDetails();
+ boolean hasBrowserDetails = browserDetails != null
+ && browserDetails.getUriFragment() != null;
+
+ if (hasBrowserDetails && !retainOnRefreshUIs.isEmpty()) {
+ // Check for a known UI
+
+ @SuppressWarnings("null")
+ String windowName = browserDetails.getWindowName();
+ Integer retainedUIId = retainOnRefreshUIs.get(windowName);
+
+ if (retainedUIId != null) {
+ Class<? extends UI> expectedUIClass = getUIClass(request);
+ UI retainedUI = uIs.get(retainedUIId);
+ // We've had the same UI instance in a window with this
+ // name, but should we still use it?
+ if (retainedUI.getClass() == expectedUIClass) {
+ return retainedUI;
+ } else {
+ getLogger().info(
+ "Not using retained UI in " + windowName
+ + " because retained UI was of type "
+ + retainedUIId.getClass() + " but "
+ + expectedUIClass
+ + " is expected for the request.");
+ }
+ }
+ }
+
+ return null;
+ }
+
public UI createUI(WrappedRequest request) {
Class<? extends UI> uiClass = getUIClass(request);
return globalResourceHandler;
}
+ public Collection<UIProvider> getUIProviders() {
+ return Collections.unmodifiableCollection(uiProviders);
+ }
+
}
return titleAnnotation.value();
}
}
+
+ @Override
+ public UI getExistingUI(WrappedRequest request) {
+ return null;
+ }
}
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletRequest;
+
+import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
+import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
+
+public class LegacyVaadinPortlet extends VaadinPortlet {
+
+ protected Class<? extends LegacyApplication> getApplicationClass()
+ throws ClassNotFoundException {
+ try {
+ return ServletPortletHelper
+ .getLegacyApplicationClass(getDeploymentConfiguration());
+ } catch (ApplicationClassException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected LegacyApplication getNewApplication(PortletRequest request)
+ throws PortletException {
+ try {
+ Class<? extends LegacyApplication> applicationClass = getApplicationClass();
+ return applicationClass.newInstance();
+ } catch (Exception e) {
+ throw new PortletException(e);
+ }
+ }
+
+ @Override
+ protected Application createApplication(PortletRequest request)
+ throws PortletException {
+ Application application = super.createApplication(request);
+
+ // Must set current before running init()
+ Application.setCurrent(application);
+
+ LegacyApplication legacyApplication = getNewApplication(request);
+ legacyApplication.doInit();
+ application.addUIProvider(legacyApplication);
+
+ return application;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.server;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
+import com.vaadin.server.ServletPortletHelper.ApplicationClassException;
+
+public class LegacyVaadinServlet extends VaadinServlet {
+
+ protected Class<? extends LegacyApplication> getApplicationClass()
+ throws ClassNotFoundException {
+ try {
+ return ServletPortletHelper
+ .getLegacyApplicationClass(getDeploymentConfiguration());
+ } catch (ApplicationClassException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected LegacyApplication getNewApplication(HttpServletRequest request)
+ throws ServletException {
+ try {
+ Class<? extends LegacyApplication> applicationClass = getApplicationClass();
+ return applicationClass.newInstance();
+ } catch (Exception e) {
+ throw new ServletException(e);
+ }
+ }
+
+ @Override
+ protected Application createApplication(HttpServletRequest request)
+ throws ServletException {
+ Application application = super.createApplication(request);
+
+ // Must set current before running init()
+ Application.setCurrent(application);
+
+ LegacyApplication legacyApplication = getNewApplication(request);
+ legacyApplication.doInit();
+ application.addUIProvider(legacyApplication);
+
+ return application;
+ }
+
+}
import java.util.Properties;
import com.vaadin.Application;
+import com.vaadin.Application.LegacyApplication;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.ui.UI;
}
}
- static Class<? extends Application> getApplicationClass(
+ static Class<? extends LegacyApplication> getLegacyApplicationClass(
DeploymentConfiguration deploymentConfiguration)
throws ApplicationClassException {
Properties initParameters = deploymentConfiguration
.getApplicationConfiguration().getInitParameters();
String applicationParameter = initParameters.getProperty("application");
- String uiParameter = initParameters
- .getProperty(Application.UI_PARAMETER);
ClassLoader classLoader = deploymentConfiguration.getClassLoader();
if (applicationParameter == null) {
-
- // Validate the parameter value
- verifyUIClass(uiParameter, classLoader);
-
- // Application can be used if a valid rootLayout is defined
- return Application.class;
+ throw new ApplicationClassException(
+ "No \"application\" init parameter found");
}
try {
- return (Class<? extends Application>) classLoader
- .loadClass(applicationParameter);
+ return classLoader.loadClass(applicationParameter).asSubclass(
+ LegacyApplication.class);
} catch (final ClassNotFoundException e) {
throw new ApplicationClassException(
"Failed to load application class: " + applicationParameter,
ApplicationConstants.HEARTBEAT_REQUEST_PATH);
}
+ public static void initDefaultUIProvider(Application application,
+ DeploymentConfiguration deploymentConfiguration)
+ throws ApplicationClassException {
+ String uiProperty = deploymentConfiguration
+ .getApplicationConfiguration().getInitParameters()
+ .getProperty(Application.UI_PARAMETER);
+ if (uiProperty != null) {
+ verifyUIClass(uiProperty, deploymentConfiguration.getClassLoader());
+ application.addUIProvider(new DefaultUIProvider());
+ }
+ }
+
+ public static void checkUiProviders(Application newApplication)
+ throws ApplicationClassException {
+ if (newApplication.getUIProviders().isEmpty()) {
+ throw new ApplicationClassException(
+ "No UIProvider has been added to the application and there is no \""
+ + Application.UI_PARAMETER + "\" init parameter.");
+ }
+ }
+
}
public String getThemeForUI(WrappedRequest request,
Class<? extends UI> uiClass);
+ /**
+ * Finds an existing {@link UI} for a request.
+ * <p>
+ * Implementations should take care to not return an UI instance that might
+ * be used in some other browser as that might cause synchronization issues
+ * when changes from one browser window are not present in the other.
+ * <p>
+ * If no UI provider returns an existing UI, the framework does also check
+ * the window.name for an existing instance with
+ * {@link #isUiPreserved(WrappedRequest, Class)} before falling back to
+ * bootstrapping and creating a new UI instance.
+ *
+ * @param request
+ * the request for which a UI is desired
+ * @return a UI belonging to the request, or <code>null</code> if this UI
+ * provider doesn't have an existing UI for the request.
+ */
+ public UI getExistingUI(WrappedRequest request);
+
}
if (restartApplication) {
closeApplication(application, request.getPortletSession(false));
- return createApplication(request);
+ return createAndRegisterApplication(request);
} else if (closeApplication) {
closeApplication(application, request.getPortletSession(false));
return null;
// No existing application was found
if (requestCanCreateApplication) {
- return createApplication(request);
+ return createAndRegisterApplication(request);
} else {
throw new SessionExpiredException();
}
}
}
- private Application createApplication(PortletRequest request)
+ private Application createAndRegisterApplication(PortletRequest request)
throws PortletException {
- Application newApplication = getNewApplication(request);
+ Application newApplication = createApplication(request);
+
+ try {
+ ServletPortletHelper.checkUiProviders(newApplication);
+ } catch (ApplicationClassException e) {
+ throw new PortletException(e);
+ }
+
final PortletApplicationContext2 context = getApplicationContext(request
.getPortletSession());
context.setApplication(newApplication, new PortletCommunicationManager(
return newApplication;
}
+ protected Application createApplication(PortletRequest request)
+ throws PortletException {
+ Application application = new Application();
+
+ try {
+ ServletPortletHelper.initDefaultUIProvider(application,
+ getDeploymentConfiguration());
+ } catch (ApplicationClassException e) {
+ throw new PortletException(e);
+ }
+
+ return application;
+ }
+
private Application getExistingApplication(PortletRequest request,
boolean allowSessionCreation) throws MalformedURLException,
SessionExpiredException {
return null;
}
- protected Class<? extends Application> getApplicationClass()
- throws ApplicationClassException {
- return ServletPortletHelper
- .getApplicationClass(getDeploymentConfiguration());
- }
-
- protected Application getNewApplication(PortletRequest request)
- throws PortletException {
- try {
- final Application application = getApplicationClass().newInstance();
- return application;
- } catch (final IllegalAccessException e) {
- throw new PortletException("getNewApplication failed", e);
- } catch (final InstantiationException e) {
- throw new PortletException("getNewApplication failed", e);
- } catch (final ApplicationClassException e) {
- throw new PortletException("getNewApplication failed", e);
- }
- }
-
private void handleServiceException(WrappedPortletRequest request,
WrappedPortletResponse response, Application application,
Throwable e) throws IOException, PortletException {
if (restartApplication) {
closeApplication(application, request.getSession(false));
- return createApplication(request);
+ return createAndRegisterApplication(request);
} else if (closeApplication) {
closeApplication(application, request.getSession(false));
return null;
* If the request is such that it should create a new application if
* one as not found, we do that.
*/
- return createApplication(request);
+ return createAndRegisterApplication(request);
} else {
/*
* The application was not found and a new one should not be
}
+ private Application createAndRegisterApplication(HttpServletRequest request)
+ throws ServletException {
+ Application newApplication = createApplication(request);
+
+ try {
+ ServletPortletHelper.checkUiProviders(newApplication);
+ } catch (ApplicationClassException e) {
+ throw new ServletException(e);
+ }
+
+ final ServletApplicationContext context = getApplicationContext(request
+ .getSession());
+ context.setApplication(newApplication,
+ createCommunicationManager(newApplication));
+
+ return newApplication;
+ }
+
/**
* Check if the request should create an application if an existing
* application is not found.
* @throws ServletException
* @throws MalformedURLException
*/
- private Application createApplication(HttpServletRequest request)
- throws ServletException, MalformedURLException {
- Application newApplication = getNewApplication(request);
+ protected Application createApplication(HttpServletRequest request)
+ throws ServletException {
+ Application newApplication = new Application();
- final ServletApplicationContext context = getApplicationContext(request
- .getSession());
- context.setApplication(newApplication,
- createCommunicationManager(newApplication));
+ try {
+ ServletPortletHelper.initDefaultUIProvider(newApplication,
+ getDeploymentConfiguration());
+ } catch (ApplicationClassException e) {
+ throw new ServletException(e);
+ }
return newApplication;
}
log("Invalid security key received from " + request.getRemoteHost());
}
- /**
- * Creates a new application for the given request.
- *
- * @param request
- * the HTTP request.
- * @return A new Application instance.
- * @throws ServletException
- */
- protected Application getNewApplication(HttpServletRequest request)
- throws ServletException {
-
- // Creates a new application instance
- try {
- Class<? extends Application> applicationClass = ServletPortletHelper
- .getApplicationClass(getDeploymentConfiguration());
-
- final Application application = applicationClass.newInstance();
- application.addUIProvider(new DefaultUIProvider());
-
- return application;
- } catch (final IllegalAccessException e) {
- throw new ServletException("getNewApplication failed", e);
- } catch (final InstantiationException e) {
- throw new ServletException("getNewApplication failed", e);
- } catch (ApplicationClassException e) {
- throw new ServletException("getNewApplication failed", e);
- }
- }
-
/**
* Starts the application if it is not already running.
*
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
}
@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)) {
}
});
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");
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;
/**
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, "
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;
/**
try {
final Application.LegacyApplication app = (Application.LegacyApplication) c
.newInstance();
- app.init();
+ app.doInit();
Layout lo = (Layout) app.getMainWindow().getContent();
lo.setParent(null);
return lo;
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
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);
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;
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;
/**
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);
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;
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");
</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>
</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>
</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>
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
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
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
}
@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";
}
} else if (value == reference) {
return "this";
} else {
- return value.toString();
+ return "some";
}
}
+++ /dev/null
-package com.vaadin.tests.components;
-
-import com.vaadin.Application;
-import com.vaadin.server.ApplicationContext;
-import com.vaadin.server.WebBrowser;
-
-public abstract class AbstractTestApplication extends Application {
- protected abstract String getTestDescription();
-
- protected abstract Integer getTicketNumber();
-
- protected WebBrowser getBrowser() {
- ApplicationContext context = getContext();
- WebBrowser webBrowser = context.getBrowser();
- return webBrowser;
- }
-}
--- /dev/null
+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 AbstractTestUIProvider extends AbstractUIProvider {
+ protected abstract String getTestDescription();
+
+ protected abstract Integer getTicketNumber();
+
+ protected WebBrowser getBrowser() {
+ ApplicationContext context = Application.getCurrent().getContext();
+ WebBrowser webBrowser = context.getBrowser();
+ return webBrowser;
+ }
+}
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;
}
protected void updateLocale(Locale locale) {
- setLocale(locale);
+ Application.getCurrent().setLocale(locale);
for (Component c : fields) {
removeComponent(c);
}
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 {
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 {
}
@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) {
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);
}
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
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;
private AbstractComponent rc1, col1, col2, col3, row1, row2, row3, x3, x22;
- public GridLayoutTests(Application application) {
+ public GridLayoutTests(LegacyApplication application) {
super();
}
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;
public class HorizontalLayoutTests extends AbstractLayoutTests {
- public HorizontalLayoutTests(Application application) {
+ public HorizontalLayoutTests(LegacyApplication application) {
super();
}
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;
public class VerticalLayoutTests extends AbstractLayoutTests {
- public VerticalLayoutTests(Application application) {
+ public VerticalLayoutTests(LegacyApplication application) {
super();
}
* @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);
+ }
}
}
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)",
newState();
- addRequestHandler(this);
+ Application.getCurrent().addRequestHandler(this);
}
public void newState() {
Link l = new Link("l", icon);
main.addComponent(l);
- addRequestHandler(this);
+ Application.getCurrent().addRequestHandler(this);
}
@Override