]> source.dussan.org Git - vaadin-framework.git/commitdiff
Client now renderes unknown compoenents with special component that dirs their uidl...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Jun 2007 12:34:50 +0000 (12:34 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 7 Jun 2007 12:34:50 +0000 (12:34 +0000)
svn changeset:1637/svn branch:trunk

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

index 0068b67e5799201df0849d2520fc482828e65b4d..2c1f0b4303f429efebc7d8112673eb6b7a8a20ac 100755 (executable)
@@ -102,43 +102,50 @@ public class Client implements EntryPoint {
 
        private void handleReceivedJSONMessage(Response response) {
                Date start = new Date();
-               JSONValue json = JSONParser
-                               .parse(response.getText().substring(3) + "}");
-
-               // Process changes
-               JSONArray changes = (JSONArray) ((JSONObject) json).get("changes");
-               for (int i = 0; i < changes.size(); i++) {
-                       try {
-                               UIDL change = new UIDL((JSONArray) changes.get(i));
-                               console.log("Received the following change: ");
+               
+               try{
+                       JSONValue json = JSONParser
+                       .parse(response.getText().substring(3) + "}");
+                       // Process changes
+                       JSONArray changes = (JSONArray) ((JSONObject) json).get("changes");
+                       for (int i = 0; i < changes.size(); i++) {
                                try {
-                                       console.dirUIDL(change);
-                               } catch (Exception e) {
-                                       // TODO: dir doesn't work in any browser although it should work (works in hosted mode)
-                                       // it partially did at some part but now broken.
-                               }
-                               UIDL uidl = change.getChildUIDL(0);
-                               Paintable paintable = getPaintable(uidl.getId());
-                               if (paintable != null)
-                                       paintable.updateFromUIDL(uidl, this);
-                               else {
-                                       if (!uidl.getTag().equals("window"))
-                                               throw new IllegalStateException("Received update for "
-                                                               + uidl.getTag()
-                                                               + ", but there is no such paintable ("
-                                                               + uidl.getId() + ") registered yet.");
-                                       Widget window = createWidgetFromUIDL(uidl);
-                                       // We should also handle other windows 
-                                       RootPanel.get("itmtk-ajax-window").add(window);
+                                       UIDL change = new UIDL((JSONArray) changes.get(i));
+                                       console.log("Received the following change: ");
+                                       try {
+                                               console.dirUIDL(change);
+                                       } catch (Exception e) {
+                                               // TODO: dir doesn't work in any browser although it should work (works in hosted mode)
+                                               // it partially did at some part but now broken.
+                                       }
+                                       UIDL uidl = change.getChildUIDL(0);
+                                       Paintable paintable = getPaintable(uidl.getId());
+                                       if (paintable != null)
+                                               paintable.updateFromUIDL(uidl, this);
+                                       else {
+                                               if (!uidl.getTag().equals("window"))
+                                                       throw new IllegalStateException("Received update for "
+                                                                       + uidl.getTag()
+                                                                       + ", but there is no such paintable ("
+                                                                       + uidl.getId() + ") registered yet.");
+                                               Widget window = createWidgetFromUIDL(uidl);
+                                               // We should also handle other windows 
+                                               RootPanel.get("itmtk-ajax-window").add(window);
+                                       }
+       
+                               } catch (Throwable e) {
+                                       e.printStackTrace();
                                }
-
-                       } catch (Throwable e) {
-                               e.printStackTrace();
+       
                        }
-
+                       long prosessingTime = (new Date().getTime()) - start.getTime();
+                       console.log(" Processing time was " + String.valueOf(prosessingTime));
+               } catch (Exception e) {
+                       // TODO: remove this try catch when uidl JSON stabilizes
+                       console.log("Error parsing JSON:");
+                       console.log(response.getText().substring(3) + "}");
                }
-               long prosessingTime = (new Date().getTime()) - start.getTime();
-               console.log(" Processing time was " + String.valueOf(prosessingTime));
+
        }
 
        public void registerPaintable(String id, Paintable paintable) {
index 03fae654412ea11a3eaed60a98f277991c9aac21..3d144da418931a796e233a2ec4b0ac74f535b406 100644 (file)
@@ -5,6 +5,7 @@ import com.itmill.toolkit.terminal.gwt.client.ui.Button;
 import com.itmill.toolkit.terminal.gwt.client.ui.GridLayout;
 import com.itmill.toolkit.terminal.gwt.client.ui.Label;
 import com.itmill.toolkit.terminal.gwt.client.ui.OrderedLayout;
+import com.itmill.toolkit.terminal.gwt.client.ui.UnknownComponent;
 import com.itmill.toolkit.terminal.gwt.client.ui.Window;
 
 public class DefaultWidgetFactory implements WidgetFactory {
@@ -22,7 +23,7 @@ public class DefaultWidgetFactory implements WidgetFactory {
                if ("gridlayout".equals(tag))
                        return new GridLayout();
 
-               return null;
+               return new UnknownComponent();
        }
 
 }
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/UnknownComponent.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/UnknownComponent.java
new file mode 100644 (file)
index 0000000..b5efa79
--- /dev/null
@@ -0,0 +1,32 @@
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.Tree;
+import com.google.gwt.user.client.ui.VerticalPanel;
+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 UnknownComponent extends Composite implements Paintable{
+       
+       com.google.gwt.user.client.ui.Label caption = new com.google.gwt.user.client.ui.Label();;
+       Tree uidlTree = new Tree();
+       
+       public UnknownComponent() {
+               VerticalPanel panel = new VerticalPanel();
+               panel.add(caption);
+               panel.add(uidlTree);
+               initWidget(panel);
+               setStyleName("itmtk-unknown");
+               caption.setStyleName("itmtk-unknown-caption");
+       }
+       
+       public void updateFromUIDL(UIDL uidl, Client client) {
+               setCaption("Client faced an unknown component type. Unrendered UIDL:");
+               uidlTree.addItem(uidl.dir());
+       }
+       
+       public void setCaption(String c) {
+               caption.setText(c);
+       }
+}