]> source.dussan.org Git - vaadin-framework.git/commitdiff
Major revision to OrderedLayout to fix #1875 . Likely to cause regressions, do not...
authorJoonas Lehtinen <joonas.lehtinen@itmill.com>
Tue, 1 Jul 2008 20:44:01 +0000 (20:44 +0000)
committerJoonas Lehtinen <joonas.lehtinen@itmill.com>
Tue, 1 Jul 2008 20:44:01 +0000 (20:44 +0000)
svn changeset:5002/svn branch:trunk

WebContent/ITMILL/themes/default/button/button.css
WebContent/ITMILL/themes/default/caption/caption.css
WebContent/ITMILL/themes/default/styles.css
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/ui/IOrderedLayout.java

index 1b933bff05aeb71bfe88bd38edfe4046c9b0a9fb..cf9b4ae697528405b0afe9e7132cebe2d00a60b2 100644 (file)
        background:transparent;
        background-color: #FFE0E0;
 }
-*/
\ No newline at end of file
+*/
+
+.i-checkbox *, .i-button * {
+       float: left;
+}
+
+.i-checkbox:after, .i-button:after {
+       content: ".";
+       display: block;
+       height: 0;
+    clear: both;
+    visibility: hidden;
+}
+               
+.i-checkbox, .i-button {
+       display: inline-block;
+}
+
+/* Hides from IE-mac \*/
+* html .i-caption, * html .i-orderedlayout-wrap { height: 1%; }
+.i-caption, .i-orderedlayout-wrap { display: block; }
+/* End hide from IE-mac */
index 9ab7505c2b3e2667b6d55447fea3364b7f0e5877..627b79fc708ec666a21f4a1deeedebf94796ef04 100644 (file)
@@ -6,13 +6,38 @@
        text-align: left /* Force default alignment */
 }
 
+.i-caption * { 
+       float:left; 
+       display: block;
+}
+.i-orderedlayout-wrap-e {
+       float:left;     
+}
+       
+.i-caption:after, .i-orderedlayout-wrap:after {
+       content: ".";
+       display: block;
+       height: 0;
+    clear: both;
+    visibility: hidden;
+}
+               
+.i-caption, .i-orderedlayout-wrap {
+       display: inline-block;
+}
+
+/* Hides from IE-mac \*/
+* html .i-caption, * html .i-orderedlayout-wrap { height: 1%; }
+.i-caption, .i-orderedlayout-wrap { display: block; }
+/* End hide from IE-mac */
+
 .i-errorindicator {
-       width: 10px;
-       height: 16px;
-       padding-right:13px;
-       display: inline;
-       background: transparent url(../icons/16/error.png) no-repeat top right;
+       background:transparent url(../icons/16/error.png) no-repeat scroll right top;
+       height:16px;
+       width:10px;
+       margin-left: 3px;
 }
+
 * html .i-errorindicator {
        background: transparent none;
        /* gif for transparency */
index 0ad6b4849febceb38afcd4ec9c188815a9f5ec1f..ae3eac6632548be70333279e6f7a69b942400fc5 100644 (file)
        background-color: #FFE0E0;
 }
 */
+
+.i-checkbox *, .i-button * {
+       float: left;
+}
+
+.i-checkbox:after, .i-button:after {
+       content: ".";
+       display: block;
+       height: 0;
+    clear: both;
+    visibility: hidden;
+}
+               
+.i-checkbox, .i-button {
+       display: inline-block;
+}
+
+/* Hides from IE-mac \*/
+* html .i-caption, * html .i-orderedlayout-wrap { height: 1%; }
+.i-caption, .i-orderedlayout-wrap { display: block; }
+/* End hide from IE-mac */
 /* Provide some extra whitespace for wrapped elements
    (these elements usually need the extra space, since 
    they aren't even handling their own caption) */
        text-align: left /* Force default alignment */
 }
 
