]> source.dussan.org Git - vaadin-framework.git/commitdiff
drafting OrderedLayout
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 6 Jun 2007 13:10:09 +0000 (13:10 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 6 Jun 2007 13:10:09 +0000 (13:10 +0000)
svn changeset:1624/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/Client.java
src/com/itmill/toolkit/terminal/gwt/client/Paintable.java
src/com/itmill/toolkit/terminal/gwt/client/ui/OrderedLayout.java [new file with mode: 0644]

index 83104cdf1f9aabf800633a0ecc21dd6092075e5a..1cc93a24e270edcbb1878e01f85152eab45b6dc2 100755 (executable)
@@ -26,99 +26,115 @@ import com.itmill.toolkit.terminal.gwt.client.ui.RootWindow;
 public class Client implements EntryPoint {
 
        private String appUri = "http://127.0.0.1:8080/tk/HelloWorld";
-       
+
        // TODO remove repaintAll things start to pile up
-       private RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri + "/UIDL/?repaintAll=1&");
-       
+       private RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri
+                       + "/UIDL/?repaintAll=1&");
+
        private Console console;
 
        private RootWindow rw;
-       
+
        private Vector pendingVariables = new Vector();
-       
+
        private HashMap components = new HashMap();
-       
+
        private int requestCount = 0;
 
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
-               
+
                console = new Console(RootPanel.get("itmtk-loki"));
-               
+
                console.log("muutos");
 
                console.log("Starting app");
