]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added stug for customlayout
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 15 Jun 2007 06:07:08 +0000 (06:07 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Fri, 15 Jun 2007 06:07:08 +0000 (06:07 +0000)
svn changeset:1739/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/DefaultWidgetFactory.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java [new file with mode: 0644]

index e893e285e0f0e47c37a101c337087895fe204783..ee4a009b3e2edfd59c51689c4b5b4f9f19f8b36c 100644 (file)
@@ -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 (file)
index 0000000..b650d07
--- /dev/null
@@ -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 + " <div location=\"one\"></div>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);
+                       }
+               }
+               */
+       }
+       
+       
+
+}