+.i-caption * { 
+       float:left; 
+       display: block;
+}
+.i-orderedlayout-wrap-e {
+       float:left;     
+}
+       
+.i-caption:after, .i-orderedlayout-wrap:after {
+       content: ".";
+       display: block;
+       height: 0;
+    clear: both;
+    visibility: hidden;
+}
+               
+.i-caption, .i-orderedlayout-wrap {
+       display: inline-block;
+}
+
+/* Hides from IE-mac \*/
+* html .i-caption, * html .i-orderedlayout-wrap { height: 1%; }
+.i-caption, .i-orderedlayout-wrap { display: block; }
+/* End hide from IE-mac */
+
 .i-errorindicator {
-       width: 10px;
-       height: 16px;
-       padding-right:13px;
-       display: inline;
-       background: transparent url(icons/16/error.png) no-repeat top right;
+       background:transparent url(icons/16/error.png) no-repeat scroll right top;
+       height:16px;
+       width:10px;
+       margin-left: 3px;
 }
+
 * html .i-errorindicator {
        background: transparent none;
        /* gif for transparency */
index a1afdf7c407d5c8840344adb8df9b41cde7cefa9..10313d289c77979e43778f917fddd7af93b40fc8 100755 (executable)
@@ -735,14 +735,6 @@ public class ApplicationConnection {
         // Visibility
         boolean visible = !uidl.getBooleanAttribute("invisible");
         component.setVisible(visible);
-        // Set captions
-        if (manageCaption) {
-            final Container parent = Util.getParentLayout(component);
-            if (parent != null) {
-                parent.updateCaption((Paintable) component, uidl);
-            }
-        }
-
         if (!visible) {
             return true;
         }
@@ -826,6 +818,14 @@ public class ApplicationConnection {
         // Styles + disabled & readonly
         component.setStyleName(styleBuf.toString());
 
+        // Set captions
+        if (manageCaption) {
+            final Container parent = Util.getParentLayout(component);
+            if (parent != null) {
+                parent.updateCaption((Paintable) component, uidl);
+            }
+        }
+
         if (usePaintableIdsInDOM) {
             DOM.setElementProperty(component.getElement(), "id", uidl.getId());
         }
index bab2b6e06c664b9629f5ba12d4055ef6ed6518c2..eec807edfabf3e04f9842bb0fe654ee319375934 100644 (file)
@@ -26,6 +26,8 @@ public class Caption extends HTML {
 
     private final ApplicationConnection client;
 
+    private boolean placedAfterComponent = false;
+
     /**
      * 
      * @param component
@@ -47,10 +49,12 @@ public class Caption extends HTML {
 
         boolean isEmpty = true;
 
+        placedAfterComponent = true;
+
         if (uidl.hasAttribute("icon")) {
             if (icon == null) {
                 icon = new Icon(client);
-
+                placedAfterComponent = false;
                 DOM.insertChild(getElement(), icon.getElement(), 0);
             }
             icon.setUri(uidl.getStringAttribute("icon"));
@@ -74,6 +78,7 @@ public class Caption extends HTML {
                 c = "";
             } else {
                 isEmpty = false;
+                placedAfterComponent = false;
             }
             DOM.setInnerText(captionText, c);
         } else {
@@ -169,4 +174,8 @@ public class Caption extends HTML {
     public Paintable getOwner() {
         return owner;
     }
+
+    public boolean shouldBePlacedAfterComponent() {
+        return placedAfterComponent;
+    }
 }
index 6720574bbcb6880bb35aec4788bc7a13d34f0ec3..3497ce479f2a2a943e5ca8a913d022380b99403f 100644 (file)
@@ -5,7 +5,6 @@
 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.DOM;
@@ -36,8 +35,6 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
 
     int orientationMode = ORIENTATION_VERTICAL;
 
-    protected HashMap componentToCaption = new HashMap();
-
     protected ApplicationConnection client;
 
     /**
@@ -103,12 +100,10 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
             uidlWidgets.add(child);
         }
 
-        final ArrayList oldWidgets = getPaintables();
-
+        final ArrayList oldWidgets = getChildrenAsArraylist();
         final Iterator oldIt = oldWidgets.iterator();
         final Iterator newIt = uidlWidgets.iterator();
         final Iterator newUidl = uidl.getChildIterator();
-
         final ArrayList paintedWidgets = new ArrayList();
 
         Widget oldChild = null;
@@ -143,25 +138,18 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
                 // oldChild
                 // TODO this might be optimized by moving only container element
                 // to correct position
-                removeCaption(child);
                 int index = getPaintableIndex(oldChild);
-                if (componentToCaption.containsKey(oldChild)) {
-                    index--;
-                }
                 remove(child);
                 this.insert(child, index);
             } else {
                 // insert new child before old one
                 final int index = getPaintableIndex(oldChild); // TODO this
-                // returns wrong
-                // value if
-                // captions are
-                // used
                 insert(child, index);
             }
             ((Paintable) child).updateFromUIDL(childUidl, client);
             paintedWidgets.add(child);
         }
+
         // remove possibly remaining old Paintable object which were not updated
         while (oldIt.hasNext()) {
             oldChild = (Widget) oldIt.next();
@@ -175,19 +163,11 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
         handleAlignments(uidl);
     }
 
-    /**
-     * Retuns a list of Paintables currently rendered in layout
-     * 
-     * @return list of Paintable objects
-     */
-    protected ArrayList getPaintables() {
+    private ArrayList getChildrenAsArraylist() {
         final ArrayList al = new ArrayList();
         final Iterator it = iterator();
         while (it.hasNext()) {
-            final Widget w = (Widget) it.next();
-            if (w instanceof Paintable) {
-                al.add(w);
-            }
+            al.add(it.next());
         }
         return al;
     }
@@ -200,12 +180,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
      * @param p
      *                Paintable to be removed
      */
-    public boolean removePaintable(Paintable p) {
-        final Caption c = (Caption) componentToCaption.get(p);
-        if (c != null) {
-            componentToCaption.remove(c);
-            remove(c);
-        }
+    protected boolean removePaintable(Paintable p) {
         client.unregisterPaintable(p);
         return remove((Widget) p);
     }
@@ -218,11 +193,6 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
      */
     public void replaceChildComponent(Widget from, Widget to) {
         client.unregisterPaintable((Paintable) from);
-        final Caption c = (Caption) componentToCaption.get(from);
-        if (c != null) {
-            remove(c);
-            componentToCaption.remove(c);
-        }
         final int index = getPaintableIndex(from);
         if (index >= 0) {
             remove(index);
@@ -231,20 +201,9 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
     }
 
     protected void insert(Widget w, int beforeIndex) {
-        if (w instanceof Caption) {
-            final Caption c = (Caption) w;
-            // captions go into same container element as their
-            // owners
-            final Element container = getWidgetWrapperFor((Widget) c.getOwner())
-                    .getContainerElement();
-            final Element captionContainer = DOM.createDiv();
-            DOM.insertChild(container, captionContainer, 0);
-            insert(w, captionContainer, beforeIndex, false);
-        } else {
-            WidgetWrapper wr = new WidgetWrapper();
-            DOM.insertChild(childContainer, wr.getElement(), beforeIndex);
-            insert(w, wr.getContainerElement(), beforeIndex, false);
-        }
+        WidgetWrapper wr = new WidgetWrapper();
+        DOM.insertChild(childContainer, wr.getElement(), beforeIndex);
+        insert(w, wr.getContainerElement(), beforeIndex, false);
     }
 
     public boolean hasChildComponent(Widget component) {
@@ -252,31 +211,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
     }
 
     public void updateCaption(Paintable component, UIDL uidl) {
-
-        Caption c = (Caption) componentToCaption.get(component);
-
-        if (Caption.isNeeded(uidl)) {
-            if (c == null) {
-                final int index = getPaintableIndex((Widget) component);
-                c = new Caption(component, client);
-                insert(c, index);
-                componentToCaption.put(component, c);
-            }
-            c.updateCaption(uidl);
-        } else {
-            if (c != null) {
-                remove(c);
-                componentToCaption.remove(component);
-            }
-        }
-    }
-
-    public void removeCaption(Widget w) {
-        final Caption c = (Caption) componentToCaption.get(w);
-        if (c != null) {
-            this.remove(c);
-            componentToCaption.remove(w);
-        }
+        getWidgetWrapperFor((Widget) component).updateCaption(uidl, component);
     }
 
     public void add(Widget w) {
@@ -293,9 +228,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
         final Element wrapper = getWidgetWrapperFor(w).getElement();
         final boolean removed = super.remove(w);
         if (removed) {
-            if (!(w instanceof Caption)) {
-                DOM.removeChild(childContainer, wrapper);
-            }
+            DOM.removeChild(childContainer, wrapper);
             return true;
         }
         return false;
@@ -317,9 +250,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
         int size = 0;
         for (Iterator it = getChildren().iterator(); it.hasNext();) {
             Widget w = (Widget) it.next();
-            if (!(w instanceof Caption)) {
-                size++;
-            }
+            size++;
         }
         return size;
     }
@@ -330,7 +261,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
             Widget w = (Widget) it.next();
             if (w == child) {
                 return i;
-            } else if (!(w instanceof Caption)) {
+            } else {
                 i++;
             }
         }
@@ -356,7 +287,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
         final int[] alignments = uidl.getIntArrayAttribute("alignments");
         int alignmentIndex = 0;
         // Insert alignment attributes
-        final Iterator it = getPaintables().iterator();
+        final Iterator it = getChildrenAsArraylist().iterator();
         boolean first = true;
         while (it.hasNext()) {
 
@@ -385,6 +316,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
     class WidgetWrapper extends UIObject {
 
         Element td;
+        Caption caption = null;
 
         public WidgetWrapper() {
             if (orientationMode == ORIENTATION_VERTICAL) {
@@ -397,6 +329,65 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
             } else {
                 setElement(DOM.createTD());
             }
+            // DOM.setElementAttribute(getElement(), "class",
+            // "i-orderedlayout-wrap");
+        }
+
+        public void updateCaption(UIDL uidl, Paintable paintable) {
+            if (Caption.isNeeded(uidl)) {
+                boolean justAdded = false;
+                if (caption == null) {
+                    justAdded = true;
+                    caption = new Caption(paintable, client);
+                }
+                caption.updateCaption(uidl);
+                final boolean after = caption.shouldBePlacedAfterComponent();
+                final Element captionElement = caption.getElement();
+                final Element firstElement = DOM.getFirstChild(getElement());
+                final Element widgetElement = firstElement == captionElement ? DOM
+                        .getChild(getElement(), 1)
+                        : firstElement;
+                String currentWidgetClass = DOM.getElementAttribute(
+                        widgetElement, "class");
+                if (null == currentWidgetClass) {
+                    currentWidgetClass = "";
+                }
+                if (justAdded) {
+                    if (after) {
+                        DOM.appendChild(getElement(), captionElement);
+                        DOM.setElementAttribute(getElement(), "class",
+                                "i-orderedlayout-wrap");
+                        DOM.setElementAttribute(widgetElement, "class",
+                                currentWidgetClass + " i-orderedlayout-wrap-e");
+                    } else {
+                        DOM.insertBefore(getElement(), captionElement,
+                                firstElement);
+                    }
+
+                } else
+                // Swap caption and widget if needed or add
+                if (caption.shouldBePlacedAfterComponent() == (firstElement == captionElement)) {
+                    DOM.removeChild(getElement(), firstElement);
+                    DOM.appendChild(getElement(), firstElement);
+                    DOM.setElementAttribute(getElement(), "class",
+                            after ? "i-orderedlayout-wrap" : "");
+                    if (after) {
+                        DOM.setElementAttribute(widgetElement, "class",
+                                currentWidgetClass + " i-orderedlayout-wrap-e");
+                    } else {
+                        // TODO remove unnecessary wrap-e
+                    }
+                }
+
+            } else {
+                if (caption != null) {
+                    DOM.removeChild(getElement(), caption.getElement());
+                    caption = null;
+                    DOM.setElementAttribute(getElement(), "class", "");
+
+                    // TODO Also remove wrap-e
+                }
+            }
         }
 
         public WidgetWrapper(Element element) {
@@ -494,7 +485,7 @@ public abstract class IOrderedLayout extends ComplexPanel implements Container {
      * @param child
      * @return
      */
-    public WidgetWrapper getWidgetWrapperFor(Widget child) {
+    protected WidgetWrapper getWidgetWrapperFor(Widget child) {
         final Element containerElement = DOM.getParent(child.getElement());
         return new WidgetWrapper(containerElement);
     }