From abe653cbbace5c7aee28324c2b5f641f4c93872b Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Fri, 15 Jun 2007 06:07:08 +0000 Subject: [PATCH] Added stug for customlayout svn changeset:1739/svn branch:trunk --- .../gwt/client/DefaultWidgetFactory.java | 3 + .../terminal/gwt/client/ui/ICustomLayout.java | 93 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java b/src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java index e893e285e0..ee4a009b3e 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.core.client.GWT; import com.google.gwt.user.client.ui.Widget; +import com.itmill.toolkit.terminal.gwt.client.ui.ICustomLayout; import com.itmill.toolkit.terminal.gwt.client.ui.IPasswordField; import com.itmill.toolkit.terminal.gwt.client.ui.IButton; import com.itmill.toolkit.terminal.gwt.client.ui.ICheckBox; @@ -53,6 +54,8 @@ public class DefaultWidgetFactory implements WidgetFactory { return new ITabsheet(); if ("embedded".equals(tag)) return new IEmbedded(); + if ("customlayout".equals(tag)) + return new ICustomLayout(); if ("textfield".equals(tag)) { if(uidl.hasAttribute("multiline")) return new ITextArea(); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java new file mode 100644 index 0000000000..b650d07e46 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java @@ -0,0 +1,93 @@ +package com.itmill.toolkit.terminal.gwt.client.ui; + +import java.util.HashMap; +import java.util.Iterator; + +import com.google.gwt.user.client.ui.HTMLPanel; +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.itmill.toolkit.terminal.gwt.client.CaptionWrapper; +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 ICustomLayout extends SimplePanel implements Paintable, Layout { + + private HashMap componentToWrapper = new HashMap(); + HTMLPanel html; + private static HashMap styleToTemplate = new HashMap(); + String currentStyle; + + 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); + } + + 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); + } + } + + public void replaceChildComponent(Widget from, Widget to) { + CaptionWrapper wrapper = (CaptionWrapper) componentToWrapper.get(from); + if (wrapper != null) { + componentToWrapper.remove(from); + from = wrapper; + } + // TODO + html.remove(from); + html.add(to); + + } + + public boolean hasChildComponent(Widget component) { + // TODO + return componentToWrapper.get(component) != null; + } + + public void updateCaption(Widget component, UIDL uidl) { + // TODO + /* + CaptionWrapper wrapper = (CaptionWrapper) componentToWrapper.get(component); + if (CaptionWrapper.isNeeded(uidl)) { + if (wrapper == null) { + int index = getWidgetIndex(component); + remove(component); + wrapper = new CaptionWrapper(component); + insert(wrapper, index); + componentToWrapper.put(component, wrapper); + } + wrapper.updateCaption(uidl); + } else { + if (wrapper != null) { + int index = getWidgetIndex(wrapper); + remove(wrapper); + insert(wrapper.getWidget(), index); + componentToWrapper.remove(component); + } + } + */ + } + + + +} -- 2.39.5