import com.itmill.toolkit.terminal.gwt.client.ContainerResizedListener;
import com.itmill.toolkit.terminal.gwt.client.ICaption;
import com.itmill.toolkit.terminal.gwt.client.Paintable;
+import com.itmill.toolkit.terminal.gwt.client.RenderInformation;
import com.itmill.toolkit.terminal.gwt.client.RenderSpace;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
import com.itmill.toolkit.terminal.gwt.client.Util;
private int selectedUIDLItemIndex = -1;
+ private RenderInformation renderInformation = new RenderInformation();
+
public IAccordion() {
super(CLASSNAME);
// IE6 needs this to calculate offsetHeight correctly
}
lazyUpdateMap.clear();
}
+
+ renderInformation.updateSize(getElement());
+
rendering = false;
}
- protected void renderTab(UIDL tabUidl, int index, boolean selected) {
+ protected void renderTab(UIDL tabUidl, int index, boolean selected,
+ boolean hidden) {
StackItem item;
int itemIndex;
if (stack.size() <= index) {
item.updateCaption(tabUidl);
}
+ item.setVisible(!hidden);
+
if (selected) {
selectedUIDLItemIndex = itemIndex;
}
openTab.setHeight(spaceForOpenItem);
} else {
renderSpace.setHeight(0);
+ openTab.setHeightFromWidget();
+
}
}
}
}
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ }
+
+ public void setHeightFromWidget() {
+ Widget paintable = getPaintable();
+ if (paintable == null) {
+ return;
+ }
+
+ int paintableHeight = (paintable).getElement().getOffsetHeight();
+ setHeight(paintableHeight);
+
+ }
+
/**
* Returns caption width including padding
*
private boolean open = false;
private Element content = DOM.createDiv();
private Element captionNode = DOM.createDiv();
- private Paintable paintable;
public StackItem(UIDL tabUidl) {
setElement(DOM.createDiv());
}
}
+ public void replacePaintable(Paintable newPntbl) {
+ if (getWidgetCount() > 1) {
+ client.unregisterPaintable((Paintable) getWidget(1));
+ paintables.remove(getWidget(1));
+ remove(1);
+ }
+ add((Widget) newPntbl, content);
+ paintables.add(newPntbl);
+ }
+
public void open() {
open = true;
DOM.setStyleAttribute(content, "top", getCaptionHeight() + "px");
add((Widget) newPntbl, content);
paintables.add(newPntbl);
} else if (getPaintable() != newPntbl) {
- client.unregisterPaintable((Paintable) getWidget(1));
- paintables.remove(getWidget(1));
- remove(1);
- add((Widget) newPntbl, content);
- paintables.add(newPntbl);
+ replacePaintable(newPntbl);
}
- paintable = newPntbl;
- paintable.updateFromUIDL(contentUidl, client);
+ newPntbl.updateFromUIDL(contentUidl, client);
- if (isOpen()) {
- if (isDynamicHeight()) {
- setHeight(((Widget) paintable).getOffsetHeight());
- }
+ if (isOpen() && isDynamicHeight()) {
+ setHeightFromWidget();
}
}
return DOM.getFirstChild(content).getOffsetWidth();
}
+ public boolean contains(Paintable p) {
+ return (getPaintable() == p);
+ }
+
+ public boolean isCaptionVisible() {
+ return caption.isVisible();
+ }
+
}
protected void clearPaintables() {
}
public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
- // TODO Auto-generated method stub
+ for (StackItem item : stack) {
+ if (item.getPaintable() == oldComponent) {
+ item.replacePaintable((Paintable) newComponent);
+ return;
+ }
+ }
}
public void updateCaption(Paintable component, UIDL uidl) {
for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
StackItem si = (StackItem) iterator.next();
if (si.getPaintable() == component) {
+ boolean visible = si.isVisible();
si.updateCaption(uidl);
+ if (si.isCaptionVisible() != visible) {
+ si.setVisible(si.isCaptionVisible());
+ }
+
return;
}
}
}
public boolean requestLayout(Set<Paintable> child) {
- // TODO Auto-generated method stub
- return false;
+ if (!isDynamicHeight() && !isDynamicWidth()) {
+ /*
+ * If the height and width has been specified for this container the
+ * child components cannot make the size of the layout change
+ */
+
+ return true;
+ }
+
+ updateOpenTabSize();
+
+ if (renderInformation.updateSize(getElement())) {
+ /*
+ * Size has changed so we let the child components know about the
+ * new size.
+ */
+ iLayout();
+ return false;
+ } else {
+ /*
+ * Size has not changed so we do not need to propagate the event
+ * further
+ */
+ return true;
+ }
+
}
public RenderSpace getAllocatedSpace(Widget child) {
return (ICaption) getWidget(index);
}
+ public void setVisible(int index, boolean visible) {
+ Element e = DOM.getParent(getTab(index).getElement());
+ if (visible) {
+ DOM.setStyleAttribute(e, "display", "");
+ } else {
+ DOM.setStyleAttribute(e, "display", "none");
+ }
+ }
+
}
public static final String CLASSNAME = "i-tabsheet";
super.setWidth(realWidth + "px");
}
- protected void renderTab(final UIDL tabUidl, int index, boolean selected) {
+ protected void renderTab(final UIDL tabUidl, int index, boolean selected,
+ boolean hidden) {
ICaption c = tb.getTab(index);
if (c == null) {
c = new ICaption(null, client);
}
c.updateCaption(tabUidl);
+ tb.setVisible(index, !hidden);
+
/*
* Force the width of the caption container so the content will not wrap
* and tabs won't be too narrow in certain browsers
ITabsheet.this.iLayout();
(content).updateFromUIDL(contentUIDL, client);
- fixVisibleTabSize();
+ updateOpenTabSize();
ITabsheet.this.removeStyleDependentName("loading");
if (previousVisibleWidget != null) {
DOM.setStyleAttribute(previousVisibleWidget.getElement(),
DOM.setStyleAttribute(contentNode, "height", "");
renderSpace.setHeight(0);
}
- fixVisibleTabSize();
+ updateOpenTabSize();
iLayout();
}
contentNode.getStyle().setProperty("width", contentWidth + "px");
renderSpace.setWidth(contentWidth);
}
- fixVisibleTabSize();
+ updateOpenTabSize();
iLayout();
}
* position: absolute (to work around a firefox flickering bug) we must keep
* this up-to-date by hand.
*/
- private void fixVisibleTabSize() {
+ private void updateOpenTabSize() {
/*
* The overflow=auto element must have a height specified, otherwise it
* will be just as high as the contents and no scrollbars will appear
public void updateCaption(Paintable component, UIDL uidl) {
int i = tp.getWidgetIndex((Widget) component);
ICaption c = (ICaption) captions.get("" + i);
+ boolean visible = c.isVisible();
c.updateCaption(uidl);
+ if (c.isVisible() != visible) {
+ tb.setVisible(i, c.isVisible());
+ }
}
public boolean requestLayout(Set<Paintable> child) {
return true;
}
- fixVisibleTabSize();
+ updateOpenTabSize();
if (renderInformation.updateSize(getElement())) {
/*