]> source.dussan.org Git - vaadin-framework.git/commitdiff
Created stubs for Label, Window and Button. Now Hello World works.
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 6 Jun 2007 16:24:02 +0000 (16:24 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Wed, 6 Jun 2007 16:24:02 +0000 (16:24 +0000)
svn changeset:1629/svn branch:trunk

20 files changed:
src/com/itmill/toolkit/terminal/gwt/client/BooleanVariable.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/Client.java
src/com/itmill/toolkit/terminal/gwt/client/Console.java
src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java [new file with mode: 0644]
src/com/itmill/toolkit/terminal/gwt/client/UIDL.java
src/com/itmill/toolkit/terminal/gwt/client/Variable.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/VariableFactory.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java [new file with mode: 0644]
src/com/itmill/toolkit/terminal/gwt/client/ui/Button.java [new file with mode: 0644]
src/com/itmill/toolkit/terminal/gwt/client/ui/Component.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/ContainerComponent.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/Label.java [new file with mode: 0644]
src/com/itmill/toolkit/terminal/gwt/client/ui/OrderedLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/RootWindow.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/TkLabel.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/TkTextField.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/TkUnknown.java [deleted file]
src/com/itmill/toolkit/terminal/gwt/client/ui/Window.java [new file with mode: 0644]

diff --git a/src/com/itmill/toolkit/terminal/gwt/client/BooleanVariable.java b/src/com/itmill/toolkit/terminal/gwt/client/BooleanVariable.java
deleted file mode 100755 (executable)
index 342f943..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client;
-
-import com.itmill.toolkit.terminal.gwt.client.ui.Component;
-
-public class BooleanVariable extends Variable {
-
-       private boolean value = true;
-
-       public BooleanVariable(Component owner, String name, String id) {
-               super(owner, name, id);
-       }
-       
-
-       public void update() {
-               owner.getClient().updateVariable(this);
-               if(immediate)
-                       owner.getClient().flushVariables();
-
-       }
-
-       public boolean getValue() {
-               return value;
-       }
-
-       public void setValue(boolean value) {
-               this.value = value;
-       }
-
-
-       public String getEncodedValue() {
-               return ( value ? "true" : "false" );
-       }
-
-}
index 1cc93a24e270edcbb1878e01f85152eab45b6dc2..f3ac00f8632f2a88c7abb9081349c56d4e47c7a0 100755 (executable)
@@ -1,8 +1,6 @@
 package com.itmill.toolkit.terminal.gwt.client;
 
 import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Set;
 import java.util.Vector;
 
 import com.google.gwt.core.client.EntryPoint;
@@ -11,17 +9,17 @@ import com.google.gwt.http.client.RequestBuilder;
 import com.google.gwt.http.client.RequestCallback;
 import com.google.gwt.http.client.RequestException;
 import com.google.gwt.http.client.Response;
-import com.google.gwt.http.client.URL;
 import com.google.gwt.json.client.JSONArray;
 import com.google.gwt.json.client.JSONObject;
 import com.google.gwt.json.client.JSONParser;
 import com.google.gwt.json.client.JSONValue;
 import com.google.gwt.user.client.ui.RootPanel;
-import com.itmill.toolkit.terminal.gwt.client.ui.Component;
-import com.itmill.toolkit.terminal.gwt.client.ui.RootWindow;
+import com.google.gwt.user.client.ui.Widget;
 
 /**
  * Entry point classes define <code>onModuleLoad()</code>.
+ * 
+ * TODO IDEA: Should be extend Widget here !?!?!
  */
 public class Client implements EntryPoint {
 
@@ -33,14 +31,14 @@ public class Client implements EntryPoint {
 
        private Console console;
 
-       private RootWindow rw;
-
        private Vector pendingVariables = new Vector();
 
-       private HashMap components = new HashMap();
+       private HashMap paintables = new HashMap();
 
        private int requestCount = 0;
 
+       private WidgetFactory widgetFactory = new DefaultWidgetFactory();
+
        /**
         * This is the entry point method.
         */
@@ -48,10 +46,6 @@ public class Client implements EntryPoint {
 
                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 {
@@ -71,7 +65,6 @@ public class Client implements EntryPoint {
 
                        });
                } catch (RequestException e1) {
-                       // TODO Auto-generated catch block
                        e1.printStackTrace();
                }
 
@@ -89,29 +82,9 @@ public class Client implements EntryPoint {
 
                                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());
-                                       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());
+                                       handleReceivedJSONMessage(response);
                                }
+
                        });
                        console.log("Request sent");
 
