From 11d152a9bab1c97b08ec45668641a18674ce55a2 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Thu, 13 Aug 2009 15:57:15 +0000 Subject: [PATCH] Multiple changes for gwt terminals server side: * fixes #3181 * improvement for #3054 (not a full fix) * removed mostly broken equals & hashCode methods from Web and Portlet contexts * refactoring svn changeset:8480/svn branch:6.1 --- .../gwt/client/ApplicationConnection.java | 17 +++++- .../terminal/gwt/client/BrowserInfo.java | 10 +++ .../server/AbstractApplicationServlet.java | 61 ++++++++----------- .../gwt/server/PortletApplicationContext.java | 16 ----- .../gwt/server/WebApplicationContext.java | 17 ------ .../terminal/gwt/server/WebBrowser.java | 6 +- 6 files changed, 55 insertions(+), 72 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 5bcb2873ff..b09373d20e 100755 --- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -304,7 +304,22 @@ public class ApplicationConnection { console.log("Making UIDL Request with params: " + requestData); String uri = getAppUri() + "UIDL" + configuration.getPathInfo(); if (repaintAll) { - uri += "?repaintAll=1"; + int clientHeight = Window.getClientHeight(); + int clientWidth = Window.getClientWidth(); + com.google.gwt.dom.client.Element pe = view.getElement() + .getParentElement(); + int offsetHeight = pe.getOffsetHeight(); + int offsetWidth = pe.getOffsetWidth(); + int screenWidth = BrowserInfo.get().getScreenWidth(); + int screenHeight = BrowserInfo.get().getScreenHeight(); + + // TODO figure out how client and view size could be used better on + // server. screen size can be accessed via Browser object, but other + // values currently only via transaction listener. + uri += "?repaintAll=1&" + "sh=" + screenHeight + "&sw=" + + screenWidth + "&cw=" + clientWidth + "&ch=" + + clientHeight + "&vw=" + offsetWidth + "&vh=" + + offsetHeight; if (analyzeLayouts) { uri += "&analyzeLayouts=1"; } diff --git a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java index 23e70832b6..2872ca360e 100644 --- a/src/com/vaadin/terminal/gwt/client/BrowserInfo.java +++ b/src/com/vaadin/terminal/gwt/client/BrowserInfo.java @@ -222,4 +222,14 @@ public class BrowserInfo { c.log("isIE() " + get().isIE()); } + public native int getScreenWidth() + /*-{ + return $wnd.screen.width; + }-*/; + + public native int getScreenHeight() + /*-{ + return $wnd.screen.height; + }-*/; + } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java index 3ae6504ed1..f6106cfb1d 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java @@ -115,9 +115,6 @@ public abstract class AbstractApplicationServlet extends HttpServlet { /** * If set, do not load the default theme but assume that loading it is * handled e.g. by ApplicationPortlet. - * - * The default theme should be located in - * REQUEST_DEFAULT_THEME_URI/THEME_DIRECTORY_PATH/getDefaultTheme() . */ public static final String REQUEST_DEFAULT_THEME = ApplicationServlet.class .getName() @@ -412,14 +409,15 @@ public abstract class AbstractApplicationServlet extends HttpServlet { /* Update browser information from the request */ webApplicationContext.getBrowser().updateBrowserProperties(request); + // Start the newly created application + startApplication(request, application, webApplicationContext); + /* * Transaction starts. Call transaction listeners. Transaction end * is called in the finally block below. */ webApplicationContext.startTransaction(application, request); - // TODO Add screen height and width to the GWT client - /* Handle the request */ if (requestType == RequestType.FILE_UPLOAD) { applicationManager.handleFileUpload(request, response); @@ -430,7 +428,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet { return; } - // Removes application if it has stopped (by thread, + // Removes application if it has stopped (mayby by thread or // transactionlistener) if (!application.isRunning()) { endApplication(request, response, application); @@ -795,9 +793,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet { } /** - * Creates and starts a new application. This is not meant to be overridden. - * Override getNewApplication to create the application instance in a custom - * way. + * Creates a new application and registers it into WebApplicationContext + * (aka session). This is not meant to be overridden. Override + * getNewApplication to create the application instance in a custom way. * * @param request * @return @@ -808,15 +806,9 @@ public abstract class AbstractApplicationServlet extends HttpServlet { throws ServletException, MalformedURLException { Application newApplication = getNewApplication(request); - // Create application - final URL applicationUrl = getApplicationUrl(request); - - // Initial locale comes from the request - Locale locale = request.getLocale(); - HttpSession session = request.getSession(); - - // Start the newly created application - startApplication(session, newApplication, applicationUrl, locale); + final WebApplicationContext context = WebApplicationContext + .getApplicationContext(request.getSession()); + context.addApplication(newApplication); return newApplication; } @@ -864,7 +856,8 @@ public abstract class AbstractApplicationServlet extends HttpServlet { // no explicit theme for window defined if (request.getAttribute(REQUEST_DEFAULT_THEME) != null) { // the default theme is defined in request (by portal) - return (String) request.getAttribute(REQUEST_DEFAULT_THEME); + themeName = (String) request + .getAttribute(REQUEST_DEFAULT_THEME); } else { // using the default theme defined by Vaadin themeName = getDefaultTheme(); @@ -993,29 +986,27 @@ public abstract class AbstractApplicationServlet extends HttpServlet { throws ServletException; /** - * Starts the application if it is not already running. Ensures the - * application is added to the WebApplicationContext. + * Starts the application if it is not already running. * - * @param session + * @param request * @param application - * @param applicationUrl - * @param locale + * @param webApplicationContext * @throws ServletException + * @throws MalformedURLException */ - private void startApplication(HttpSession session, Application application, - URL applicationUrl, Locale locale) throws ServletException { - if (application == null) { - throw new ServletException( - "Application is null and can't be started"); - } + private void startApplication(HttpServletRequest request, + Application application, WebApplicationContext webApplicationContext) + throws ServletException, MalformedURLException { if (!application.isRunning()) { - final WebApplicationContext context = WebApplicationContext - .getApplicationContext(session); - // final URL applicationUrl = getApplicationUrl(request); - context.addApplication(application); + // Create application + final URL applicationUrl = getApplicationUrl(request); + + // Initial locale comes from the request + Locale locale = request.getLocale(); application.setLocale(locale); - application.start(applicationUrl, applicationProperties, context); + application.start(applicationUrl, applicationProperties, + webApplicationContext); } } diff --git a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java index 87fe4104a8..dfbfaf38ee 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java +++ b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java @@ -98,22 +98,6 @@ public class PortletApplicationContext extends WebApplicationContext implements super.removeApplication(application); } - @Override - public boolean equals(Object obj) { - if (portletSession == null) { - return super.equals(obj); - } - return portletSession.equals(obj); - } - - @Override - public int hashCode() { - if (portletSession == null) { - return super.hashCode(); - } - return portletSession.hashCode(); - } - public void setPortletApplication(Portlet portlet, Application app) { portletToApplication.put(portlet, app); } diff --git a/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java b/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java index 246de4e392..304282fd9f 100644 --- a/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java +++ b/src/com/vaadin/terminal/gwt/server/WebApplicationContext.java @@ -107,23 +107,6 @@ public class WebApplicationContext implements ApplicationContext, return cx; } - @Override - public boolean equals(Object obj) { - if (session == null) { - return false; - } - - return session.equals(obj); - } - - @Override - public int hashCode() { - if (session == null) { - return -1; - } - return session.hashCode(); - } - /** * Adds the transaction listener to this context. * diff --git a/src/com/vaadin/terminal/gwt/server/WebBrowser.java b/src/com/vaadin/terminal/gwt/server/WebBrowser.java index 2ec726fc6a..67e8ac7f06 100644 --- a/src/com/vaadin/terminal/gwt/server/WebBrowser.java +++ b/src/com/vaadin/terminal/gwt/server/WebBrowser.java @@ -64,9 +64,9 @@ public class WebBrowser implements Terminal { browserApplication = agent; } - final String sw = request.getParameter("screenWidth"); - final String sh = request.getParameter("screenHeight"); - if (sw != null && sh != null) { + final String sw = request.getParameter("sw"); + if (sw != null) { + final String sh = request.getParameter("sh"); try { screenHeight = Integer.parseInt(sh); screenWidth = Integer.parseInt(sw); -- 2.39.5