aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>2007-06-13 17:16:55 +0000
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>2007-06-13 17:16:55 +0000
commite09ad7b1c2c5c5ec91e4127c10f5164fba7437a0 (patch)
treeeb09fb7bae33e9fc67144ee2028216813ac6e955
parentb2f4bb7a485161b187419cd3f18d7e038aeed20e (diff)
downloadvaadin-framework-e09ad7b1c2c5c5ec91e4127c10f5164fba7437a0.tar.gz
vaadin-framework-e09ad7b1c2c5c5ec91e4127c10f5164fba7437a0.zip
Preliminary Layout-interface, Included support for replacing widgets in layouts, Getting more of FeatureBrowser t work, Checkbox widget
svn changeset:1704/svn branch:trunk
-rwxr-xr-xsrc/com/itmill/toolkit/terminal/gwt/client/Client.java20
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java10
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/UIDL.java15
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java2
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java8
-rw-r--r--src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java45
6 files changed, 73 insertions, 27 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Client.java b/src/com/itmill/toolkit/terminal/gwt/client/Client.java
index 55b7f86a41..d5102b47cc 100755
--- a/src/com/itmill/toolkit/terminal/gwt/client/Client.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/Client.java
@@ -16,6 +16,7 @@ import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
+import com.itmill.toolkit.terminal.gwt.client.ui.TkButton;
/**
* Entry point classes define <code>onModuleLoad()</code>.
@@ -101,10 +102,8 @@ public class Client implements EntryPoint {
private void handleReceivedJSONMessage(Response response) {
Date start = new Date();
-
- System.out.println(response.getText().substring(3) + "}");
- JSONValue json = JSONParser
- .parse(response.getText().substring(3) + "}");
+ String jsonText = response.getText().substring(3) + "}";
+ JSONValue json = JSONParser.parse(jsonText);
// Process changes
JSONArray changes = (JSONArray) ((JSONObject) json).get("changes");
for (int i = 0; i < changes.size(); i++) {
@@ -138,7 +137,7 @@ public class Client implements EntryPoint {
}
long prosessingTime = (new Date().getTime()) - start.getTime();
- console.log(" Processing time was " + String.valueOf(prosessingTime));
+ console.log(" Processing time was " + String.valueOf(prosessingTime) + "ms for "+jsonText.length()+" characters of JSON");
}
@@ -151,7 +150,7 @@ public class Client implements EntryPoint {
}
public Widget createWidgetFromUIDL(UIDL uidlForChild) {
- Widget w = widgetFactory.createWidget(uidlForChild.getTag(), null);
+ Widget w = widgetFactory.createWidget(uidlForChild, null);
if (w instanceof Paintable) {
registerPaintable(uidlForChild.getId(), (Paintable) w);
((Paintable)w).updateFromUIDL(uidlForChild, this);
@@ -228,5 +227,14 @@ public class Client implements EntryPoint {
this.widgetFactory = widgetFactory;
}
+ public void repaintComponent(Widget component, UIDL uidl) {
+ Widget parent = component.getParent();
+ while (parent != null && !(parent instanceof Layout)) parent = parent.getParent();
+ if (parent != null && ((Layout)parent).hasChildComponent(component)) {
+ ((Layout) parent).replaceChildComponent(component,createWidgetFromUIDL(uidl));
+ }
+
+ }
+
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java
index f80b3bd00a..74b149b8ce 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java
@@ -2,6 +2,7 @@ package com.itmill.toolkit.terminal.gwt.client;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.terminal.gwt.client.ui.TkButton;
+import com.itmill.toolkit.terminal.gwt.client.ui.TkCheckBox;
import com.itmill.toolkit.terminal.gwt.client.ui.TkEmbedded;
import com.itmill.toolkit.terminal.gwt.client.ui.TkGridLayout;
import com.itmill.toolkit.terminal.gwt.client.ui.TkLabel;
@@ -17,10 +18,15 @@ import com.itmill.toolkit.terminal.gwt.client.ui.TkWindow;
public class DefaultWidgetFactory implements WidgetFactory {
- public Widget createWidget(String tag, String theme) {
+ public Widget createWidget(UIDL uidl, String theme) {
- if ("button".equals(tag))
+ String tag = uidl.getTag();
+
+ if ("button".equals(tag)){
+ if ("switch".equals(uidl.getStringAttribute("type")))
+ return new TkCheckBox();
return new TkButton();
+ }
if ("window".equals(tag))
return new TkWindow();
if ("orderedlayout".equals(tag))
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java b/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java
index 6f2299965d..4c50eabd02 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/UIDL.java
@@ -36,7 +36,7 @@ public class UIDL {
public String getStringAttribute(String name) {
JSONValue val = ((JSONObject) json.get(1)).get(name);
if (val == null)
- return "";
+ return null;
return ((JSONString) val).stringValue();
}
@@ -136,6 +136,10 @@ public class UIDL {
};
}
+
+ public int getNumberOfChildren() {
+ return json.size() - 2;
+ }
public String toString() {
String s = "<" + getTag();
@@ -164,14 +168,12 @@ public class UIDL {
private class UIDLBrowser extends Tree {
public UIDLBrowser() {
- final TreeItem root = new TreeItem("Click here to explore UIDL");
+ final TreeItem root = new TreeItem(getTag());
addItem(root);
+ root.addItem("");
addTreeListener(new TreeListener() {
public void onTreeItemStateChanged(TreeItem item) {
- }
-
- public void onTreeItemSelected(TreeItem item) {
if (item == root) {
removeItem(root);
UIDLBrowser.this.removeTreeListener(this);
@@ -182,6 +184,9 @@ public class UIDL {
}
}
+ public void onTreeItemSelected(TreeItem item) {
+ }
+
});
}
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java
index b39e470221..a9f52525fa 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/WidgetFactory.java
@@ -4,6 +4,6 @@ import com.google.gwt.user.client.ui.Widget;
public interface WidgetFactory {
- Widget createWidget(String tag, String theme);
+ Widget createWidget(UIDL uidl, String theme);
}
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java
index 4cf2946ad0..187b29f093 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkButton.java
@@ -18,6 +18,14 @@ public class TkButton extends com.google.gwt.user.client.ui.Button implements
}
public void updateFromUIDL(UIDL uidl, Client client) {
+ if (uidl.getStringAttribute("type") != null) {
+ if (this.client != null)
+ client.repaintComponent(this, uidl);
+ else
+ throw new IllegalStateException(
+ "Can not paint button of type: "
+ + uidl.getStringAttribute("type"));
+ }
this.client = client;
id = uidl.getId();
setText(uidl.getStringAttribute("caption"));
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java
index 419ad0a8be..876baee612 100644
--- a/src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java
+++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/TkOrderedLayout.java
@@ -2,41 +2,60 @@ package com.itmill.toolkit.terminal.gwt.client.ui;
import java.util.Iterator;
+import com.google.gwt.user.client.ui.CellPanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.IndexedPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.WidgetCollection;
import com.itmill.toolkit.terminal.gwt.client.Client;
+import com.itmill.toolkit.terminal.gwt.client.Layout;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
-public class TkOrderedLayout extends Composite implements Paintable {
-
+public class TkOrderedLayout extends Composite implements Paintable, Layout {
+
SimplePanel container = new SimplePanel();
-
- Panel panel;
-
+
+ IndexedPanel panel;
+
public TkOrderedLayout() {
initWidget(container);
}
public void updateFromUIDL(UIDL uidl, Client client) {
container.clear();
-
- if(uidl.getStringAttribute("orientation").equals("horizontal"))
+
+ if ("horizontal".equals(uidl.getStringAttribute("orientation")))
panel = new HorizontalPanel();
else
panel = new VerticalPanel();
-
- container.add(panel);
-
+
+ container.add((Panel) panel);
+
for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
- UIDL uidlForChild = (UIDL)i.next();
+ UIDL uidlForChild = (UIDL) i.next();
Widget child = client.createWidgetFromUIDL(uidlForChild);
- panel.add(child);
+ ((Panel) panel).add(child);
}
}
-
+
+ public void replaceChildComponent(Widget from, Widget to) {
+ int index = panel.getWidgetIndex(from);
+ if (index >= 0) {
+ panel.remove(index);
+ if (panel instanceof HorizontalPanel)
+ ((HorizontalPanel) panel).insert(to, index);
+ else
+ ((VerticalPanel) panel).insert(to, index);
+ }
+ }
+
+ public boolean hasChildComponent(Widget paintable) {
+ return panel.getWidgetIndex(paintable) >= 0;
+ }
+
}