From: Leif Åstrand Date: Tue, 14 Feb 2012 10:34:56 +0000 (+0200) Subject: Update tab sheet and accordion to work with MeasureManager (#8313) X-Git-Tag: 7.0.0.alpha2~434^2~52 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2cc2f2df61308eba106f6116e02f21ddbfdbf22f;p=vaadin-framework.git Update tab sheet and accordion to work with MeasureManager (#8313) --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java index 3e4f21477b..ed1acc3849 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordion.java @@ -15,34 +15,23 @@ import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.Widget; -import com.vaadin.terminal.gwt.client.ContainerResizedListener; import com.vaadin.terminal.gwt.client.RenderInformation; -import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VCaption; import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; -public class VAccordion extends VTabsheetBase implements - ContainerResizedListener { +public class VAccordion extends VTabsheetBase { public static final String CLASSNAME = "v-accordion"; private Set widgets = new HashSet(); - private String height; - - private String width = ""; - HashMap lazyUpdateMap = new HashMap(); - private RenderSpace renderSpace = new RenderSpace(0, 0, true); - StackItem openTab = null; - boolean rendering = false; - int selectedUIDLItemIndex = -1; RenderInformation renderInformation = new RenderInformation(); @@ -202,58 +191,19 @@ public class VAccordion extends VTabsheetBase implements } } - @Override - public void setWidth(String width) { - if (this.width.equals(width)) { - return; - } - - Util.setWidthExcludingPaddingAndBorder(this, width, 2); - this.width = width; - if (!rendering) { - updateOpenTabSize(); - - if (isDynamicHeight()) { - Util.updateRelativeChildrenAndSendSizeUpdateEvent(client, - openTab, this); - updateOpenTabSize(); - } - - if (isDynamicHeight()) { - openTab.setHeightFromWidget(); - } - iLayout(); - } - } - - @Override - public void setHeight(String height) { - Util.setHeightExcludingPaddingAndBorder(this, height, 2); - this.height = height; - - if (!rendering) { - updateOpenTabSize(); - } - - } - /** * Sets the size of the open tab */ - private void updateOpenTabSize() { + void updateOpenTabSize() { if (openTab == null) { - renderSpace.setHeight(0); - renderSpace.setWidth(0); return; } // WIDTH if (!isDynamicWidth()) { - int w = getOffsetWidth(); - openTab.setWidth(w); - renderSpace.setWidth(w); + openTab.setWidth("100%"); } else { - renderSpace.setWidth(0); + openTab.setWidth(null); } // HEIGHT @@ -277,10 +227,8 @@ public class VAccordion extends VTabsheetBase implements spaceForOpenItem = 0; } - renderSpace.setHeight(spaceForOpenItem); openTab.setHeight(spaceForOpenItem); } else { - renderSpace.setHeight(0); openTab.setHeightFromWidget(); } @@ -512,12 +460,16 @@ public class VAccordion extends VTabsheetBase implements clear(); } - public boolean isDynamicHeight() { - return height == null || height.equals(""); + boolean isDynamicWidth() { + VPaintableWidget paintable = VPaintableMap.get(client).getPaintable( + this); + return paintable.isUndefinedWidth(); } - public boolean isDynamicWidth() { - return width == null || width.equals(""); + boolean isDynamicHeight() { + VPaintableWidget paintable = VPaintableMap.get(client).getPaintable( + this); + return paintable.isUndefinedHeight(); } @Override @@ -526,65 +478,6 @@ public class VAccordion extends VTabsheetBase implements return widgets.iterator(); } - public boolean hasChildComponent(Widget component) { - for (Widget w : widgets) { - if (w == component) { - return true; - } - } - return false; - } - - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - for (Widget w : getChildren()) { - StackItem item = (StackItem) w; - if (item.getChildWidget() == oldComponent) { - item.replaceWidget(newComponent); - return; - } - } - } - - public boolean requestLayout(Set children) { - 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 - */ - // layout size change may affect its available space (scrollbars) - for (Widget widget : children) { - client.handleComponentRelativeSize(widget); - } - - return true; - } - - updateOpenTabSize(); - - if (renderInformation.updateSize(getElement())) { - /* - * Size has changed so we let the child components know about the - * new size. - */ - iLayout(); - // TODO Check if this is needed - client.runDescendentsLayout(this); - - 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 renderSpace; - } - @Override protected int getTabCount() { return getWidgetCount(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java index 2ed356127c..86ef5d1c96 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VAccordionPaintable.java @@ -12,11 +12,11 @@ import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.ui.VAccordion.StackItem; -public class VAccordionPaintable extends VTabsheetBasePaintable { +public class VAccordionPaintable extends VTabsheetBasePaintable implements + ResizeRequired { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - getWidgetForPaintable().rendering = true; getWidgetForPaintable().selectedUIDLItemIndex = -1; super.updateFromUIDL(uidl, client); /* @@ -50,8 +50,6 @@ public class VAccordionPaintable extends VTabsheetBasePaintable { getWidgetForPaintable().renderInformation .updateSize(getWidgetForPaintable().getElement()); - - getWidgetForPaintable().rendering = false; } @Override @@ -68,4 +66,16 @@ public class VAccordionPaintable extends VTabsheetBasePaintable { /* Accordion does not render its children's captions */ } + public void onResize() { + VAccordion accordion = getWidgetForPaintable(); + + accordion.updateOpenTabSize(); + + if (isUndefinedHeight()) { + accordion.openTab.setHeightFromWidget(); + } + accordion.iLayout(); + + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java index 809c1a0380..db74a0fc20 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheet.java @@ -5,7 +5,6 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.Iterator; -import java.util.Set; import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.DivElement; @@ -23,7 +22,6 @@ import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.BrowserInfo; -import com.vaadin.terminal.gwt.client.RenderInformation; import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.TooltipInfo; import com.vaadin.terminal.gwt.client.UIDL; @@ -484,13 +482,8 @@ public class VTabsheet extends VTabsheetBase { final VTabsheetPanel tp = new VTabsheetPanel(); private final Element contentNode, deco; - private String height; - private String width; - boolean waitingForResponse; - final RenderInformation renderInformation = new RenderInformation(); - /** * Previous visible widget is set invisible with CSS (not display: none, but * visibility: hidden), to avoid flickering during render process. Normal @@ -498,8 +491,6 @@ public class VTabsheet extends VTabsheetBase { */ private Widget previousVisibleWidget; - boolean rendering = false; - private String currentStyle; private void onTabSelected(final int tabIndex) { @@ -547,11 +538,15 @@ public class VTabsheet extends VTabsheetBase { } boolean isDynamicWidth() { - return width == null || width.equals(""); + VPaintableWidget paintable = VPaintableMap.get(client).getPaintable( + this); + return paintable.isUndefinedWidth(); } boolean isDynamicHeight() { - return height == null || height.equals(""); + VPaintableWidget paintable = VPaintableMap.get(client).getPaintable( + this); + return paintable.isUndefinedHeight(); } public VTabsheet() { @@ -857,22 +852,8 @@ public class VTabsheet extends VTabsheetBase { } } - @Override - public void setHeight(String height) { - super.setHeight(height); - this.height = height; - updateContentNodeHeight(); - - if (!rendering) { - updateOpenTabSize(); - iLayout(); - // TODO Check if this is needed - client.runDescendentsLayout(this); - } - } - void updateContentNodeHeight() { - if (height != null && !"".equals(height)) { + if (!isDynamicHeight()) { int contentHeight = getOffsetHeight(); contentHeight -= DOM.getElementPropertyInt(deco, "offsetHeight"); contentHeight -= tb.getOffsetHeight(); @@ -889,45 +870,6 @@ public class VTabsheet extends VTabsheetBase { } } - @Override - public void setWidth(String width) { - if ((this.width == null && width.equals("")) - || (this.width != null && this.width.equals(width))) { - return; - } - - super.setWidth(width); - if (width.equals("")) { - width = null; - } - this.width = width; - if (width == null) { - renderSpace.setWidth(0); - contentNode.getStyle().setProperty("width", ""); - } else { - int contentWidth = getOffsetWidth() - getContentAreaBorderWidth(); - if (contentWidth < 0) { - contentWidth = 0; - } - contentNode.getStyle().setProperty("width", contentWidth + "px"); - renderSpace.setWidth(contentWidth); - } - - if (!rendering) { - if (isDynamicHeight()) { - Util.updateRelativeChildrenAndSendSizeUpdateEvent(client, tp, - this); - } - - updateOpenTabSize(); - iLayout(); - // TODO Check if this is needed - client.runDescendentsLayout(this); - - } - - } - public void iLayout() { updateTabScroller(); tp.runWebkitOverflowAutoFix(); @@ -968,8 +910,10 @@ public class VTabsheet extends VTabsheetBase { * Layouts the tab-scroller elements, and applies styles. */ private void updateTabScroller() { - if (width != null) { - DOM.setStyleAttribute(tabs, "width", width); + if (!isDynamicWidth()) { + VPaintableWidget paintable = VPaintableMap.get(client) + .getPaintable(this); + DOM.setStyleAttribute(tabs, "width", paintable.getDefinedWidth()); } // Make sure scrollerIndex is valid @@ -1050,55 +994,9 @@ public class VTabsheet extends VTabsheetBase { 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) { - tp.replaceComponent(oldComponent, newComponent); - } - - public boolean requestLayout(Set children) { - 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 - */ - // layout size change may affect its available space (scrollbars) - for (Widget widget : children) { - client.handleComponentRelativeSize(widget); - } - return true; - } - - updateOpenTabSize(); - - if (renderInformation.updateSize(getElement())) { - /* - * Size has changed so we let the child components know about the - * new size. - */ - iLayout(); - client.runDescendentsLayout(this); - - return false; - } else { - /* - * Size has not changed so we do not need to propagate the event - * further - */ - return true; - } - - } - private int borderW = -1; - private int getContentAreaBorderWidth() { + int getContentAreaBorderWidth() { if (borderW < 0) { borderW = Util.measureHorizontalBorder(contentNode); } @@ -1107,11 +1005,6 @@ public class VTabsheet extends VTabsheetBase { private final RenderSpace renderSpace = new RenderSpace(0, 0, true); - public RenderSpace getAllocatedSpace(Widget child) { - // All tabs have equal amount of space allocated - return renderSpace; - } - @Override protected int getTabCount() { return tb.getTabCount(); diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java index 582452988a..8552f45bd9 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetBase.java @@ -12,11 +12,10 @@ 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.vaadin.terminal.gwt.client.ApplicationConnection; -import com.vaadin.terminal.gwt.client.Container; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VPaintableWidget; -abstract class VTabsheetBase extends ComplexPanel implements Container { +abstract class VTabsheetBase extends ComplexPanel { String id; ApplicationConnection client; diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java index 29e3e3d95c..7379362b3f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VTabsheetPaintable.java @@ -10,11 +10,11 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VPaintableWidget; -public class VTabsheetPaintable extends VTabsheetBasePaintable { +public class VTabsheetPaintable extends VTabsheetBasePaintable implements + ResizeRequired { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - getWidgetForPaintable().rendering = true; if (isRealUpdate(uidl)) { // Handle stylename changes before generics (might affect size @@ -24,12 +24,11 @@ public class VTabsheetPaintable extends VTabsheetBasePaintable { super.updateFromUIDL(uidl, client); if (!isRealUpdate(uidl)) { - getWidgetForPaintable().rendering = false; return; } // tabs; push or not - if (!getWidgetForPaintable().isDynamicWidth()) { + if (!isUndefinedWidth()) { // FIXME: This makes tab sheet tabs go to 1px width on every update // and then back to original width // update width later, in updateTabScroller(); @@ -44,7 +43,7 @@ public class VTabsheetPaintable extends VTabsheetBasePaintable { getWidgetForPaintable().updateDynamicWidth(); } - if (!getWidgetForPaintable().isDynamicHeight()) { + if (!isUndefinedHeight()) { // Must update height after the styles have been set getWidgetForPaintable().updateContentNodeHeight(); getWidgetForPaintable().updateOpenTabSize(); @@ -61,11 +60,7 @@ public class VTabsheetPaintable extends VTabsheetBasePaintable { // Ignore, most likely empty tabsheet } - getWidgetForPaintable().renderInformation - .updateSize(getWidgetForPaintable().getElement()); - getWidgetForPaintable().waitingForResponse = false; - getWidgetForPaintable().rendering = false; } @Override @@ -82,4 +77,26 @@ public class VTabsheetPaintable extends VTabsheetBasePaintable { /* Tabsheet does not render its children's captions */ } + public void onResize() { + VTabsheet tabsheet = getWidgetForPaintable(); + + tabsheet.updateContentNodeHeight(); + + if (isUndefinedWidth()) { + tabsheet.contentNode.getStyle().setProperty("width", ""); + } else { + int contentWidth = tabsheet.getOffsetWidth() + - tabsheet.getContentAreaBorderWidth(); + if (contentWidth < 0) { + contentWidth = 0; + } + tabsheet.contentNode.getStyle().setProperty("width", + contentWidth + "px"); + } + + tabsheet.updateOpenTabSize(); + tabsheet.iLayout(); + + } + }