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<Widget> widgets = new HashSet<Widget>();
- private String height;
-
- private String width = "";
-
HashMap<StackItem, UIDL> lazyUpdateMap = new HashMap<StackItem, UIDL>();
- private RenderSpace renderSpace = new RenderSpace(0, 0, true);
-
StackItem openTab = null;
- boolean rendering = false;
-
int selectedUIDLItemIndex = -1;
RenderInformation renderInformation = new RenderInformation();
}
}
- @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
spaceForOpenItem = 0;
}
- renderSpace.setHeight(spaceForOpenItem);
openTab.setHeight(spaceForOpenItem);
} else {
- renderSpace.setHeight(0);
openTab.setHeightFromWidget();
}
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
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<Widget> 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();
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);
/*
getWidgetForPaintable().renderInformation
.updateSize(getWidgetForPaintable().getElement());
-
- getWidgetForPaintable().rendering = false;
}
@Override
/* Accordion does not render its children's captions */
}
+ public void onResize() {
+ VAccordion accordion = getWidgetForPaintable();
+
+ accordion.updateOpenTabSize();
+
+ if (isUndefinedHeight()) {
+ accordion.openTab.setHeightFromWidget();
+ }
+ accordion.iLayout();
+
+ }
+
}
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;
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;
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
*/
private Widget previousVisibleWidget;
- boolean rendering = false;
-
private String currentStyle;
private void onTabSelected(final int tabIndex) {
}
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() {
}
}
- @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();
}
}
- @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();
* 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
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<Widget> 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);
}
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();
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;
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
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();
getWidgetForPaintable().updateDynamicWidth();
}
- if (!getWidgetForPaintable().isDynamicHeight()) {
+ if (!isUndefinedHeight()) {
// Must update height after the styles have been set
getWidgetForPaintable().updateContentNodeHeight();
getWidgetForPaintable().updateOpenTabSize();
// Ignore, most likely empty tabsheet
}
- getWidgetForPaintable().renderInformation
- .updateSize(getWidgetForPaintable().getElement());
-
getWidgetForPaintable().waitingForResponse = false;
- getWidgetForPaintable().rendering = false;
}
@Override
/* 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();
+
+ }
+
}