+++ /dev/null
-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" );
- }
-
-}
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;
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 {
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.
*/
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 {
});
} catch (RequestException e1) {
- // TODO Auto-generated catch block
e1.printStackTrace();
}
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");
}
}
- 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;
}
}
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);
-// }-*/;
-
}
--- /dev/null
+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;
+ }
+
+}
}
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() {
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() {
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;
}
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";
+++ /dev/null
-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();
-
-}
+++ /dev/null
-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;
- }
-
-}
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client;
+
+import com.google.gwt.user.client.ui.Widget;
+
+public interface WidgetFactory {
+
+ Widget createWidget(String tag, String theme);
+
+}
--- /dev/null
+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"));
+ }
+
+}
+++ /dev/null
-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;
- }
-
-}
+++ /dev/null
-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);
- }
- }
- }
-
-}
--- /dev/null
+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));
+ }
+}
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);
+++ /dev/null
-
-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;
- }
-
-}
+++ /dev/null
-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();
- }
-
- }
-
-}
+++ /dev/null
-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;
- }
-
-}
+++ /dev/null
-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());
- }
-
-}
+++ /dev/null
-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;
- }
-
-}
+++ /dev/null
-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;
- }
-
-}
--- /dev/null
+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);
+ }
+
+}