]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support for opening application level windows, opening urls, managing subwindows...
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Sun, 26 Aug 2007 11:16:18 +0000 (11:16 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Sun, 26 Aug 2007 11:16:18 +0000 (11:16 +0000)
svn changeset:2127/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java
src/com/itmill/toolkit/terminal/gwt/server/ApplicationServlet.java
src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
src/com/itmill/toolkit/ui/FrameWindow.java
src/com/itmill/toolkit/ui/Window.java

index 71b400bd9abe19f5361730a5af8174fb0945c430..1eb3942a7b8984930600a5f24f6a23fb64cf2081 100755 (executable)
@@ -81,10 +81,14 @@ public class ApplicationConnection implements EntryPoint, FocusListener {
         return $wnd.itmtk.appUri;
        }-*/;
 
+       private native String getPathInfo()/*-{
+        return $wnd.itmtk.pathInfo;
+       }-*/;
+
        private void makeUidlRequest(String requestData) {
                console.log("Making UIDL Request with params: " + requestData);
                rb = new RequestBuilder(RequestBuilder.POST, appUri
-                               + "/UIDL/?requestId=" + (Math.random()) + "&" + requestData);
+                               + "/UIDL" + getPathInfo() + "?requestId=" + (Math.random()) + "&" + requestData);
                try {
                        rb.sendRequest(requestData, new RequestCallback() {
                                public void onError(Request request, Throwable exception) {
@@ -168,16 +172,8 @@ public class ApplicationConnection implements EntryPoint, FocusListener {
                                                                + uidl.getTag()
                                                                + ", but there is no such paintable ("
                                                                + uidl.getId() + ") registered yet.");
-                                       if(uidl.getId().equals("PID0")) {
-                                               // view
                                                view.updateFromUIDL(uidl, this);
-                                       } else {
-                                               Widget window = widgetFactory.createWidget(uidl);
-                                               registerPaintable(uidl.getId(), (Paintable) window);
-                                               RootPanel.get().add(window);
-                                               ((Paintable) window).updateFromUIDL(uidl, this);
-                                       }
-                               }
+                                               }
                        } catch (Throwable e) {
                                e.printStackTrace();
                        }
index b0b2e2df927f8f4d1d767fdc6b8a2a2f0c15757d..9b780e8897f79c58df8e44471679908e1a86ad1c 100644 (file)
@@ -3,6 +3,7 @@ package com.itmill.toolkit.terminal.gwt.client.ui;
 import java.util.HashSet;
 import java.util.Iterator;
 
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.SimplePanel;
 import com.google.gwt.user.client.ui.Widget;
@@ -25,10 +26,29 @@ public class IView extends SimplePanel implements Paintable {
        }
        
        public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+               
+               // Start drawing from scratch
                clear();
+               
+               // Some attributes to note
                theme = uidl.getStringAttribute("theme");
                com.google.gwt.user.client.Window.setTitle(uidl.getStringAttribute("caption"));
-               UIDL childUidl = uidl.getChildUIDL(0);
+               
+               // Process children
+               int childIndex = 0;
+               
+               // Open URL:s
+               while (childIndex < uidl.getChidlCount() && 
+                               "open".equals(uidl.getChildUIDL(childIndex).getTag())) {
+                       UIDL open = uidl.getChildUIDL(childIndex);
+                       String url = open.getStringAttribute("src");
+                       String target = open.getStringAttribute("target");
+                       Window.open(url, target != null ? target : null, "");
+                       childIndex++;
+               }
+               
+               // Draw this application level window
+               UIDL childUidl = uidl.getChildUIDL(childIndex);
                Paintable lo = (Paintable) client.getWidget(childUidl);
                if(layout != null) {
                        if(layout != lo) {
@@ -43,9 +63,11 @@ public class IView extends SimplePanel implements Paintable {
                }
                lo.updateFromUIDL(childUidl, client);
                
-               int i=1;
+               // Update subwindows
                HashSet removedSubWindows = new HashSet(subWindows);
-               while ((childUidl = uidl.getChildUIDL(i++)) != null) {
+               
+               // Open new windows
+               while ((childUidl = uidl.getChildUIDL(childIndex++)) != null) {
                        if ("window".equals(childUidl.getTag())) {
                                Widget w = client.getWidget(childUidl);
                                if (subWindows.contains(w)) {
@@ -58,6 +80,8 @@ public class IView extends SimplePanel implements Paintable {
                                ((Paintable)w).updateFromUIDL(childUidl, client);
                        }
                }
+               
+               // Close old windows
                for (Iterator rem=removedSubWindows.iterator(); rem.hasNext();) {
                        IWindow w = (IWindow) rem.next();
                        client.unregisterPaintable(w);
index 3366ef49c5a6538e7f1371e1702362165a1fd7c9..0eba8a132302ca2221da47738b4cca573c644cae 100644 (file)
@@ -426,6 +426,14 @@ public class ApplicationServlet extends HttpServlet {
                String uri = request.getRequestURL().toString();
                boolean hasSlash = (uri.charAt(uri.length()-1) == '/') ? true : false;
                
+               String relative = "";
+               String t = request.getPathInfo().substring(1);
+               while (t.indexOf('/')>=0) {
+                       t = t.substring(t.indexOf('/')+1);
+                       relative += "../";
+               }
+               
+               
                page
                                .write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" "
                                                + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
@@ -448,10 +456,10 @@ public class ApplicationServlet extends HttpServlet {
                
                page.write(appUrl);
                
-               page.write("'\n};\n" +
+               page.write("', pathInfo: '"+request.getPathInfo()+"'\n};\n" +
                                "</script>\n" +
                                
-                               "<script language='javascript' src='"+ (hasSlash ? "../" : "") + "com.itmill.toolkit.terminal.gwt.Client/com.itmill.toolkit.terminal.gwt.Client.nocache.js'></script>" +
+                               "<script language='javascript' src='"+ (hasSlash ? "../" : "") + relative + "com.itmill.toolkit.terminal.gwt.Client/com.itmill.toolkit.terminal.gwt.Client.nocache.js'></script>" +
 
                                "<link REL=\"stylesheet\" TYPE=\"text/css\" HREF=\""+request.getContextPath() + THEME_DIRECTORY_PATH+themeName+"/style.css\">" + 
                                "</head>\n<body>\n" +
index 7298376780aa1ef135f8c2599320d854b098a62f..1eaa0eab816bbd252596d5f284d3bb1c7bd4996c 100644 (file)
@@ -206,14 +206,7 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
                                                // Reset sent locales
                                                locales = null;
                                                requireLocale(application.getLocale().toString());
-
-                                               // Adds all non-native windows
-                                               for (Iterator i = window.getApplication().getWindows()
-                                                               .iterator(); i.hasNext();) {
-                                                       Window w = (Window) i.next();
-                                                       if (!"native".equals(w.getStyle()) && w != window)
-                                                               paintables.add(w);
-                                               }
+                                               
                                        } else
                                                paintables = getDirtyComponents();
                                        if (paintables != null) {
@@ -299,10 +292,6 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
                                        outWriter.print(", \"meta\" : {");
                                        boolean metaOpen = false;
 
-                                       // .. or initializion (first uidl-request)
-                                       if (application.ajaxInit()) {
-                                               outWriter.print("\"appInit\":true");
-                                       }
                                        // add meta instruction for client to set focus if it is set
                                        Paintable f = (Paintable) application.consumeFocus();
                                        if (f != null) {
@@ -601,6 +590,9 @@ public class CommunicationManager implements Paintable.RepaintRequestListener,
 
                // Find the window where the request is handled
                String path = request.getPathInfo();
+               
+               // Remove UIDL from the path
+               path = path.substring("/UIDL".length());
 
                // Main window as the URI is empty
                if (path == null || path.length() == 0 || path.equals("/"))
index e9b18d9e76efa4bac840b8fcf2e423c7efe9ba17..1b25d9c09a3fcd654bebe8e8585ca774cda44032 100644 (file)
@@ -56,6 +56,7 @@ import com.itmill.toolkit.terminal.Resource;
  * @author IT Mill Ltd.
  * @version
  * @VERSION@
+ * @deprecated
  * @since 3.0
  */
 public class FrameWindow extends Window {
index 890ae5c41070e2d84aff1ceebc7b4ac2dc0a3329..48115ffb0dae8910639ac9b2e87abc93c2991159 100644 (file)
@@ -650,8 +650,7 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
        /**
         * Sets the name.
         * <p>
-        * The name of the window must be unique inside the application. Also the
-        * name may only contain the following characters: a-z, A-Z and 0-9.
+        * The name of the window must be unique inside the application.
         * </p>
         * 
         * <p>
@@ -670,17 +669,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
                                        "Window name can not be changed while "
                                                        + "the window is in application");
 
-               // Checks the name format
-               if (name != null)
-                       for (int i = 0; i < name.length(); i++) {
-                               char c = name.charAt(i);
-                               if (!(('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9')))
-                                       throw new IllegalArgumentException(
-                                                       "Window name can contain "
-                                                                       + "only a-z, A-Z and 0-9 characters: '"
-                                                                       + name + "' given.");
-                       }
-
                this.name = name;
        }