From d562544200adb96db8a1a830e61d271043ef73a1 Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Fri, 14 Dec 2007 14:17:51 +0000 Subject: [PATCH] Accordion now supports sizing with height also. svn changeset:3243/svn branch:trunk --- .../terminal/gwt/client/ui/IAccordion.java | 51 ++++++++++++++++++- .../public/default/accordion/accordion.css | 8 +-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java index c47ac52be9..e19f9eb674 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAccordion.java @@ -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; } } diff --git a/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css b/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css index fd5f752f02..bb18b70e50 100644 --- a/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css +++ b/src/com/itmill/toolkit/terminal/gwt/public/default/accordion/accordion.css @@ -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 { -- 2.39.5