]> source.dussan.org Git - vaadin-framework.git/commitdiff
Accordion now supports sizing with height also.
authorJouni Koivuviita <jouni.koivuviita@itmill.com>
Fri, 14 Dec 2007 14:17:51 +0000 (14:17 +0000)
committerJouni Koivuviita <jouni.koivuviita@itmill.com>
Fri, 14 Dec 2007 14:17:51 +0000 (14:17 +0000)
svn changeset:3243/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java
src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css

index c47ac52be940637ae6a01c64bf950a9a3b02a7e2..e19f9eb674758c2f580b53e71c36b491de1f733f 100644 (file)
@@ -41,6 +41,9 @@ public class IAccordion extends ITabsheetBase implements
     }
 
     private StackItem getSelectedStack() {
+        if (stack.size() == 0) {
+            return null;
+        }
         return (StackItem) stack.get(activeTabIndex);
     }
 
@@ -70,12 +73,15 @@ public class IAccordion extends ITabsheetBase implements
             StackItem item = (StackItem) stack.get(index);
             item.setContent(new StackContent(contentUidl));
             item.open();
+            iLayout();
         }
     }
 
     public void onSelectTab(StackItem item) {
         final int index = stack.indexOf(item);
         if (index != activeTabIndex && !disabled && !readonly) {
+            if (getSelectedStack() == null)
+                return;
             getSelectedStack().close();
             addStyleDependentName("loading");
             // run updating variables in deferred command to bypass some FF
@@ -102,11 +108,44 @@ public class IAccordion extends ITabsheetBase implements
     }
 
     public void iLayout() {
+        StackItem item = getSelectedStack();
+        if (item == null)
+            return;
+
         if (height != null && height != "") {
-            // TODO
+            // Detach visible widget from document flow for a while to calculate used height correctly
+            Widget w = item.getContent().getContainedWidget();
+            String originalPositioning = "";
+            if(w != null) {
+                originalPositioning = DOM.getStyleAttribute(w.getElement(), "position");
+                DOM.setStyleAttribute(w.getElement(), "visibility", "hidden");
+                DOM.setStyleAttribute(w.getElement(), "position", "absolute");
+            }
+            item.getContent().setHeight("");
+            
+
+            // Calculate target height
+            super.setHeight(height);
+            int targetHeight = getOffsetHeight();
+            super.setHeight("");
+
+            // Calculate used height
+            int usedHeight = getOffsetHeight();
+
+            int h = targetHeight - usedHeight;
+            if (h < 0)
+                h = 0;
+            item.getContent().setHeight(h + "px");
+            
+            // Put widget back into normal flow
+            if(w != null) {
+                DOM.setStyleAttribute(w.getElement(), "position", originalPositioning);
+                DOM.setStyleAttribute(w.getElement(), "visibility", "");
+            }
         } else {
-            // getVisibleContent().getContent().setHeight("");
+            item.getContent().setHeight("");
         }
+
         Util.runDescendentsLayout(this);
     }
 
@@ -192,10 +231,13 @@ public class IAccordion extends ITabsheetBase implements
 
     protected class StackContent extends UIObject {
 
+        private Widget widget;
+        
         protected StackContent() {
             setElement(DOM.createDiv());
             setVisible(false);
             setStyleName(CLASSNAME + "-item-content");
+            DOM.setStyleAttribute(getElement(), "overflow", "auto");
         }
 
         protected StackContent(UIDL contentUidl) {
@@ -215,6 +257,11 @@ public class IAccordion extends ITabsheetBase implements
             final Paintable content = client.getPaintable(contentUidl);
             DOM.appendChild(getElement(), ((Widget) content).getElement());
             (content).updateFromUIDL(contentUidl, client);
+            widget = (Widget) content;
+        }
+        
+        public Widget getContainedWidget() {
+            return widget;
         }
 
     }
index fd5f752f02312bf1da87b15e456c697bae3cbdc6..bb18b70e5076569d9296f94ce83fa8fd5baece64 100644 (file)
@@ -1,17 +1,18 @@
 .i-accordion {
        outline: none;
-       border-bottom: 1px solid #c8cccd;
+       overflow: hidden;
 }
 
 .i-accordion-item-caption {
-       height: 25px;
-       padding: 6px 0 0 18px;
+       height: 24px;
+       padding: 7px 0 0 18px;
        overflow: hidden;
        white-space: nowrap;
        background: #edf0f0 url(../tabsheet/img/tab-bg.png);
        font-size: 15px;
        color: #656d73;
        border-top: 1px solid #c8cccd;
+       cursor: pointer;
 }
 
 .i-accordion-item-caption span {
@@ -24,6 +25,7 @@
        background: #d5dee2 url(img/selected-bg.png);
        border-top-color: #cbd7de;
        border-bottom-color: #bfc9d4;
+       cursor: default;
 }
 
 .i-accordion-item-open .i-accordion-item-caption span {