]> source.dussan.org Git - vaadin-framework.git/commitdiff
caption and icon setters to Paintable interface, major tabsheet refactoring, client...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Mon, 11 Aug 2008 07:58:18 +0000 (07:58 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Mon, 11 Aug 2008 07:58:18 +0000 (07:58 +0000)
svn changeset:5161/svn branch:trunk

15 files changed:
WebContent/ITMILL/themes/default/styles.css
WebContent/ITMILL/themes/default/tabsheet/tabsheet.css
src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IForm.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IGridLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheet.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheetBase.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ITabsheetPanel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/absolutegrid/ISizeableGridLayout.java
src/com/itmill/toolkit/ui/Component.java
src/com/itmill/toolkit/ui/TabSheet.java

index c7a31d2d2ca70f64ee250590110f4015913a86c0..0df47105650aa4cb14a9068d40efcb48934b8363 100644 (file)
@@ -1852,16 +1852,29 @@ i-orderedlayout-margin-top {
        text-align: left /* Force default alignment */
 }
 
-
 .i-tabsheet-tabs {
        empty-cells: hide;
        border-collapse: collapse;
+       margin:0;
+       padding:0;
+       border:0;
        height: 38px;
        background: transparent url(tabsheet/img/tabs-bg.png) repeat-x bottom left;
        width: 100%;
        overflow:hidden;
 }
 
+.i-tabsheet-tabs td {
+       margin:0;
+       padding:0;
+}
+
+.i-tabsheet-tabs .i-tabsheet-spacertd {
+       width: 100%;
+       height: 37px;
+       border: 1px solid #b6bbbc;
+}
+
 .i-tabsheet-hidetabs .i-tabsheet-tabcontainer {
        display: none;
 }
@@ -1919,17 +1932,7 @@ i-orderedlayout-margin-top {
        white-space: nowrap;
 }
 
-.i-tabsheet-tabs .gwt-TabBarFirst {
-       display: none;
-}
-
-.i-tabsheet-tabs .gwt-TabBarRest {
-       border: 1px solid #b6bbbc;
-       background: #f8f9f9 url(tabsheet/img/tab-bg.png);
-       height: 37px;
-}
-
-.i-tabsheet-tabs .gwt-TabBarItem {
+.i-tabsheet-tabs .i-tabsheet-tabitem {
        border: 1px solid #b6bbbc;
        border-right: none;
        height: 20px;
@@ -1942,7 +1945,7 @@ i-orderedlayout-margin-top {
        cursor: pointer;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem-selected {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected {
        border: none;
        background: transparent url(panel/img/top-left.png) no-repeat;
        margin: 0;
@@ -1952,15 +1955,15 @@ i-orderedlayout-margin-top {
        color: #ee5311;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem:hover {
        color: #4b5257;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem-selected:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected:hover {
        color: #ee5311;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
        background: transparent url(panel/img/top-right.png) repeat-x right top;
        margin: 0 -1px 0 9px;
        height: 18px;
@@ -1997,7 +2000,7 @@ i-orderedlayout-margin-top {
 
 /* Progress indication */
 
-.i-tabsheet-loading .i-tabsheet-tabs .gwt-TabBarItem-selected span{
+.i-tabsheet-loading .i-tabsheet-tabs .i-tabsheet-tabitem-selected span{
        background: transparent url(common/img/ajax-loader.gif) no-repeat;
        display: block;
        margin-left: -10px;
@@ -2023,7 +2026,7 @@ i-orderedlayout-margin-top {
        height: 46px;
 }
 
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
        border: 1px solid #babfc0;
        border-bottom: none;
        background: #fff;
@@ -2033,7 +2036,7 @@ i-orderedlayout-margin-top {
        cursor: default;
        color: #ee5311;
 }
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
        border: 1px solid #babfc0;
        border-bottom: none;
        background: #fff;
@@ -2044,12 +2047,12 @@ i-orderedlayout-margin-top {
        color: #ee5311;
 }
 
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
        background: transparent;
        padding: 0;
        margin: 0;
 }
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
        background: transparent;
        padding: 0;
        margin: 0;
index c9194476ffb2aa4082e89207486b0d519fdd3eee..9be11e7dca4f41cad00941e90e4e0d71cb93019a 100644 (file)
@@ -5,16 +5,29 @@
        text-align: left /* Force default alignment */
 }
 
-
 .i-tabsheet-tabs {
        empty-cells: hide;
        border-collapse: collapse;
+       margin:0;
+       padding:0;
+       border:0;
        height: 38px;
        background: transparent url(img/tabs-bg.png) repeat-x bottom left;
        width: 100%;
        overflow:hidden;
 }
 
+.i-tabsheet-tabs td {
+       margin:0;
+       padding:0;
+}
+
+.i-tabsheet-tabs .i-tabsheet-spacertd {
+       width: 100%;
+       height: 37px;
+       border: 1px solid #b6bbbc;
+}
+
 .i-tabsheet-hidetabs .i-tabsheet-tabcontainer {
        display: none;
 }
        white-space: nowrap;
 }
 
-.i-tabsheet-tabs .gwt-TabBarFirst {
-       display: none;
-}
-
-.i-tabsheet-tabs .gwt-TabBarRest {
-       border: 1px solid #b6bbbc;
-       background: #f8f9f9 url(img/tab-bg.png);
-       height: 37px;
-}
-
-.i-tabsheet-tabs .gwt-TabBarItem {
+.i-tabsheet-tabs .i-tabsheet-tabitem {
        border: 1px solid #b6bbbc;
        border-right: none;
        height: 20px;
@@ -95,7 +98,7 @@
        cursor: pointer;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem-selected {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected {
        border: none;
        background: transparent url(../panel/img/top-left.png) no-repeat;
        margin: 0;
        color: #ee5311;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem:hover {
        color: #4b5257;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem-selected:hover {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected:hover {
        color: #ee5311;
 }
 
-.i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+.i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
        background: transparent url(../panel/img/top-right.png) repeat-x right top;
        margin: 0 -1px 0 9px;
        height: 18px;
 
 /* Progress indication */
 
-.i-tabsheet-loading .i-tabsheet-tabs .gwt-TabBarItem-selected span{
+.i-tabsheet-loading .i-tabsheet-tabs .i-tabsheet-tabitem-selected span{
        background: transparent url(../common/img/ajax-loader.gif) no-repeat;
        display: block;
        margin-left: -10px;
        height: 46px;
 }
 
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
        border: 1px solid #babfc0;
        border-bottom: none;
        background: #fff;
        cursor: default;
        color: #ee5311;
 }
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected {
        border: 1px solid #babfc0;
        border-bottom: none;
        background: #fff;
        color: #ee5311;
 }
 
-* html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+* html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
        background: transparent;
        padding: 0;
        margin: 0;
 }
-*+html .i-tabsheet-tabs .gwt-TabBarItem-selected .i-caption {
+*+html .i-tabsheet-tabs .i-tabsheet-tabitem-selected .i-caption {
        background: transparent;
        padding: 0;
        margin: 0;
index bd591bd2299c6b189fdcac165b6b0a372b871ff6..af2cc4a0d6521cf39688f3fd73b28b4d03ee1a07 100644 (file)
@@ -13,6 +13,7 @@ import com.google.gwt.user.client.ui.ClickListener;
 import com.google.gwt.user.client.ui.ComplexPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.BrowserInfo;
 import com.itmill.toolkit.terminal.gwt.client.Caption;
 import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
@@ -33,7 +34,7 @@ public class IAccordion extends ITabsheetBase implements
     public IAccordion() {
         super(CLASSNAME);
         // IE6 needs this to calculate offsetHeight correctly
-        if (Util.isIE6()) {
+        if (BrowserInfo.get().isIE6()) {
             DOM.setStyleAttribute(getElement(), "zoom", "1");
         }
     }
@@ -51,25 +52,24 @@ public class IAccordion extends ITabsheetBase implements
     }
 
     protected void renderTab(UIDL tabUidl, int index, boolean selected) {
-        // TODO check indexes, now new tabs get placed last (changing tab order
-        // is not supported from server-side)
-
-        StackItem item = new StackItem(tabUidl);
-
-        if (stack.size() == 0) {
-            item.addStyleDependentName("first");
+        StackItem item;
+        if (stack.size() <= index) {
+            item = new StackItem(tabUidl);
+            if (stack.size() == 0) {
+                item.addStyleDependentName("first");
+            }
+            stack.add(item);
+            add(item, getElement());
+        } else {
+            item = (StackItem) stack.get(index);
+            item.updateCaption(tabUidl);
         }
 
-        stack.add(item);
-        add(item, getElement());
-
         if (selected) {
             item.open();
             item.setContent(tabUidl.getChildUIDL(0));
         } else if (tabUidl.getChildCount() > 0) {
-            // updating a drawn child on hidden tab
-            Paintable paintable = client.getPaintable(tabUidl.getChildUIDL(0));
-            paintable.updateFromUIDL(tabUidl.getChildUIDL(0), client);
+            item.setContent(tabUidl.getChildUIDL(0));
         }
     }
 
@@ -169,16 +169,14 @@ public class IAccordion extends ITabsheetBase implements
 
         private Caption caption;
         private boolean open = false;
-        private Element content;
-        private Element captionNode;
+        private Element content = DOM.createDiv();
+        private Element captionNode = DOM.createDiv();
         private Paintable paintable;
 
         public StackItem(UIDL tabUidl) {
             setElement(DOM.createDiv());
             caption = new Caption(null, client);
             caption.addClickListener(this);
-            content = DOM.createDiv();
-            captionNode = DOM.createDiv();
             super.add(caption, captionNode);
             DOM.appendChild(captionNode, caption.getElement());
             DOM.appendChild(getElement(), captionNode);
@@ -189,13 +187,13 @@ public class IAccordion extends ITabsheetBase implements
             DOM.setElementProperty(captionNode, "className", CLASSNAME
                     + "-item-caption");
             DOM.setStyleAttribute(content, "overflow", "auto");
-            DOM.setStyleAttribute(content, "display", "none");
             // Force 'hasLayout' in IE6 (prevents layout problems)
-            if (Util.isIE6()) {
+            if (BrowserInfo.get().isIE6()) {
                 DOM.setStyleAttribute(content, "zoom", "1");
             }
+            close();
 
-            caption.updateCaption(tabUidl);
+            updateCaption(tabUidl);
         }
 
         public Element getContainerElement() {
@@ -212,7 +210,11 @@ public class IAccordion extends ITabsheetBase implements
 
         public void open() {
             open = true;
-            DOM.setStyleAttribute(content, "display", "");
+            if (getPaintable() != null) {
+                remove(getPaintable());
+            }
+            DOM.setStyleAttribute(content, "visibility", "");
+            DOM.setStyleAttribute(content, "position", "");
             addStyleDependentName("open");
             if (getPaintable() != null) {
                 add(getPaintable(), content);
@@ -221,10 +223,8 @@ public class IAccordion extends ITabsheetBase implements
 
         public void close() {
             open = false;
-            if (getPaintable() != null) {
-                remove(getPaintable());
-            }
-            DOM.setStyleAttribute(content, "display", "none");
+            DOM.setStyleAttribute(content, "visibility", "hidden");
+            DOM.setStyleAttribute(content, "position", "absolute");
             removeStyleDependentName("open");
         }
 
@@ -234,8 +234,6 @@ public class IAccordion extends ITabsheetBase implements
 
         public void setContent(UIDL contentUidl) {
             final Paintable newPntbl = client.getPaintable(contentUidl);
-            // due hack #1 in ITabsheetBase
-            ((Widget) newPntbl).setVisible(true);
             if (getPaintable() == null) {
                 add((Widget) newPntbl, content);
                 paintables.add(newPntbl);
@@ -253,6 +251,10 @@ public class IAccordion extends ITabsheetBase implements
         public void onClick(Widget sender) {
             onSelectTab(this);
         }
+
+        public void updateCaption(UIDL uidl) {
+            caption.updateCaption(uidl);
+        }
     }
 
     protected void clearPaintables() {
@@ -264,4 +266,26 @@ public class IAccordion extends ITabsheetBase implements
         return paintables.iterator();
     }
 
+    public boolean hasChildComponent(Widget component) {
+        if (paintables.contains(component)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+        // TODO Auto-generated method stub
+    }
+
+    public void updateCaption(Paintable component, UIDL uidl) {
+        for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+            StackItem si = (StackItem) iterator.next();
+            if (si.getPaintable() == component) {
+                si.updateCaption(uidl);
+                return;
+            }
+        }
+    }
+
 }
index 366257fcaa2daba4df4a5ead68a0126b8afb6d6c..8b7349d187649daf8c322244b330d58c96a040b8 100644 (file)
@@ -109,12 +109,11 @@ public class ICustomLayout extends ComplexPanel implements Paintable,
     /** Update the layout from UIDL */
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
         this.client = client;
-        // Client manages general cases
-        if (client.updateComponent(this, uidl, false)) {
+        // ApplicationConnection manages generic component features
+        if (client.updateComponent(this, uidl, true)) {
             return;
         }
 
-        // Update PID
         pid = uidl.getId();
         if (!hasTemplate()) {
             // Update HTML template only once
index e4f86ec1cb50fe9c3fe2341b29f29d3381d9bcbc..7c2f61e4fa85fd8d0d103ff1fba18130c72f5287 100644 (file)
@@ -616,8 +616,7 @@ public class IExpandLayout extends ComplexPanel implements
         // Modify layout margins
         handleMargins(uidl);
 
-        // Ensure correct implementation
-        if (client.updateComponent(this, uidl, false)) {
+        if (client.updateComponent(this, uidl, true)) {
             return;
         }
 
index 6722e1e42103a1971cd046761a47bbb2516efc54..8613f0bfde9ab3e74d6a5d3f3205cf12d7fa4186 100644 (file)
@@ -54,7 +54,7 @@ public class IForm extends ComplexPanel implements Paintable,
     }\r
 \r
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {\r
-        if (client.updateComponent(this, uidl, false)) {\r
+        if (client.updateComponent(this, uidl, true)) {\r
             return;\r
         }\r
 \r
index a476e263d969e98b3fb577c9de485c065d68f0f9..beb7c82b9a5bdf8f4edf8294dcb79f1238ba42bf 100644 (file)
@@ -34,7 +34,7 @@ public class IFormLayout extends FlexTable implements Container {
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
         this.client = client;
 
-        if (client.updateComponent(this, uidl, false)) {
+        if (client.updateComponent(this, uidl, true)) {
             return;
         }
 
index d62f6300001e714b79a1d09ad8c89139846efb55..c1a9b0dee3801ad7bd23d5fccd00bf9a91bdffb8 100644 (file)
@@ -70,7 +70,7 @@ public class IGridLayout extends SimplePanel implements Paintable, Container,
 
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
 
-        if (client.updateComponent(this, uidl, false)) {
+        if (client.updateComponent(this, uidl, true)) {
             return;
         }
         final MarginInfo margins = new MarginInfo(uidl
index f6ec5038576dddf599f3d5450f632d42d9c1c7a5..3bd5a469e274597c430c55687701ddc4c049be44 100644 (file)
@@ -212,7 +212,7 @@ public class IOrderedLayout extends Panel implements Container,
         updateMarginAndSpacingSizesFromCSS(uidl);
 
         // Update sizes, ...
-        if (client.updateComponent(this, uidl, false)) {
+        if (client.updateComponent(this, uidl, true)) {
             return;
         }
 
index 3c76cbd47b7309c0835f49a78408c6a5863ffb61..64fb4fccd651049c6c29c17f11b4ec8de8bb7f28 100644 (file)
@@ -4,6 +4,7 @@
 
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
+import java.util.HashMap;
 import java.util.Iterator;
 
 import com.google.gwt.user.client.Command;
@@ -11,10 +12,9 @@ import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.DeferredCommand;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.ComplexPanel;
 import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.SourcesTabEvents;
-import com.google.gwt.user.client.ui.TabBar;
-import com.google.gwt.user.client.ui.TabListener;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
 import com.itmill.toolkit.terminal.gwt.client.Caption;
@@ -26,6 +26,77 @@ import com.itmill.toolkit.terminal.gwt.client.Util;
 public class ITabsheet extends ITabsheetBase implements
         ContainerResizedListener {
 
+    class TabBar extends ComplexPanel implements ClickListener {
+
+        private Element tr = DOM.createTR();
+
+        private Element spacerTd = DOM.createTD();
+
+        TabBar() {
+            Element el = DOM.createTable();
+            Element tbody = DOM.createTBody();
+            DOM.appendChild(el, tbody);
+            DOM.appendChild(tbody, tr);
+            setStyleName(spacerTd, CLASSNAME + "-spacertd");
+            DOM.appendChild(tr, spacerTd);
+            setElement(el);
+        }
+
+        protected Element getContainerElement() {
+            return tr;
+        }
+
+        private Widget oldSelected;
+
+        public int getTabCount() {
+            return getWidgetCount();
+        }
+
+        public void addTab(Caption c) {
+            Element td = DOM.createTD();
+            setStyleName(td, CLASSNAME + "-tabitemcell");
+            Element div = DOM.createTD();
+            setStyleName(div, CLASSNAME + "-tabitem");
+            DOM.appendChild(td, div);
+            DOM.insertBefore(tr, td, spacerTd);
+            c.addClickListener(this);
+            add(c, div);
+        }
+
+        public void onClick(Widget sender) {
+            int index = getWidgetIndex(sender);
+            onTabSelected(index);
+        }
+
+        public void selectTab(int index) {
+            Widget newSelected = getWidget(index);
+            Widget.setStyleName(DOM.getParent(newSelected.getElement()),
+                    CLASSNAME + "-tabitem-selected", true);
+            if (oldSelected != null) {
+                Widget.setStyleName(DOM.getParent(oldSelected.getElement()),
+                        CLASSNAME + "-tabitem-selected", false);
+            }
+            oldSelected = newSelected;
+        }
+
+        public void removeTab(int i) {
+            remove(i);
+        }
+
+        public boolean remove(Widget w) {
+            ((Caption) w).removeClickListener(this);
+            return super.remove(w);
+        }
+
+        public Caption getTab(int index) {
+            if (index >= getWidgetCount()) {
+                return null;
+            }
+            return (Caption) getWidget(index);
+        }
+
+    }
+
     public static final String CLASSNAME = "i-tabsheet";
 
     public static final String TABS_CLASSNAME = "i-tabsheet-tabcontainer";
@@ -40,6 +111,8 @@ public class ITabsheet extends ITabsheetBase implements
     private final ITabsheetPanel tp;
     private final Element contentNode, deco;
 
+    private final HashMap captions = new HashMap();
+
     private String height;
     private String width;
 
@@ -52,41 +125,31 @@ public class ITabsheet extends ITabsheetBase implements
      */
     private Widget previousVisibleWidget;
 
-    private final TabListener tl = new TabListener() {
-
-        public void onTabSelected(SourcesTabEvents sender, final int tabIndex) {
-            if (client != null && activeTabIndex != tabIndex) {
-                addStyleDependentName("loading");
-                // run updating variables in deferred command to bypass some
-                // FF
-                // optimization issues
-                DeferredCommand.addCommand(new Command() {
-                    public void execute() {
-                        previousVisibleWidget = tp.getWidget(tp
-                                .getVisibleWidget());
-                        DOM.setStyleAttribute(previousVisibleWidget
-                                .getElement(), "visibility", "hidden");
-                        client.updateVariable(id, "selected", tabKeys.get(
-                                tabIndex).toString(), true);
-                    }
-                });
-                waitingForResponse = true;
-            }
+    private void onTabSelected(final int tabIndex) {
+        if (disabled || waitingForResponse) {
+            return;
         }
-
-        public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
-            if (disabled || waitingForResponse) {
-                return false;
-            }
-            final Object tabKey = tabKeys.get(tabIndex);
-            if (disabledTabKeys.contains(tabKey)) {
-                return false;
-            }
-
-            return true;
+        final Object tabKey = tabKeys.get(tabIndex);
+        if (disabledTabKeys.contains(tabKey)) {
+            return;
         }
-
-    };
+        if (client != null && activeTabIndex != tabIndex) {
+            addStyleDependentName("loading");
+            // run updating variables in deferred command to bypass some
+            // FF
+            // optimization issues
+            DeferredCommand.addCommand(new Command() {
+                public void execute() {
+                    previousVisibleWidget = tp.getWidget(tp.getVisibleWidget());
+                    DOM.setStyleAttribute(previousVisibleWidget.getElement(),
+                            "visibility", "hidden");
+                    client.updateVariable(id, "selected", tabKeys.get(tabIndex)
+                            .toString(), true);
+                }
+            });
+            waitingForResponse = true;
+        }
+    }
 
     public ITabsheet() {
         super(CLASSNAME);
@@ -133,11 +196,9 @@ public class ITabsheet extends ITabsheetBase implements
 
         DOM.appendChild(tabs, scroller);
 
-        tb.addTabListener(tl);
-
         // TODO Use for Safari only. Fix annoying 1px first cell in TabBar.
-        DOM.setStyleAttribute(DOM.getFirstChild(DOM.getFirstChild(DOM
-                .getFirstChild(tb.getElement()))), "display", "none");
+        // DOM.setStyleAttribute(DOM.getFirstChild(DOM.getFirstChild(DOM
+        // .getFirstChild(tb.getElement()))), "display", "none");
 
     }
 
@@ -217,21 +278,30 @@ public class ITabsheet extends ITabsheetBase implements
     }
 
     protected void renderTab(final UIDL tabUidl, int index, boolean selected) {
-        // TODO check indexes, now new tabs get placed last (changing tab order
-        // is not supported from server-side)
-        Caption c = new Caption(null, client);
+        Caption c = tb.getTab(index);
+        if (c == null) {
+            c = new Caption(null, client);
+            tb.addTab(c);
+        }
         c.updateCaption(tabUidl);
-        tb.addTab(c);
+        captions.put("" + index, c);
         if (selected) {
             renderContent(tabUidl.getChildUIDL(0));
             tb.selectTab(index);
-        } else if (tabUidl.getChildCount() > 0) {
-            // updating a drawn child on hidden tab
-            Paintable paintable = client.getPaintable(tabUidl.getChildUIDL(0));
-            paintable.updateFromUIDL(tabUidl.getChildUIDL(0), client);
+        } else {
+            if (tabUidl.getChildCount() > 0) {
+                // updating a drawn child on hidden tab
+                Paintable paintable = client.getPaintable(tabUidl
+                        .getChildUIDL(0));
+
+                if (tp.getWidgetIndex((Widget) paintable) < 0) {
+                    tp.insert((Widget) paintable, index);
+                }
+                paintable.updateFromUIDL(tabUidl.getChildUIDL(0), client);
+            } else if (tp.getWidgetCount() <= index) {
+                tp.add(new Label(""));
+            }
         }
-        // Add place-holder content
-        tp.add(new Label(""));
     }
 
     protected void selectTab(int index, final UIDL contentUidl) {
@@ -347,9 +417,9 @@ public class ITabsheet extends ITabsheetBase implements
 
     private void showAllTabs() {
         scrollerIndex = 0;
+        Element tr = DOM.getFirstChild(DOM.getFirstChild(tb.getElement()));
         for (int i = 0; i < tb.getTabCount(); i++) {
-            DOM.setStyleAttribute(DOM.getChild(DOM.getFirstChild(DOM
-                    .getFirstChild(tb.getElement())), i + 1), "display", "");
+            DOM.setStyleAttribute(DOM.getChild(tr, i), "display", "");
         }
     }
 
@@ -369,15 +439,29 @@ public class ITabsheet extends ITabsheetBase implements
         }
         tp.clear();
 
-        // Get rid of unnecessary 100% cell heights in TabBar (really ugly hack)
-        final Element tr = DOM.getChild(DOM.getChild(tb.getElement(), 0), 0);
-        final Element rest = DOM.getChild(DOM.getChild(tr, DOM
-                .getChildCount(tr) - 1), 0);
-        DOM.removeElementAttribute(rest, "style");
-
     }
 
     protected Iterator getPaintableIterator() {
         return tp.iterator();
     }
+
+    public boolean hasChildComponent(Widget component) {
+        if (tp.getWidgetIndex(component) < 0) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
+        int widgetIndex = tp.getWidgetIndex(oldComponent);
+        tp.remove(oldComponent);
+        tp.insert(newComponent, widgetIndex);
+    }
+
+    public void updateCaption(Paintable component, UIDL uidl) {
+        int i = tp.getWidgetIndex((Widget) component);
+        Caption c = (Caption) captions.get("" + i);
+        c.updateCaption(uidl);
+    }
 }
index 05a77cfaf2858a5f754b1e991a75b2545d0b7720..65e1a1f07e9c31e13eaeaaa570fe5834d5a63ec0 100644 (file)
@@ -9,16 +9,16 @@ import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.ComplexPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.Container;
 import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
 
-abstract class ITabsheetBase extends ComplexPanel implements Paintable {
+abstract class ITabsheetBase extends ComplexPanel implements Container {
 
     String id;
     ApplicationConnection client;
 
     protected final ArrayList tabKeys = new ArrayList();
-    protected final ArrayList captions = new ArrayList();
     protected int activeTabIndex = 0;
     protected boolean disabled;
     protected boolean readonly;
@@ -43,73 +43,46 @@ abstract class ITabsheetBase extends ComplexPanel implements Paintable {
 
         // Render content
         final UIDL tabs = uidl.getChildUIDL(0);
-        if (keepCurrentTabs(uidl)) {
-            int index = 0;
-            for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
-                final UIDL tab = (UIDL) it.next();
-                final boolean selected = tab.getBooleanAttribute("selected");
-                if (selected) {
-                    selectTab(index, tab.getChildUIDL(0));
-                } else if (tab.getChildCount() > 0) {
-                    // updating a drawn child on hidden tab
-                    Paintable paintable = client.getPaintable(tab
-                            .getChildUIDL(0));
-                    // TODO widget may flash on screen
-                    paintable.updateFromUIDL(tab.getChildUIDL(0), client);
-                    // Hack #1 in ITabsheetBase: due ITabsheets content has no
-                    // wrappers for each tab, we need to hide the actual widgets
-                    ((Widget) paintable).setVisible(false);
-                }
-                index++;
-            }
-        } else {
+        ArrayList oldPaintables = new ArrayList();
+        for (Iterator iterator = getPaintableIterator(); iterator.hasNext();) {
+            oldPaintables.add(iterator.next());
+        }
 
-            ArrayList oldPaintables = new ArrayList();
-            for (Iterator iterator = getPaintableIterator(); iterator.hasNext();) {
-                oldPaintables.add(iterator.next());
-            }
+        // Clear previous values
+        tabKeys.clear();
+        disabledTabKeys.clear();
 
-            // Clear previous values
-            tabKeys.clear();
-            captions.clear();
-            disabledTabKeys.clear();
-
-            clearPaintables();
-
-            int index = 0;
-            for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
-                final UIDL tab = (UIDL) it.next();
-                final String key = tab.getStringAttribute("key");
-                final boolean selected = tab.getBooleanAttribute("selected");
-                String caption = tab.getStringAttribute("caption");
-                if (caption == null) {
-                    caption = " ";
-                }
+        int index = 0;
+        for (final Iterator it = tabs.getChildIterator(); it.hasNext();) {
+            final UIDL tab = (UIDL) it.next();
+            final String key = tab.getStringAttribute("key");
+            final boolean selected = tab.getBooleanAttribute("selected");
 
-                if (tab.getBooleanAttribute("disabled")) {
-                    disabledTabKeys.add(key);
-                }
+            if (tab.getBooleanAttribute("disabled")) {
+                disabledTabKeys.add(key);
+            }
 
-                captions.add(caption);
-                tabKeys.add(key);
+            tabKeys.add(key);
 
-                if (selected) {
-                    activeTabIndex = index;
-                }
-                if (tab.getChildCount() > 0) {
-                    Paintable p = client.getPaintable(tab.getChildUIDL(0));
-                    oldPaintables.remove(p);
-                }
-                renderTab(tab, index, selected);
-                index++;
+            if (selected) {
+                activeTabIndex = index;
+            }
+            if (tab.getChildCount() > 0) {
+                Paintable p = client.getPaintable(tab.getChildUIDL(0));
+                oldPaintables.remove(p);
             }
+            renderTab(tab, index, selected);
+            index++;
+        }
 
-            for (Iterator iterator = oldPaintables.iterator(); iterator
-                    .hasNext();) {
-                Object oldPaintable = iterator.next();
-                if (oldPaintable instanceof Paintable) {
-                    client.unregisterPaintable((Paintable) oldPaintable);
+        for (Iterator iterator = oldPaintables.iterator(); iterator.hasNext();) {
+            Object oldPaintable = iterator.next();
+            if (oldPaintable instanceof Paintable) {
+                Widget w = (Widget) oldPaintable;
+                if (w.isAttached()) {
+                    w.removeFromParent();
                 }
+                client.unregisterPaintable((Paintable) oldPaintable);
             }
         }
 
@@ -125,21 +98,6 @@ abstract class ITabsheetBase extends ComplexPanel implements Paintable {
      */
     abstract protected void clearPaintables();
 
-    protected boolean keepCurrentTabs(UIDL uidl) {
-        final UIDL tabs = uidl.getChildUIDL(0);
-        boolean retval = tabKeys.size() == tabs.getNumberOfChildren();
-        for (int i = 0; retval && i < tabKeys.size(); i++) {
-            String key = (String) tabKeys.get(i);
-            UIDL tabUIDL = tabs.getChildUIDL(i);
-            retval = key.equals(tabUIDL.getStringAttribute("key"))
-                    && captions.get(i).equals(
-                            tabUIDL.getStringAttribute("caption"))
-                    && (tabUIDL.hasAttribute("disabled") == disabledTabKeys
-                            .contains(key));
-        }
-        return retval;
-    }
-
     /**
      * Implement in extending classes. This method should render needed elements
      * and set the visibility of the tab according to the 'selected' parameter.
index 01ac63645e82c38200a92692ffccbfa5280ab2f3..d07d720f9c69c9565e162735e70fad529a61bca7 100644 (file)
@@ -5,13 +5,14 @@
 package com.itmill.toolkit.terminal.gwt.client.ui;\r
 \r
 import com.google.gwt.user.client.DOM;\r
+import com.google.gwt.user.client.Element;\r
 import com.google.gwt.user.client.ui.ComplexPanel;\r
 import com.google.gwt.user.client.ui.Widget;\r
 \r
 /**\r
  * A panel that displays all of its child widgets in a 'deck', where only one\r
  * can be visible at a time. It is used by\r
- * {@link com.itmill.toolkit.terminal.gwt.client.ui.ITabsheetPanel}.\r
+ * {@link com.itmill.toolkit.terminal.gwt.client.ui.ITabsheet}.\r
  * \r
  * This class has the same basic functionality as the GWT DeckPanel\r
  * {@link com.google.gwt.user.client.ui.DeckPanel}, with the exception that it\r
@@ -20,6 +21,7 @@ import com.google.gwt.user.client.ui.Widget;
 public class ITabsheetPanel extends ComplexPanel {\r
 \r
     private Widget visibleWidget;\r
+    private boolean fullheight = false;\r
 \r
     /**\r
      * Creates an empty tabsheet panel.\r
@@ -35,8 +37,15 @@ public class ITabsheetPanel extends ComplexPanel {
      *                the widget to be added\r
      */\r
     public void add(Widget w) {\r
-        super.add(w, getElement());\r
-        initChildWidget(w);\r
+        Element el = createContainerElement();\r
+        DOM.appendChild(getElement(), el);\r
+        super.add(w, el);\r
+    }\r
+\r
+    private Element createContainerElement() {\r
+        Element el = DOM.createDiv();\r
+        hide(el);\r
+        return el;\r
     }\r
 \r
     /**\r
@@ -59,18 +68,21 @@ public class ITabsheetPanel extends ComplexPanel {
      *                 if <code>beforeIndex</code> is out of range\r
      */\r
     public void insert(Widget w, int beforeIndex) {\r
-        super.insert(w, getElement(), beforeIndex, true);\r
-        initChildWidget(w);\r
+        Element el = createContainerElement();\r
+        DOM.insertChild(getElement(), el, beforeIndex);\r
+        super.insert(w, el, beforeIndex, false);\r
     }\r
 \r
     public boolean remove(Widget w) {\r
+        final int index = getWidgetIndex(w);\r
         final boolean removed = super.remove(w);\r
         if (removed) {\r
-            resetChildWidget(w);\r
-\r
             if (visibleWidget == w) {\r
                 visibleWidget = null;\r
             }\r
+            Element child = DOM.getChild(getElement(), index);\r
+            DOM.removeChild(getElement(), child);\r
+            unHide(child);\r
         }\r
         return removed;\r
     }\r
@@ -87,26 +99,39 @@ public class ITabsheetPanel extends ComplexPanel {
         Widget newVisible = getWidget(index);\r
         if (visibleWidget != newVisible) {\r
             if (visibleWidget != null) {\r
-                visibleWidget.setVisible(false);\r
+                hide(DOM.getParent(visibleWidget.getElement()));\r
             }\r
             visibleWidget = newVisible;\r
-            visibleWidget.setVisible(true);\r
+            unHide(DOM.getParent(visibleWidget.getElement()));\r
         }\r
     }\r
 \r
-    /**\r
-     * Make the widget invisible, and set its width and height to full.\r
-     */\r
-    private void initChildWidget(Widget w) {\r
-        w.setVisible(false);\r
+    public void setHeight(String height) {\r
+        super.setHeight(height);\r
+        if ("100%".equals(height) && !fullheight) {\r
+            int childCount = DOM.getChildCount(getElement());\r
+            for (int i = 0; i < childCount; i++) {\r
+                DOM.setStyleAttribute(DOM.getChild(getElement(), i), "height",\r
+                        "100%");\r
+            }\r
+            fullheight = true;\r
+        } else if (fullheight) {\r
+            int childCount = DOM.getChildCount(getElement());\r
+            for (int i = 0; i < childCount; i++) {\r
+                DOM.setStyleAttribute(DOM.getChild(getElement(), i), "height",\r
+                        "");\r
+            }\r
+            fullheight = false;\r
+        }\r
     }\r
 \r
-    /**\r
-     * Make the widget visible, and clear the widget's width and height\r
-     * attributes. This is done so that any changes to the visibility, height,\r
-     * or width of the widget that were done by the panel are undone.\r
-     */\r
-    private void resetChildWidget(Widget w) {\r
-        w.setVisible(true);\r
+    private void hide(Element e) {\r
+        DOM.setStyleAttribute(e, "visibility", "hidden");\r
+        DOM.setStyleAttribute(e, "position", "absolute");\r
+    }\r
+\r
+    private void unHide(Element e) {\r
+        DOM.setStyleAttribute(e, "visibility", "");\r
+        DOM.setStyleAttribute(e, "position", "");\r
     }\r
 }\r
index f149fea15d6733be5519556f61c32a689fa3001f..6b515765e18451044d342a0fc90568f1fc9f34cf 100644 (file)
@@ -37,7 +37,7 @@ public class ISizeableGridLayout extends AbsoluteGrid implements Paintable,
     public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
         this.client = client;
 
-        if (client.updateComponent(this, uidl, false)) {
+        if (client.updateComponent(this, uidl, true)) {
             return;
         }
 
index e500d1725525bbc536b2b5f8aab444a40fd02e06..08628ddf5b3bb9fa2414166c7cbd5a95e5314f35 100644 (file)
@@ -168,6 +168,16 @@ public interface Component extends Paintable, VariableOwner, Sizeable {
      */
     public String getCaption();
 
+    /**
+     * Sets the component's caption <code>String</code>. Caption is the
+     * visible name of the component. This method will trigger a
+     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
+     * 
+     * @param caption
+     *                the new caption <code>String</code> for the component.
+     */
+    public void setCaption(String caption);
+
     /**
      * Gets the component's icon. A component may have a graphical icon
      * associated with it, this method retrieves it if it is defined.
@@ -176,6 +186,15 @@ public interface Component extends Paintable, VariableOwner, Sizeable {
      */
     public Resource getIcon();
 
+    /**
+     * Sets the component's icon. This method will trigger a
+     * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent RepaintRequestEvent}.
+     * 
+     * @param icon
+     *                the icon to be shown with the component's caption.
+     */
+    public void setIcon(Resource icon);
+
     /**
      * Gets the component's parent window. If the component does not yet belong
      * to a window <code>null</code> is returned.
index 8aeed7c169cf3712047119c2baa58248ec4c502c..80cbb7a97d04ec9ea4cbfed245442e2a94ffc4a9 100644 (file)
@@ -5,7 +5,6 @@
 package com.itmill.toolkit.ui;
 
 import java.lang.reflect.Method;
-import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Map;
@@ -32,16 +31,6 @@ public class TabSheet extends AbstractComponentContainer implements
      */
     private final LinkedList tabs = new LinkedList();
 
-    /**
-     * Tab -> caption mapping.
-     */
-    private final Hashtable tabCaptions = new Hashtable();
-
-    /**
-     * Tab -> icon mapping .
-     */
-    private final Hashtable tabIcons = new Hashtable();
-
     /**
      * Selected tab.
      */
@@ -85,7 +74,6 @@ public class TabSheet extends AbstractComponentContainer implements
             super.removeComponent(c);
             keyMapper.remove(c);
             tabs.remove(c);
-            tabCaptions.remove(c);
             if (c.equals(selected)) {
                 if (tabs.isEmpty()) {
                     selected = null;
@@ -94,7 +82,6 @@ public class TabSheet extends AbstractComponentContainer implements
                     fireSelectedTabChange();
                 }
             }
-            c.removeListener(this);
             requestRepaint();
         }
     }
@@ -111,21 +98,24 @@ public class TabSheet extends AbstractComponentContainer implements
     }
 
     /**
-     * Adds a new tab into TabSheet with overridden caption and icon.
+     * Adds a new tab into TabSheet.
      * 
      * @param c
      *                the component to be added onto tab.
      * @param caption
-     *                the caption of the tab to be used instead of components
-     *                own.
+     *                the caption to be set for the component and used rendered
+     *                in tab bar
      * @param icon
-     *                the icon of the tab to be used instead of components own.
+     *                the icon to be set for the component and used rendered in
+     *                tab bar
      */
     public void addTab(Component c, String caption, Resource icon) {
         if (c != null) {
-            tabCaptions.put(c, caption != null ? caption : "");
+            if (caption != null) {
+                c.setCaption(caption);
+            }
             if (icon != null) {
-                tabIcons.put(c, icon);
+                c.setIcon(icon);
             }
             addTab(c);
         }
@@ -147,7 +137,6 @@ public class TabSheet extends AbstractComponentContainer implements
             }
             super.addComponent(c);
             requestRepaint();
-            c.addListener(this);
         }
     }
 
@@ -273,20 +262,15 @@ public class TabSheet extends AbstractComponentContainer implements
      *                the component.
      */
     public String getTabCaption(Component c) {
-        String caption = (String) tabCaptions.get(c);
-        if (caption == null) {
-            caption = c.getCaption();
-        }
-        if (caption == null) {
-            caption = "";
+        if (c.getCaption() == null) {
+            return "";
+        } else {
+            return c.getCaption();
         }
-        return caption;
     }
 
     /**
-     * Sets overridden tab caption for given component.
-     * 
-     * Normally TabSheet uses caption from component
+     * Sets tabs captions.
      * 
      * @param c
      *                the component.
@@ -294,8 +278,9 @@ public class TabSheet extends AbstractComponentContainer implements
      *                the caption to set.
      */
     public void setTabCaption(Component c, String caption) {
-        tabCaptions.put(c, caption);
-        requestRepaint();
+        if (tabs.contains(c)) {
+            c.setCaption(caption);
+        }
     }
 
     /**
@@ -305,11 +290,7 @@ public class TabSheet extends AbstractComponentContainer implements
      *                the component.
      */
     public Resource getTabIcon(Component c) {
-        if (tabIcons.containsKey(c)) {
-            return (Resource) tabIcons.get(c);
-        } else {
-            return c.getIcon();
-        }
+        return c.getIcon();
     }
 
     /**
@@ -321,12 +302,9 @@ public class TabSheet extends AbstractComponentContainer implements
      * @param icon
      */
     public void setTabIcon(Component c, Resource icon) {
-        if (icon == null) {
-            tabIcons.remove(c);
-        } else {
-            tabIcons.put(c, icon);
+        if (tabs.contains(c)) {
+            c.setIcon(icon);
         }
-        requestRepaint();
     }
 
     /**
@@ -527,11 +505,13 @@ public class TabSheet extends AbstractComponentContainer implements
     }
 
     /*
-     * We need to repaint on child repaint due the way captions and icons are
-     * handled
+     * If child is not rendered on the client we need to repaint on child
+     * repaint due the way captions and icons are handled.
      */
     public void repaintRequested(RepaintRequestEvent event) {
-        requestRepaint();
+        if (!paintedTabs.contains(event.getPaintable())) {
+            requestRepaint();
+        }
     }
 
     public void detach() {