From: Joonas Lehtinen Date: Fri, 15 Jun 2007 06:51:13 +0000 (+0000) Subject: Customlayout works X-Git-Tag: 6.7.0.beta1~6243 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a42ca8a62907cf00fe2d9b6c6bf82122b03b4979;p=vaadin-framework.git Customlayout works svn changeset:1742/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/Client.java b/src/com/itmill/toolkit/terminal/gwt/client/Client.java index 174b4797f9..1cc34dad2e 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/Client.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/Client.java @@ -2,6 +2,7 @@ package com.itmill.toolkit.terminal.gwt.client; import java.util.Date; import java.util.HashMap; +import java.util.Iterator; import java.util.Vector; import com.google.gwt.core.client.EntryPoint; @@ -13,6 +14,7 @@ import com.google.gwt.http.client.Response; 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.JSONString; import com.google.gwt.json.client.JSONValue; import com.google.gwt.user.client.ui.FocusWidget; import com.google.gwt.user.client.ui.RootPanel; @@ -27,6 +29,8 @@ public class Client implements EntryPoint { private String appUri; + private HashMap resourcesMap = new HashMap(); + // TODO remove repaintAll until things start to pile up private RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, appUri + "/UIDL/?repaintAll=1&"); @@ -109,6 +113,14 @@ public class Client implements EntryPoint { console.log(jsonText); return; } + // Store resources + JSONObject resources = (JSONObject) ((JSONObject) json) + .get("resources"); + for (Iterator i = resources.keySet().iterator(); i.hasNext();) { + String key = (String) i.next(); + resourcesMap.put(key, ((JSONString)resources.get(key)).stringValue()); + } + // Process changes JSONArray changes = (JSONArray) ((JSONObject) json).get("changes"); for (int i = 0; i < changes.size(); i++) { @@ -302,9 +314,9 @@ public class Client implements EntryPoint { // Visibility, Disabling and read-only status if (component instanceof FocusWidget) { boolean enabled = true; - if(uidl.hasAttribute("disabled")) + if (uidl.hasAttribute("disabled")) enabled = !uidl.getBooleanAttribute("disabled"); - else if(uidl.hasAttribute("readonly")) + else if (uidl.hasAttribute("readonly")) enabled = !uidl.getBooleanAttribute("readonly"); ((FocusWidget) component).setEnabled(enabled); } @@ -336,5 +348,9 @@ public class Client implements EntryPoint { registerPaintable(id, (Paintable) w); return w; } + + public String getResource(String name) { + return (String) resourcesMap.get(name); + } } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java index b650d07e46..769733645e 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java @@ -3,6 +3,8 @@ package com.itmill.toolkit.terminal.gwt.client.ui; import java.util.HashMap; import java.util.Iterator; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.VerticalPanel; @@ -17,36 +19,54 @@ public class ICustomLayout extends SimplePanel implements Paintable, Layout { private HashMap componentToWrapper = new HashMap(); HTMLPanel html; - private static HashMap styleToTemplate = new HashMap(); String currentStyle; + String locationPrefix = HTMLPanel.createUniqueId() + "_"; public void updateFromUIDL(UIDL uidl, Client client) { if (client.updateComponent(this, uidl, false)) return; - // Initialize HTMLPanel when needed - String newStyle = uidl.getStringAttribute("style"); - if (currentStyle == null || !currentStyle.equals(newStyle)) { - String template = (String) styleToTemplate.get(newStyle); - if (template == null) { - template = "custom layout of style " + newStyle + "
foobar"; - styleToTemplate.put(newStyle, template); - } - html = new HTMLPanel(template); - // TODO Map locations - add(html); - } + updateHTML(uidl, client); componentToWrapper.clear(); for (Iterator i = uidl.getChildIterator(); i.hasNext();) { UIDL uidlForChild = (UIDL) i.next(); - Widget child = client.getWidget(uidlForChild); - //html.add(child); - ((Paintable)child).updateFromUIDL(uidlForChild, client); + if (uidlForChild.getTag().equals("location")) { + String location = uidlForChild.getStringAttribute("name"); + Widget child = client.getWidget(uidlForChild.getChildUIDL(0)); + html.add(child,locationPrefix + location); + ((Paintable)child).updateFromUIDL(uidlForChild.getChildUIDL(0), client); + + } } } + private void updateHTML(UIDL uidl, Client client) { + String newStyle = uidl.getStringAttribute("style"); + if (currentStyle != null && currentStyle.equals(newStyle)) return; + + String template = client.getResource("layout/"+newStyle+".html"); + if (template == null) { + template = "Layout " + newStyle + " is missing"; + } else { + currentStyle = newStyle; + } + html = new HTMLPanel(template); + add(html); + + addUniqueIdsForLocations(html.getElement(), locationPrefix); + } + + private native void addUniqueIdsForLocations(Element e, String idPrefix) /*-{ + var divs = e.getElementsByTagName("div"); + for (var i = 0; i < divs.length; i++) { + var div = divs[i]; + var location = div.getAttribute("location"); + if (location != null) div.setAttribute("id",idPrefix + location); + } + }-*/; + public void replaceChildComponent(Widget from, Widget to) { CaptionWrapper wrapper = (CaptionWrapper) componentToWrapper.get(from); if (wrapper != null) {