-               
+
                console.log("Makin fake UIDL Request to fool servlet of an app init");
                RequestBuilder rb2 = new RequestBuilder(RequestBuilder.GET, appUri);
                try {
                        rb2.sendRequest("", new RequestCallback() {
-                       
-                               public void onResponseReceived(Request request, Response response) {
-                                       console.log("Got fake response... sending initial UIDL request");
+
+                               public void onResponseReceived(Request request,
+                                               Response response) {
+                                       console
+                                                       .log("Got fake response... sending initial UIDL request");
                                        makeUidlRequest("repaintAll=1");
                                }
-                       
+
                                public void onError(Request request, Throwable exception) {
                                        // TODO Auto-generated method stub
-                       
+
                                }
-                       
+
                        });
                } catch (RequestException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }
-               
+
        }
 
        private void makeUidlRequest(String requestData) {
                console.log("Making UIDL Request");
-               rb = new RequestBuilder(RequestBuilder.GET, appUri + "/UIDL/?requestId=" + (++requestCount) + "&" + requestData);
+               rb = new RequestBuilder(RequestBuilder.GET, appUri
+                               + "/UIDL/?requestId=" + (++requestCount) + "&" + requestData);
                try {
                        rb.sendRequest(requestData, new RequestCallback() {
                                public void onError(Request request, Throwable exception) {
                                        console.error("Got error");
                                }
-                               public void onResponseReceived(Request request, Response response) {
-                                       console.log("Got response:");
-                                       JSONValue update = JSONParser.parse("("+response.getText()+")");
-                                       
-                                       // TEST 
+
+                               public void onResponseReceived(Request request,
+                                               Response response) {
+                                       console.log("Got response:" + response.getText() + "\n");
+                                       JSONValue update = JSONParser.parse(response.getText()
+                                                       .substring(3)
+                                                       + "}");
+
+                                       // TEST
                                        console.log(update.toString());
-                                       try {
-                                       UIDL u = new UIDL((JSONObject)update);
-                                       console.log("\nUIDL = " + u);
-                                       } catch (Throwable e) {
-                                               e.printStackTrace();
+                                       JSONArray changes = (JSONArray) ((JSONObject) update)
+                                                       .get("changes");
+
+                                       for (int i = 0; i < changes.size(); i++) {
+                                               try {
+                                                       console.log("Change " + i);
+                                                       UIDL u = new UIDL((JSONArray) changes.get(i));
+                                                       console.log("\nUIDL = " + u);
+                                               } catch (Throwable e) {
+                                                       e.printStackTrace();
+                                               }
+
                                        }
-                                       handleUIDL(update.isObject());
+
+                                       // handleUIDL(update.isObject());
                                }
                        });
                        console.log("Request sent");
-                       
+
                } catch (RequestException e) {
                        console.error(e.getMessage());
                }
        }
-       
+
        private void handleUIDL(JSONObject update) {
                JSONObject changes;
-               if(update.containsKey("meta")) {
+               if (update.containsKey("meta")) {
                        JSONObject meta = update.get("meta").isObject();
                }
-               
-               if( ( changes = update.isObject() ) != null) {
+
+               if ((changes = update.isObject()) != null) {
                        Set keys = changes.keySet();
                        Iterator it = keys.iterator();
-                       while(it.hasNext()) {
+                       while (it.hasNext()) {
                                String key = (String) it.next();
-                               if(key.startsWith("change")) {
+                               if (key.startsWith("change")) {
                                        JSONObject change = changes.get(key).isObject();
                                        JSONArray children;
-                                       if(children = change.isArray()) != null) {
+                                       if ((children = change.isArray()) != null) {
                                                for (int i = 0; i < children.size(); i++) {
                                                        applyChange(children.get(i).isObject());
                                                }
@@ -126,19 +142,20 @@ public class Client implements EntryPoint {
                                }
                        }
                }
-               
+
        }
-       
+
        private void applyChange(JSONObject change) {
-               if(change.get("attr").isObject().get("id").isString().equals("PID0")) {
+               if (change.get("attr").isObject().get("id").isString().equals("PID0")) {
                        console.log("Rendering main window");
-//                     rw = new RootWindow(change, this);
+                       // rw = new RootWindow(change, this);
                        rw.setClient(this);
                } else {
-//                     int pid = Component.getIdFromUidl(change);
-//                     console.log("Updating node: " + change.getNodeName() + ", PID:"+pid);
-//                     Component c = getPaintable(pid);
-//                     c.updateFromUidl(change);
+                       // int pid = Component.getIdFromUidl(change);
+                       // console.log("Updating node: " + change.getNodeName() + ",
+                       // PID:"+pid);
+                       // Component c = getPaintable(pid);
+                       // c.updateFromUidl(change);
                }
        }
 
@@ -148,21 +165,22 @@ public class Client implements EntryPoint {
         * @param variable
         */
        public void updateVariable(Variable variable) {
-               // remove variable first so we will maintain the correct order (in case of "double change")
+               // remove variable first so we will maintain the correct order (in case
+               // of "double change")
                pendingVariables.remove(variable);
                pendingVariables.add(variable);
        }
 
        /**
         * Sends queued variables to server
-        *
+        * 
         */
        public void flushVariables() {
 
-           StringBuffer sb = new StringBuffer();
+               StringBuffer sb = new StringBuffer();
 
                int i = 0;
-           while (!pendingVariables.isEmpty()) {
+               while (!pendingVariables.isEmpty()) {
                        Variable v = (Variable) pendingVariables.lastElement();
                        pendingVariables.removeElement(v);
 
@@ -173,27 +191,26 @@ public class Client implements EntryPoint {
                        String encodedName = URL.encodeComponent(v.getId());
                        sb.append(encodedName);
                        sb.append("=");
-           
+
                        // encode the characters in the value
                        String encodedValue = URL.encodeComponent(v.getEncodedValue());
                        sb.append(encodedValue);
-           }
-           
-           String buf = sb.toString();
-               
+               }
+
+               String buf = sb.toString();
+
                console.log("Making following request to server:");
                console.log(buf);
-               
+
                makeUidlRequest(buf);
        }
 
        public void registerComponent(Component component) {
-               components.put(""+component.getId(), component );
+               components.put("" + component.getId(), component);
        }
-       
+
        public Component getPaintable(int pid) {
-               return (Component) components.get(""+pid);
+               return (Component) components.get("" + pid);
        }
-       
-}
 
+}
index 38766b2af0b917fc1fa430a389230aa93bd5e5e6..df4ce112cb40a4c0c78eddac743b495839e1e888 100644 (file)
@@ -1,8 +1,6 @@
 package com.itmill.toolkit.terminal.gwt.client;
 
-import com.google.gwt.xml.client.Node;
-
 public interface Paintable {
 
-       public void updateFromUidl(UIDL uidl);
+       public void updateFromUIDL(UIDL uidl, Client client);
 }
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/OrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/OrderedLayout.java
new file mode 100644 (file)
index 0000000..42d23cf
--- /dev/null
@@ -0,0 +1,25 @@
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import java.util.Iterator;
+
+import com.google.gwt.user.client.ui.FlowPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.UIDL;
+
+public class OrderedLayout extends FlowPanel implements Paintable {
+
+       String id;
+       
+       public void updateFromUIDL(UIDL uidl, Client client) {
+               clear();
+               id = uidl.getId();
+               for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
+                       UIDL uidlForChild = (UIDL)i.next();
+               //      Widget child = client.createWidgetsFromUIDL(uidlForChild);
+               //      add(child);
+               }
+       }
+       
+}