package com.vaadin.terminal.gwt.client.ui;
-import java.util.Set;
-
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
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.RenderInformation;
-import com.vaadin.terminal.gwt.client.RenderSpace;
-import com.vaadin.terminal.gwt.client.Util;
-import com.vaadin.terminal.gwt.client.VConsole;
import com.vaadin.terminal.gwt.client.VErrorMessage;
-public class VForm extends ComplexPanel implements Container, KeyDownHandler {
+public class VForm extends ComplexPanel implements KeyDownHandler {
protected String id;
- private String height = "";
-
- private String width = "";
-
public static final String CLASSNAME = "v-form";
Widget lo;
ApplicationConnection client;
- private RenderInformation renderInformation = new RenderInformation();
-
- private int borderPaddingHorizontal = -1;
-
- boolean rendering = false;
-
ShortcutActionHandler shortcutHandler;
HandlerRegistration keyDownRegistration;
fieldSet.appendChild(desc); // Adding description for initial padding
// measurements, removed later if no
// description is set
+ fieldContainer.setClassName(CLASSNAME + "-content");
fieldSet.appendChild(fieldContainer);
errorMessage.setVisible(false);
errorMessage.setStyleName(CLASSNAME + "-errormessage");
fieldSet.appendChild(footerContainer);
}
- public void updateSize() {
-
- renderInformation.updateSize(getElement());
-
- renderInformation.setContentAreaHeight(renderInformation
- .getRenderedSize().getHeight() - getSpaceConsumedVertically());
- renderInformation.setContentAreaWidth(renderInformation
- .getRenderedSize().getWidth() - borderPaddingHorizontal);
- }
-
- public RenderSpace getAllocatedSpace(Widget child) {
- if (child == lo) {
- return renderInformation.getContentAreaSize();
- } else if (child == footer) {
- return new RenderSpace(renderInformation.getContentAreaSize()
- .getWidth(), 0);
- } else {
- VConsole.error("Invalid child requested RenderSpace information");
- return null;
- }
- }
-
- public boolean hasChildComponent(Widget component) {
- return component != null && (component == lo || component == footer);
- }
-
- public void replaceChildComponent(Widget oldComponent, Widget newComponent) {
- if (!hasChildComponent(oldComponent)) {
- throw new IllegalArgumentException(
- "Old component is not inside this Container");
- }
- remove(oldComponent);
- if (oldComponent == lo) {
- lo = newComponent;
- add(newComponent, fieldContainer);
- } else {
- footer = newComponent;
- add(newComponent, footerContainer);
- }
-
- }
-
- public boolean requestLayout(Set<Widget> child) {
-
- if (height != null && !"".equals(height) && width != null
- && !"".equals(width)) {
- /*
- * If the height and width has been specified the child components
- * cannot make the size of the layout change
- */
-
- return true;
- }
-
- if (renderInformation.updateSize(getElement())) {
- return false;
- } else {
- return true;
- }
-
- }
-
- @Override
- public void setHeight(String height) {
- if (this.height.equals(height)) {
- return;
- }
-
- this.height = height;
- super.setHeight(height);
-
- updateSize();
- }
-
- /**
- * @return pixels consumed by decoration, captions, descrioptiosn etc.. In
- * other words space, not used by the actual layout in form.
- */
- private int getSpaceConsumedVertically() {
- int offsetHeight2 = fieldSet.getOffsetHeight();
- int offsetHeight3 = fieldContainer.getOffsetHeight();
- int borderPadding = offsetHeight2 - offsetHeight3;
- return borderPadding;
- }
-
- @Override
- public void setWidth(String width) {
- if (borderPaddingHorizontal < 0) {
- // measure excess size lazily after stylename setting, but before
- // setting width
- int ow = getOffsetWidth();
- int dow = desc.getOffsetWidth();
- borderPaddingHorizontal = ow - dow;
- }
- if (Util.equals(this.width, width)) {
- return;
- }
-
- this.width = width;
- super.setWidth(width);
-
- updateSize();
-
- if (!rendering && height.equals("")) {
- // Width might affect height
- Util.updateRelativeChildrenAndSendSizeUpdateEvent(client, this,
- this);
- }
- }
-
public void onKeyDown(KeyDownEvent event) {
shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent()));
}
package com.vaadin.terminal.gwt.client.ui;
import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.MeasuredSize;
import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.VPaintableMap;
import com.vaadin.terminal.gwt.client.VPaintableWidget;
-public class VFormPaintable extends VAbstractPaintableWidgetContainer {
+public class VFormPaintable extends VAbstractPaintableWidgetContainer implements
+ ResizeRequired {
+
+ public VFormPaintable() {
+ VForm form = getWidgetForPaintable();
+ MeasuredSize measuredSize = getMeasuredSize();
+ measuredSize.registerDependency(form.footerContainer);
+ }
@Override
protected boolean delegateCaptionHandling() {
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- getWidgetForPaintable().rendering = true;
getWidgetForPaintable().client = client;
getWidgetForPaintable().id = uidl.getId();
super.updateFromUIDL(uidl, client);
if (!isRealUpdate(uidl)) {
- getWidgetForPaintable().rendering = false;
return;
}
}
}
- getWidgetForPaintable().updateSize();
-
// first render footer so it will be easier to handle relative height of
// main layout
if (uidl.getChildCount() > 1
}
getWidgetForPaintable().footer = newFooterWidget;
newFooter.updateFromUIDL(uidl.getChildUIDL(1), client);
- // needed for the main layout to know the space it has available
- getWidgetForPaintable().updateSize();
} else {
if (getWidgetForPaintable().footer != null) {
getWidgetForPaintable().remove(getWidgetForPaintable().footer);
client.unregisterPaintable(VPaintableMap.get(getConnection())
.getPaintable(getWidgetForPaintable().footer));
- // needed for the main layout to know the space it has available
- getWidgetForPaintable().updateSize();
}
}
// also recalculates size of the footer if undefined size form - see
// #3710
- getWidgetForPaintable().updateSize();
client.runDescendentsLayout(getWidgetForPaintable());
// We may have actions attached
getWidgetForPaintable().shortcutHandler = null;
getWidgetForPaintable().keyDownRegistration = null;
}
-
- getWidgetForPaintable().rendering = false;
}
public void updateCaption(VPaintableWidget component, UIDL uidl) {
return GWT.create(VForm.class);
}
+ public void onResize() {
+ MeasuredSize measuredSize = getMeasuredSize();
+ VForm form = getWidgetForPaintable();
+
+ int footerHeight = measuredSize
+ .getDependencyOuterHeight(form.footerContainer);
+ form.fieldContainer.getStyle().setPaddingBottom(footerHeight, Unit.PX);
+ form.footerContainer.getStyle().setMarginTop(-footerHeight, Unit.PX);
+ }
+
}