]> source.dussan.org Git - vaadin-framework.git/commitdiff
GridLayout child rendering and some refactoring
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 9 Aug 2007 06:42:06 +0000 (06:42 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 9 Aug 2007 06:42:06 +0000 (06:42 +0000)
svn changeset:1970/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java
src/com/itmill/toolkit/terminal/gwt/client/Caption.java
src/com/itmill/toolkit/terminal/gwt/client/CaptionWrapper.java
src/com/itmill/toolkit/terminal/gwt/client/Layout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java

index 7919d20d613d4e726ec7d9e8f82afe6b1902102d..65543d895bfc6a64b9ce14f3dc5f5dbc927fac8b 100755 (executable)
@@ -335,7 +335,7 @@ public class ApplicationConnection implements EntryPoint, FocusListener {
                if (manageCaption) {
                        Layout parent = getParentLayout(component);
                        if (parent != null)
-                               parent.updateCaption(component, uidl);
+                               parent.updateCaption((Paintable) component, uidl);
                }
 
                // Visibility, Disabling and read-only status
index e73f94603e3f8e332b880c67963efaea4682a47e..b3ba8edc9d85d660d8e90d5765bf47be13db48ac 100644 (file)
@@ -7,9 +7,9 @@ import com.google.gwt.user.client.ui.Widget;
 
 public class Caption extends HTML {
        
-       private Widget owner;
+       private Paintable owner;
 
-       public Caption(Widget component)  {
+       public Caption(Paintable component)  {
                owner = component;
                setStyleName("i-caption");
        }
@@ -31,12 +31,12 @@ public class Caption extends HTML {
        }
        
        /**
-        * Returns Widget (most likely Paintable) for which this Caption
+        * Returns Paintable for which this Caption
         * belongs to.
         * 
         * @return owner Widget
         */
-       public Widget getOwner() {
+       public Paintable getOwner() {
                return owner;
        }
 }
index 8b4cb683a5bf449c08a25e971788238d94de8e1c..dd073998541d81456a51cf146c5a1f98c1381d5c 100644 (file)
@@ -1,38 +1,30 @@
 package com.itmill.toolkit.terminal.gwt.client;
 
+import com.google.gwt.user.client.ui.FlowPanel;
 import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
-public class CaptionWrapper extends VerticalPanel {
+public class CaptionWrapper extends FlowPanel {
 
-       Label caption;
-       Widget widget; 
+       Label caption = new Label();
+       Paintable widget; 
        
-       public CaptionWrapper(Widget toBeWrapped) {
+       public CaptionWrapper(Paintable toBeWrapped) {
+               add(caption);
                widget = toBeWrapped;
-               add(widget);
+               add((Widget) widget);
        }
        
        public void updateCaption(UIDL uidl) {
                String c = uidl.getStringAttribute("caption");
                // TODO Description and error messages
-               if (c == null) {
-                       if (caption == null) return;
-                       remove(caption);
-                       caption = null;
-               } else {
-                       if (caption == null) {
-                               caption = new Label(c);
-                               insert(caption, 0);
-                       }
-                       else 
-                               caption.setText(c);
-               }               
+               if (c != null) {
+                       caption.setText(c);
+               }
                setVisible(!uidl.getBooleanAttribute("invisible"));
        }
        
-       public Widget getWidget() {
+       public Paintable getPaintable() {
                return widget;
        }
 }
index cc91fb7c4f45145be3a55a5eb307ce2940232011..4c302726a255aff1e3cc0f8136a0f45c223cd64d 100644 (file)
@@ -43,6 +43,6 @@ public interface Layout extends Paintable {
         * @param uidl
         *            UIDL of the child component.
         */
-       void updateCaption(Widget component, UIDL uidl);
+       void updateCaption(Paintable component, UIDL uidl);
        
 }
index 54cf26cfc5c1c28af7548292f45fee1c97fd3917..f90b11b5166b1d7a4bbc6e8596d66abac8ab84d3 100644 (file)
@@ -266,12 +266,12 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
        }
 
        /** Update caption for given widget */
-       public void updateCaption(Widget component, UIDL uidl) {
+       public void updateCaption(Paintable component, UIDL uidl) {
                CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper.get(component);
                if (Caption.isNeeded(uidl)) {
                        if (wrapper == null) {
-                               String loc = getLocation(component);
-                               super.remove(component);
+                               String loc = getLocation((Widget) component);
+                               super.remove((Widget) component);
                                wrapper = new CaptionWrapper(component);
                                super.add(wrapper, (Element) locationToElement.get(loc));
                                widgetToCaptionWrapper.put(component, wrapper);
@@ -279,9 +279,9 @@ public class ICustomLayout extends ComplexPanel implements Paintable, Layout {
                        wrapper.updateCaption(uidl);
                } else {
                        if (wrapper != null) { 
-                               String loc = getLocation(component);
+                               String loc = getLocation((Widget) component);
                                super.remove(wrapper);
-                               super.add(wrapper.getWidget(), (Element) locationToElement.get(loc));
+                               super.add((Widget) wrapper.getPaintable(), (Element) locationToElement.get(loc));
                                widgetToCaptionWrapper.remove(component);
                        }
                }
index 260270438ca41b014624c48ea87e2a9fca410b14..7cf0c64fb03954aed65d8d23ffff007bd9cbbb95 100644 (file)
@@ -1,20 +1,31 @@
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 
 import com.google.gwt.user.client.ui.FlexTable;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.CaptionWrapper;
+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 IGridLayout extends FlexTable implements Paintable {
+public class IGridLayout extends FlexTable implements Paintable, Layout {
+       
+       /** Widget to captionwrapper map */
+       private HashMap widgetToCaptionWrapper = new HashMap();
+
 
        public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
                clear();
                if (uidl.hasAttribute("caption"))
                        setTitle(uidl.getStringAttribute("caption"));
                int row = 0, column = 0;
+
+               ArrayList detachdedPaintables = new ArrayList();
+               
                for (Iterator i = uidl.getChildIterator(); i.hasNext();) {
                        UIDL r = (UIDL) i.next();
                        if ("gr".equals(r.getTag())) {
@@ -32,13 +43,48 @@ public class IGridLayout extends FlexTable implements Paintable {
                                                UIDL u = c.getChildUIDL(0);
                                                if (u != null) {
                                                        Widget child = client.getWidget(u);
-                                                       setWidget(row, column, child);
+                                                       prepareCell(row, column);
+                                                       Widget oldChild = getWidget(row, column);
+                                                       if(child != oldChild) {
+                                                               if(oldChild != null) {
+                                                                       CaptionWrapper cw = (CaptionWrapper) oldChild;
+                                                                       detachdedPaintables.add(cw.getPaintable());
+                                                                       widgetToCaptionWrapper.remove(oldChild);
+                                                               }
+                                                               CaptionWrapper wrapper = new CaptionWrapper((Paintable) child);
+                                                               setWidget(row, column, wrapper);
+                                                               widgetToCaptionWrapper.put(child, wrapper);
+                                                       }
                                                        ((Paintable) child).updateFromUIDL(u, client);
                                                }
                                        }
                                }
                        }
                }
+               
+               // for loop detached widgets and unregister them unless they are
+               // attached (case of widget which is moved to another cell)
+               for(Iterator it = detachdedPaintables.iterator();it.hasNext();) {
+                       Widget w = (Widget) it.next();
+                       if(!w.isAttached())
+                               client.unregisterPaintable((Paintable) w);
+               }
+       }
+
+       public boolean hasChildComponent(Widget component) {
+               if(widgetToCaptionWrapper.containsKey(component))
+                       return true;
+               return false;
+       }
+
+       public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       public void updateCaption(Paintable component, UIDL uidl) {
+               CaptionWrapper wrapper = (CaptionWrapper) widgetToCaptionWrapper.get(component);
+               wrapper.updateCaption(uidl);
        }
 
 }
index 72e785a245fe9e94f531ce18391786c1e5b9cf45..f3b0f2bb635312d6c023bae9f113dde6a72c398d 100644 (file)
@@ -7,6 +7,7 @@ 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.ComplexPanel;
+import com.google.gwt.user.client.ui.UIObject;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
 import com.itmill.toolkit.terminal.gwt.client.Caption;
@@ -15,8 +16,7 @@ import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
 
 /**
- * @author mattitahvonen
- *
+ * @author IT Mill Ltd
  */
 public class IOrderedLayout extends ComplexPanel implements Paintable, Layout {
        
@@ -188,7 +188,7 @@ public class IOrderedLayout extends ComplexPanel implements Paintable, Layout {
                        Caption c = (Caption) w;
                        // captions go into same container element as their
                        // owners
-                       Element container = DOM.getParent(c.getOwner().getElement());
+                       Element container = DOM.getParent(((UIObject) c.getOwner()).getElement());
                        DOM.insertChild(container, w.getElement(), 0);
                        insert(w, null, beforeIndex);
                } else {
@@ -215,13 +215,13 @@ public class IOrderedLayout extends ComplexPanel implements Paintable, Layout {
                return getWidgetIndex(component) >= 0;
        }
 
-       public void updateCaption(Widget component, UIDL uidl) {
+       public void updateCaption(Paintable component, UIDL uidl) {
                
                Caption c  = (Caption) componentToCaption.get(component);
                
                if (Caption.isNeeded(uidl)) {
                        if (c == null) {
-                               int index = getWidgetIndex(component);
+                               int index = getWidgetIndex((Widget) component);
                                c = new Caption(component);
                                insert(c, index);
                                componentToCaption.put(component, c);