]> source.dussan.org Git - vaadin-framework.git/commitdiff
Multiple changes for gwt terminals server side:
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 13 Aug 2009 15:57:15 +0000 (15:57 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 13 Aug 2009 15:57:15 +0000 (15:57 +0000)
 * 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

src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/client/BrowserInfo.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/PortletApplicationContext.java
src/com/vaadin/terminal/gwt/server/WebApplicationContext.java
src/com/vaadin/terminal/gwt/server/WebBrowser.java

index 5bcb2873ff1fb0a4ea35e13244db23bd37f950f9..b09373d20e1a41791ab0db92b81777d8ee7908c2 100755 (executable)
@@ -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";
             }
index 23e70832b6976d286f91c5e298b29a87a5d8c533..2872ca360e1815cea17f8f32ec29a7cd2b695b15 100644 (file)
@@ -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;
+    }-*/;
+
 }
index 3ae6504ed1ae7bc8dd2490a2292d6e3b93d325e2..f6106cfb1dc437104da9399b1cc5994a9fdbacbc 100644 (file)
@@ -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);
         }
     }
 
index 87fe4104a863ba2220129d4375be6b7c9bc355e5..dfbfaf38eeb17c3cd41235c35c728558f65b5207 100644 (file)
@@ -98,22 +98,6 @@ public class PortletApplicationContext extends WebApplicationContext implements
         super.removeApplication(application);\r
     }\r
 \r
-    @Override\r
-    public boolean equals(Object obj) {\r
-        if (portletSession == null) {\r
-            return super.equals(obj);\r
-        }\r
-        return portletSession.equals(obj);\r
-    }\r
-\r
-    @Override\r
-    public int hashCode() {\r
-        if (portletSession == null) {\r
-            return super.hashCode();\r
-        }\r
-        return portletSession.hashCode();\r
-    }\r
-\r
     public void setPortletApplication(Portlet portlet, Application app) {\r
         portletToApplication.put(portlet, app);\r
     }\r
index 246de4e392372975dbf65d5e0ad597e101bec80f..304282fd9f4d50bc61eb7cafbbeb30c164ac2381 100644 (file)
@@ -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.
      * 
index 2ec726fc6a7e30ebc46edd3efd2b76dac45f94b9..67e8ac7f061d3eb01a28d5e29ba6b9fad218b812 100644 (file)
@@ -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);