From d5c71a02a152c259deab1c32e97c9c36f64aac3a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 14 Feb 2012 09:26:39 +0200 Subject: [PATCH] FormLayout without calculations (#8313) --- .../terminal/gwt/client/ui/VFormLayout.java | 147 +----------------- .../gwt/client/ui/VFormLayoutPaintable.java | 5 - 2 files changed, 8 insertions(+), 144 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java index 6d3072f407..be8f5736af 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayout.java @@ -8,7 +8,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Set; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -21,12 +20,9 @@ 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.Container; import com.vaadin.terminal.gwt.client.Focusable; -import com.vaadin.terminal.gwt.client.RenderSpace; import com.vaadin.terminal.gwt.client.StyleConstants; import com.vaadin.terminal.gwt.client.UIDL; -import com.vaadin.terminal.gwt.client.Util; import com.vaadin.terminal.gwt.client.VPaintableMap; import com.vaadin.terminal.gwt.client.VPaintableWidget; import com.vaadin.terminal.gwt.client.VTooltip; @@ -34,18 +30,13 @@ import com.vaadin.terminal.gwt.client.VTooltip; /** * Two col Layout that places caption on left col and field on right col */ -public class VFormLayout extends SimplePanel implements Container { +public class VFormLayout extends SimplePanel { private final static String CLASSNAME = "v-formlayout"; ApplicationConnection client; VFormLayoutTable table; - private String width = ""; - private String height = ""; - - boolean rendering = false; - public VFormLayout() { super(); setStyleName(CLASSNAME); @@ -143,14 +134,19 @@ public class VFormLayout extends SimplePanel implements Container { CLASSNAME + "-captioncell"); setWidget(i, COLUMN_CAPTION, caption); - setContentWidth(i); - getCellFormatter().setStyleName(i, COLUMN_ERRORFLAG, CLASSNAME + "-errorcell"); setWidget(i, COLUMN_ERRORFLAG, error); childPaintable.updateFromUIDL(childUidl, client); + // Update cell width when isRelativeWidth has been udpated + if (childPaintable.isRelativeWidth()) { + getCellFormatter().setWidth(i, COLUMN_WIDGET, "100%"); + } else { + getCellFormatter().setWidth(i, COLUMN_WIDGET, null); + } + String rowstyles = CLASSNAME + "-row"; if (i == 0) { rowstyles += " " + CLASSNAME + "-firstrow"; @@ -181,55 +177,6 @@ public class VFormLayout extends SimplePanel implements Container { } } - public void setContentWidths() { - for (int row = 0; row < getRowCount(); row++) { - setContentWidth(row); - } - } - - private void setContentWidth(int row) { - String width = ""; - if (!isDynamicWidth()) { - width = "100%"; - } - getCellFormatter().setWidth(row, COLUMN_WIDGET, width); - } - - public void replaceChildComponent(Widget oldComponent, - Widget newComponent) { - int i; - for (i = 0; i < getRowCount(); i++) { - Widget candidate = getWidget(i, COLUMN_WIDGET); - if (oldComponent == candidate) { - VPaintableMap paintableMap = VPaintableMap.get(client); - VPaintableWidget oldPaintable = paintableMap - .getPaintable(oldComponent); - VPaintableWidget newPaintable = paintableMap - .getPaintable(newComponent); - Caption oldCap = widgetToCaption.get(oldComponent); - final Caption newCap = new Caption(newPaintable, client); - newCap.addClickHandler(this); - newCap.setStyleName(oldCap.getStyleName()); - widgetToCaption.put(newComponent, newCap); - ErrorFlag error = widgetToError.get(newComponent); - if (error == null) { - error = new ErrorFlag(); - widgetToError.put(newComponent, error); - } - - setWidget(i, COLUMN_CAPTION, newCap); - setWidget(i, COLUMN_ERRORFLAG, error); - setWidget(i, COLUMN_WIDGET, newComponent); - break; - } - } - - } - - public boolean hasChildComponent(Widget component) { - return widgetToCaption.containsKey(component); - } - public void updateCaption(VPaintableWidget paintable, UIDL uidl) { final Caption c = widgetToCaption.get(paintable .getWidgetForPaintable()); @@ -244,21 +191,6 @@ public class VFormLayout extends SimplePanel implements Container { } - public int getAllocatedWidth(Widget child, int availableWidth) { - Caption caption = widgetToCaption.get(child); - ErrorFlag error = widgetToError.get(child); - int width = availableWidth; - - if (caption != null) { - width -= DOM.getParent(caption.getElement()).getOffsetWidth(); - } - if (error != null) { - width -= DOM.getParent(error.getElement()).getOffsetWidth(); - } - - return width; - } - /* * (non-Javadoc) * @@ -279,18 +211,6 @@ public class VFormLayout extends SimplePanel implements Container { } } - public boolean isDynamicWidth() { - return width.equals(""); - } - - public boolean hasChildComponent(Widget component) { - return table.hasChildComponent(component); - } - - public void replaceChildComponent(Widget oldComponent, Widget newComponent) { - table.replaceChildComponent(oldComponent, newComponent); - } - public class Caption extends HTML { public static final String CLASSNAME = "v-caption"; @@ -475,55 +395,4 @@ public class VFormLayout extends SimplePanel implements Container { } } - - public boolean requestLayout(Set children) { - if (height.equals("") || width.equals("")) { - // A dynamic size might change due to children changes - return false; - } - - return true; - } - - public RenderSpace getAllocatedSpace(Widget child) { - int width = 0; - int height = 0; - - if (!this.width.equals("")) { - int availableWidth = getOffsetWidth(); - width = table.getAllocatedWidth(child, availableWidth); - } - - return new RenderSpace(width, height, false); - } - - @Override - public void setHeight(String height) { - if (this.height.equals(height)) { - return; - } - - this.height = height; - super.setHeight(height); - } - - @Override - public void setWidth(String width) { - if (this.width.equals(width)) { - return; - } - - this.width = width; - super.setWidth(width); - - if (!rendering) { - table.setContentWidths(); - if (height.equals("")) { - // Width might affect height - Util.updateRelativeChildrenAndSendSizeUpdateEvent(client, this, - this); - } - } - } - } diff --git a/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java index 8769466ce4..8e30bdb997 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VFormLayoutPaintable.java @@ -12,19 +12,14 @@ import com.vaadin.terminal.gwt.client.VPaintableWidget; public class VFormLayoutPaintable extends VAbstractPaintableWidgetContainer { @Override public void updateFromUIDL(UIDL uidl, ApplicationConnection client) { - getWidgetForPaintable().rendering = true; - getWidgetForPaintable().client = client; super.updateFromUIDL(uidl, client); if (!isRealUpdate(uidl)) { - getWidgetForPaintable().rendering = false; return; } getWidgetForPaintable().table.updateFromUIDL(uidl, client); - - getWidgetForPaintable().rendering = false; } public void updateCaption(VPaintableWidget component, UIDL uidl) { -- 2.39.5