@@ -120,97 +93,111 @@ public class Client implements EntryPoint {
                }
        }
 
-       private void handleUIDL(JSONObject update) {
-               JSONObject changes;
-               if (update.containsKey("meta")) {
-                       JSONObject meta = update.get("meta").isObject();
-               }
-
-               if ((changes = update.isObject()) != null) {
-                       Set keys = changes.keySet();
-                       Iterator it = keys.iterator();
-                       while (it.hasNext()) {
-                               String key = (String) it.next();
-                               if (key.startsWith("change")) {
-                                       JSONObject change = changes.get(key).isObject();
-                                       JSONArray children;
-                                       if ((children = change.isArray()) != null) {
-                                               for (int i = 0; i < children.size(); i++) {
-                                                       applyChange(children.get(i).isObject());
-                                               }
-                                       }
+       private void handleReceivedJSONMessage(Response response) {
+               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: " + change);
+                               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();
                        }
+
                }
+       }
+
+       public void registerPaintable(String id, Paintable paintable) {
+               paintables.put(id, paintable);
+       }
 
+       public Paintable getPaintable(String id) {
+               return (Paintable) paintables.get(id);
        }
 
-       private void applyChange(JSONObject change) {
-               if (change.get("attr").isObject().get("id").isString().equals("PID0")) {
-                       console.log("Rendering main window");
-                       // 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);
+       public Widget createWidgetFromUIDL(UIDL uidlForChild) {
+               Widget w = widgetFactory.createWidget(uidlForChild.getTag(), null);
+               if (w instanceof Paintable) {
+                       registerPaintable(uidlForChild.getId(), (Paintable) w);
+                       ((Paintable)w).updateFromUIDL(uidlForChild, this);
                }
+               return w;
        }
 
-       /**
-        * Queues a changed variable to be sent to server
-        * 
-        * @param variable
-        */
-       public void updateVariable(Variable variable) {
-               // remove variable first so we will maintain the correct order (in case
-               // of "double change")
-               pendingVariables.remove(variable);
-               pendingVariables.add(variable);
+       private void addVariableToQueue(String paintableId, String variableName,
+                       String encodedValue, boolean immediate) {
+               String id = paintableId + "_" + variableName;
+               for (int i = 0; i < pendingVariables.size(); i += 2)
+                       if ((pendingVariables.get(i)).equals(id)) {
+                               pendingVariables.remove(i);
+                               pendingVariables.remove(i);
+                               break;
+                       }
+               pendingVariables.add(id);
+               pendingVariables.add(encodedValue);
+               if (immediate)
+                       sendPendingVariableChanges();
        }
 
-       /**
-        * Sends queued variables to server
-        * 
-        */
-       public void flushVariables() {
+       public void sendPendingVariableChanges() {
+               StringBuffer req = new StringBuffer();
 
-               StringBuffer sb = new StringBuffer();
+               for (int i = 0; i < pendingVariables.size(); i++) {
+                       req.append(pendingVariables.get(i++));
+                       req.append("=");
+                       req.append(pendingVariables.get(i));
+               }
 
-               int i = 0;
-               while (!pendingVariables.isEmpty()) {
-                       Variable v = (Variable) pendingVariables.lastElement();
-                       pendingVariables.removeElement(v);
+               pendingVariables.clear();
+               makeUidlRequest(req.toString());
+       }
 
-                       if (i > 0) {
-                               sb.append("&");
-                       }
-                       // encode the characters in the name
-                       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);
-               }
+       private String escapeString(String value) {
+               // TODO
+               return value;
+       }
 
-               String buf = sb.toString();
+       public void updateVariable(String paintableId, String variableName,
+                       String newValue, boolean immediate) {
+               addVariableToQueue(paintableId, variableName, escapeString(newValue),
+                               immediate);
+       }
 
-               console.log("Making following request to server:");
-               console.log(buf);
+       public void updateVariable(String paintableId, String variableName,
+                       int newValue, boolean immediate) {
+               addVariableToQueue(paintableId, variableName, "" + newValue, immediate);
+       }
 
-               makeUidlRequest(buf);
+       public void updateVariable(String paintableId, String variableName,
+                       boolean newValue, boolean immediate) {
+               addVariableToQueue(paintableId, variableName, newValue ? "true"
+                               : "false", immediate);
        }
 
-       public void registerComponent(Component component) {
-               components.put("" + component.getId(), component);
+       public WidgetFactory getWidgetFactory() {
+               return widgetFactory;
        }
 
-       public Component getPaintable(int pid) {
-               return (Component) components.get("" + pid);
+       public void setWidgetFactory(WidgetFactory widgetFactory) {
+               this.widgetFactory = widgetFactory;
        }
 
 }
index 5f908afe1a1f9227e0bd4debfd272f74befb9d32..15ac7b4c5e8ae2d00d77d086f2e9adac08974263 100755 (executable)
@@ -22,26 +22,4 @@ public final class Console {
        public void printObject(Object msg) {
                rp.add((new Label(msg.toString())));
        }
-
-       
-//     public native void log(String msg) 
-///*-{
-//     console.log(msg);
-//}-*/;
-//
-//     public native void warn(String msg) 
-//     /*-{
-//             console.warn(msg);
-//     }-*/;
-//
-//     public native void error(String msg) 
-//     /*-{
-//             console.error(msg);
-//     }-*/;
-//
-//     public native void printObject(Object msg) 
-//     /*-{
-//             console.dir(msg);
-//     }-*/;
-
 }
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java
new file mode 100644 (file)
index 0000000..2e80534
--- /dev/null
@@ -0,0 +1,25 @@
+package com.itmill.toolkit.terminal.gwt.client;
+
+import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.ui.Button;
+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.Window;
+
+public class DefaultWidgetFactory implements WidgetFactory {
+
+       public Widget createWidget(String tag, String theme) {
+
+               if ("button".equals(tag))
+                       return new Button();
+               if ("window".equals(tag))
+                       return new Window();
+               if ("orderedlayout".equals(tag))
+                       return new OrderedLayout();
+               if ("label".equals(tag))
+                       return new Label();
+
+               return null;
+       }
+
+}
index d40f29e388bfb330fa673416ec3c4edab86c0566..43df8e52a9b9fcd353028963f525141d4fa31d3f 100644 (file)
@@ -20,23 +20,21 @@ public class UIDL {
        }
 
        public String getId() {
-               return getStringAttribute("id");
+               JSONValue val = ((JSONObject) json.get(1)).get("id");
+               if (val == null)
+                       return null;
+               return ((JSONString) val).stringValue();
        }
 
        public String getTag() {
-               return json.get(0).toString();
+               return ((JSONString) json.get(0)).stringValue();
        }
 
        public String getStringAttribute(String name) {
-               JSONValue val = ((JSONObject) json.get(1)).get(name);
-               return ((JSONString) val).stringValue();
-       }
-
-       public String getAttribute(String name) {
                JSONValue val = ((JSONObject) json.get(1)).get(name);
                if (val == null)
-                       return null;
-               return val.toString();
+                       return "";
+               return ((JSONString) val).stringValue();
        }
 
        public Set getAttributeNames() {
@@ -47,21 +45,49 @@ public class UIDL {
 
        public int getIntAttribute(String name) {
                JSONValue val = ((JSONObject) json.get(1)).get(name);
+               if (val == null)
+                       return 0;
                double num = ((JSONNumber) val).getValue();
                return (int) num;
        }
 
        public long getLongAttribute(String name) {
                JSONValue val = ((JSONObject) json.get(1)).get(name);
+               if (val == null)
+                       return 0;
                double num = ((JSONNumber) val).getValue();
                return (long) num;
        }
 
        public boolean getBooleanAttribute(String name) {
                JSONValue val = ((JSONObject) json.get(1)).get(name);
+               if (val == null)
+                       return false;
                return ((JSONBoolean) val).booleanValue();
        }
 
+       public boolean hasAttribute(String name) {
+               return ((JSONObject) json.get(1)).get(name) != null;
+       }
+       
+       public UIDL getChildUIDL(int i) {
+
+               JSONValue c = json.get(i + 2);
+               if (c.isArray() != null)
+                       return new UIDL(c.isArray());
+               throw new IllegalStateException("Child node " + i
+                               + " is not of type UIDL");
+       }
+
+       public String getChildString(int i) {
+
+               JSONValue c = json.get(i + 2);
+               if (c.isString() != null)
+                       return ((JSONString)c).stringValue();
+               throw new IllegalStateException("Child node " + i
+                               + " is not of type String");
+       }
+
        public Iterator getChildIterator() {
 
                return new Iterator() {
@@ -83,10 +109,8 @@ public class UIDL {
                                        else if (c.isObject() != null)
                                                return new XML(c.isObject());
                                        else
-                                               throw new IllegalStateException(
-                                                               "Illegal child "
-                                                                               + c + " in tag "
-                                                                               + getTag() + " at index " + index);
+                                               throw new IllegalStateException("Illegal child " + c
+                                                               + " in tag " + getTag() + " at index " + index);
                                }
                                return null;
                        }
@@ -103,7 +127,7 @@ public class UIDL {
 
                for (Iterator i = getAttributeNames().iterator(); i.hasNext();) {
                        String name = i.next().toString();
-                       s += " " + name + "=\"" + getAttribute(name) + "\"";
+                       s += " " + name + "=" + ((JSONObject) json.get(1)).get(name);
                }
 
                s += ">\n";
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Variable.java b/src/com/itmill/toolkit/terminal/gwt/client/Variable.java
deleted file mode 100755 (executable)
index 365b143..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client;
-
-import com.itmill.toolkit.terminal.gwt.client.ui.Component;
-
-public abstract class Variable {
-
-       protected Component owner;
-       protected boolean immediate = false;
-       protected String name;
-       protected String id;
-       
-       public Variable(Component owner, String name,  String id) {
-               this.owner = owner;
-               this.name = name;
-               this.id = id;
-       }
-       
-       abstract void update();
-
-       public boolean isImmediate() {
-               return immediate;
-       }
-
-       public void setImmediate(boolean immediate) {
-               this.immediate = immediate;
-       }
-
-       public String getId() {
-               return id;
-       }
-
-       public void setId(String id) {
-               this.id = id;
-       }
-
-       public String getName() {
-               return name;
-       }
-
-       public void setName(String name) {
-               this.name = name;
-       }
-
-       public abstract String getEncodedValue();
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/VariableFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/VariableFactory.java
deleted file mode 100755 (executable)
index 6bfe74a..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client;
-
-import java.util.HashMap;
-
-import com.google.gwt.xml.client.NamedNodeMap;
-import com.google.gwt.xml.client.Node;
-import com.google.gwt.xml.client.NodeList;
-import com.itmill.toolkit.terminal.gwt.client.ui.Component;
-
-public class VariableFactory {
-       
-       public static Variable getVariable(Node n, Component owner) {
-               String nName = n.getNodeName();
-               NamedNodeMap attr = n.getAttributes();
-               if(nName.equals("boolean")) {
-                       String name = attr.getNamedItem("name").getNodeValue();
-                       String id = attr.getNamedItem("id").getNodeValue();     
-                       boolean b = attr.getNamedItem("value").getNodeValue().equals("true");
-                       BooleanVariable v = new BooleanVariable(owner,name,id);
-                       v.setValue(b);
-                       return v;
-               } else {
-                       return null;
-               }
-       }
-       
-       public static HashMap getAllVariables(Node n, Component owner) {
-               HashMap v = new HashMap();
-               NodeList children  = n.getChildNodes();
-               for (int i = 0; i < children.getLength(); i++) {
-                       Variable var = getVariable(children.item(i), owner);
-                       if(var != null)
-                               v.put(var.getName(), var);
-               }
-               return v;
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java
new file mode 100644 (file)
index 0000000..b39e470
--- /dev/null
@@ -0,0 +1,9 @@
+package com.itmill.toolkit.terminal.gwt.client;
+
+import com.google.gwt.user.client.ui.Widget;
+
+public interface WidgetFactory {
+
+       Widget createWidget(String tag, String theme);
+       
+}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Button.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Button.java
new file mode 100644 (file)
index 0000000..4443dc6
--- /dev/null
@@ -0,0 +1,16 @@
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+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 Button extends com.google.gwt.user.client.ui.Button implements Paintable {
+
+       String id;
+       
+       public void updateFromUIDL(UIDL uidl, Client client) {
+               id = uidl.getId();
+               setText(uidl.getStringAttribute("caption"));
+       }
+
+}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Component.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Component.java
deleted file mode 100755 (executable)
index 6b03baf..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.Node;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-public abstract class Component {
-       
-       private ContainerComponent parent;
-       protected Client client;
-       private final int id;
-       
-       public Component(int id, Client c) {
-               client = c;
-               this.id = id;
-       }
-
-       public abstract void updateFromUidl(Node n);
-
-       public abstract Widget getWidget(); 
-       
-       public static boolean isComponent(String nodeName) {
-               if(
-                               nodeName.equals("label") ||
-                               nodeName.equals("button") ||
-                               nodeName.equals("textfield") ||
-                               nodeName.equals("select") ||
-                               nodeName.equals("orderedlayout")
-               ) return true;
-               return false;
-       }
-
-       public static Component createComponent(Node uidl, Client cli) {
-               Component c = null;
-               String nodeName = uidl.getNodeName();
-               if(nodeName.equals("label")) {
-                       c = new TkLabel(uidl, cli);
-               } else if(nodeName.equals("orderedlayout")) {
-                       c = new TkOrderedLayout(uidl, cli);
-               } else if(nodeName.equals("button")) {
-                       c = new TkButton(uidl, cli);
-               } else if(nodeName.equals("textfield")) {
-                       c = new TkTextField(uidl, cli);
-               } else {
-                       c = new TkUnknown(uidl, cli);
-               }
-               return c;
-       }
-       
-       public void appendTo(ContainerComponent cont) {
-               this.parent = cont;
-               getClient().registerComponent(this);
-               cont.appendChild(this);
-       }
-       
-       public ContainerComponent getParent() {
-               return parent;
-       }
-       
-       public Client getClient() {
-               if(client == null)
-                       client = parent.getClient();
-               return client;
-       }
-       
-       public static int getIdFromUidl(Node uidl) {
-               Node pid = uidl.getAttributes().getNamedItem("id");
-               return Integer.parseInt(pid.getNodeValue().substring(3));
-       }
-
-       public int getId() {
-               return id;
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ContainerComponent.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ContainerComponent.java
deleted file mode 100755 (executable)
index 543c245..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.xml.client.Node;
-import com.google.gwt.xml.client.NodeList;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-abstract class ContainerComponent extends Component {
-
-       public ContainerComponent(int id, Client c) {
-               super(id, c);
-       }
-
-       abstract void appendChild(Component c);
-       
-       public void renderChildNodes(Node n, Client cli) {
-               NodeList children = n.getChildNodes();
-               for(int i = 0; i < children.getLength(); i++) {
-                       Node child = children.item(i);
-                       if(Component.isComponent(child.getNodeName())) {
-                               Component c = Component.createComponent(child, cli);
-                               c.appendTo(this);
-                       }
-               }
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Label.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Label.java
new file mode 100644 (file)
index 0000000..23008ab
--- /dev/null
@@ -0,0 +1,12 @@
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+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 Label extends com.google.gwt.user.client.ui.Label implements Paintable{
+
+       public void updateFromUIDL(UIDL uidl, Client client) {
+               setText(uidl.getChildString(0));
+       }
+}
index c38113d16528b7f0ce7d3c3bd1aea32187b397c8..7b8c7a328c608854bef1090082e8715e3e8f93f7 100644 (file)
@@ -12,6 +12,7 @@ public class OrderedLayout extends FlowPanel implements Paintable {
 
        public void updateFromUIDL(UIDL uidl, Client client) {
                clear();
+               if (uidl.hasAttribute("caption")) setTitle(uidl.getStringAttribute("caption")); 
                for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
                        UIDL uidlForChild = (UIDL)i.next();
                        Widget child = client.createWidgetFromUIDL(uidlForChild);
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/RootWindow.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/RootWindow.java
deleted file mode 100755 (executable)
index 101ec44..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-       
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.Node;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-public class RootWindow extends ContainerComponent {
-
-       private RootPanel rp;
-       private Client client;
-
-       public RootWindow(Node uidl, Client c) {
-               super(0,c);
-               // root panel must be attached to client before childs can be rendered
-               setClient(c);
-               rp = RootPanel.get("itmtk-ajax-window");
-               rp.clear();
-               renderChildNodes(uidl, client);
-       }
-       
-       void appendChild(Component c) {
-               rp.add(c.getWidget());
-       }
-
-       public void updateFromUidl(Node n) {
-               // TODO Auto-generated method stub
-
-       }
-
-       public Widget getWidget() {
-               return rp;
-       }
-
-       public void setClient(Client client) {
-               this.client = client;
-       }
-       
-       public Client getClient() {
-               return this.client;
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java
deleted file mode 100755 (executable)
index a436211..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.ClickListener;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.NamedNodeMap;
-import com.google.gwt.xml.client.Node;
-import com.google.gwt.xml.client.NodeList;
-import com.itmill.toolkit.terminal.gwt.client.BooleanVariable;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-import com.itmill.toolkit.terminal.gwt.client.VariableFactory;
-
-public class TkButton extends Component {
-
-       private Button b;
-       private BooleanVariable state;
-
-       public TkButton(Node uidl, Client c) {
-               super(getIdFromUidl(uidl), c);
-               b = new Button();
-               updateFromUidl(uidl);
-               b.addClickListener(new ButtonClickListener());
-       }
-
-       public void updateFromUidl(Node n) {
-               
-               String text = "";
-               String description = null;
-               NamedNodeMap attributes = n.getAttributes();
-               Node caption = attributes.getNamedItem("caption");
-               if(caption != null)
-                       text = caption.getNodeValue();
-
-               NodeList children = n.getChildNodes();
-               for (int i = 0; i < children.getLength(); i++) {
-                       Node child = children.item(i);
-                       String nName = child.getNodeName();
-                       if(nName.equals("description"))
-                               description  = child.getFirstChild().toString();
-                       if(nName.equals("boolean")) {
-                               state = (BooleanVariable) VariableFactory.getVariable(child,this);
-                               state.setImmediate(true); // button always immediate
-                       }
-               }
-               b.setText(text);
-               if(description != null)
-                       b.setTitle(description);
-       }
-
-       public Widget getWidget() {
-               return b;
-       }
-       
-       public class ButtonClickListener implements ClickListener {
-
-               public void onClick(Widget sender) {
-                       TkButton.this.state.setValue(true);
-                       TkButton.this.state.update();
-               }
-               
-       }
-       
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkLabel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkLabel.java
deleted file mode 100755 (executable)
index 1d41ce8..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.NamedNodeMap;
-import com.google.gwt.xml.client.Node;
-import com.google.gwt.xml.client.NodeList;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-public class TkLabel extends Component {
-
-       private Label l;
-
-       public TkLabel(Node uidl, Client cli) {
-               super(getIdFromUidl(uidl), cli);
-
-               l = new Label();
-               updateFromUidl(uidl);
-       }
-
-       public void updateFromUidl(Node n) {
-               NodeList children = n.getChildNodes();
-               String text = "";
-               String description = null;
-               for (int i = 0; i < children.getLength(); i++) {
-                       Node child = children.item(i);
-                       if(child.getNodeName().equals("description"))
-                               description  = child.getNodeValue();
-                       else if(child.getNodeType() == Node.TEXT_NODE)
-                               text  = child.toString();
-               }
-               NamedNodeMap attributes = n.getAttributes();
-               Node caption = attributes.getNamedItem("caption");
-               if(caption != null)
-                       text = caption.getNodeValue();
-               l.setText(text);
-               if(description != null)
-                       l.setTitle(description);
-       }
-
-       public Widget getWidget() {
-               return l;
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java
deleted file mode 100755 (executable)
index f7c590b..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.FlowPanel;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.Node;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-public class TkOrderedLayout extends ContainerComponent {
-       
-       private FlowPanel p;
-
-       public TkOrderedLayout(Node uidl, Client cli) {
-               super(getIdFromUidl(uidl), cli);
-
-               p = new FlowPanel();
-               updateFromUidl(uidl);
-       }
-
-       void appendChild(Component c) {
-               p.add(c.getWidget());
-       }
-
-       public Widget getWidget() {
-               return p;
-       }
-
-       public void updateFromUidl(Node n) {
-               p.clear();
-               renderChildNodes(n, getClient());
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkTextField.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkTextField.java
deleted file mode 100755 (executable)
index cec2e17..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.TextBox;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.NamedNodeMap;
-import com.google.gwt.xml.client.Node;
-import com.google.gwt.xml.client.NodeList;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-public class TkTextField extends Component {
-
-
-       private TextBox tb;
-
-       public TkTextField(Node uidl, Client cli) {
-               super(getIdFromUidl(uidl),cli);
-
-               tb = new TextBox();
-               updateFromUidl(uidl);
-       }
-
-       public void updateFromUidl(Node n) {
-               NodeList children = n.getChildNodes();
-               String text = "";
-               String description = null;
-               for (int i = 0; i < children.getLength(); i++) {
-                       Node child = children.item(i);
-                       if(child.getNodeName().equals("description"))
-                               description  = child.getNodeValue();
-                       else if(child.getNodeType() == Node.TEXT_NODE)
-                               text  = child.toString();
-               }
-               NamedNodeMap attributes = n.getAttributes();
-               Node caption = attributes.getNamedItem("caption");
-               if(caption != null)
-                       text = caption.getNodeValue();
-               tb.setText(text);
-               if(description != null)
-                       tb.setTitle(description);
-       }
-
-       public Widget getWidget() {
-               return tb;
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkUnknown.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkUnknown.java
deleted file mode 100755 (executable)
index 78d18e6..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.xml.client.Node;
-import com.itmill.toolkit.terminal.gwt.client.Client;
-
-public class TkUnknown extends Component {
-
-       private Label l;
-
-       public TkUnknown(Node uidl, Client cli) {
-               super(getIdFromUidl(uidl),cli);
-
-               l = new Label("No client side component found for " + uidl.getNodeName());
-       }
-
-       public void updateFromUidl(Node n) {
-       }
-
-       public Widget getWidget() {
-               return l;
-       }
-
-}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Window.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Window.java
new file mode 100644 (file)
index 0000000..b1d0a92
--- /dev/null
@@ -0,0 +1,28 @@
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import com.google.gwt.user.client.ui.DockPanel;
+import com.google.gwt.user.client.ui.Label;
+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 Window extends DockPanel implements Paintable {
+
+       String id;
+       Label caption = new Label();
+
+       public Window() {
+               super();
+               setBorderWidth(2);
+               add(caption,NORTH);
+       }
+       
+       public void updateFromUIDL(UIDL uidl, Client client) {
+
+               id = uidl.getId();
+               caption.setText(uidl.getStringAttribute("caption"));
+               UIDL child = uidl.getChildUIDL(0);
+               add(client.createWidgetFromUIDL(child),CENTER);
+       }
+
+}