diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2012-11-14 13:21:46 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-11-14 13:21:46 +0000 |
commit | 5e0fe9c6ff1e7a17d471b25afbfa6466073a8d28 (patch) | |
tree | 53ae9bd4892cbe0fb090d602dc9066446c1fde03 | |
parent | 0e2a0f54aba0c0d5c1d5e496a50883a3ae0976f3 (diff) | |
parent | 386b7ed018f23794b4232163ec29b1d4e37b78e9 (diff) | |
download | vaadin-framework-5e0fe9c6ff1e7a17d471b25afbfa6466073a8d28.tar.gz vaadin-framework-5e0fe9c6ff1e7a17d471b25afbfa6466073a8d28.zip |
Merge "Updated Form to use hierarchy change event (#9923)"
-rw-r--r-- | client/src/com/vaadin/client/ui/VForm.java | 20 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/form/FormConnector.java | 75 | ||||
-rw-r--r-- | server/src/com/vaadin/ui/Form.java | 14 |
3 files changed, 64 insertions, 45 deletions
diff --git a/client/src/com/vaadin/client/ui/VForm.java b/client/src/com/vaadin/client/ui/VForm.java index 14dc574f71..82e2f7d3aa 100644 --- a/client/src/com/vaadin/client/ui/VForm.java +++ b/client/src/com/vaadin/client/ui/VForm.java @@ -117,6 +117,26 @@ public class VForm extends ComplexPanel implements KeyDownHandler { shortcutHandler.handleKeyboardEvent(Event.as(event.getNativeEvent())); } + void setFooterWidget(Widget footerWidget) { + if (footer != null) { + remove(footer); + } + if (footerWidget != null) { + super.add(footerWidget, footerContainer); + } + footer = footerWidget; + } + + public void setLayoutWidget(Widget newLayoutWidget) { + if (lo != null) { + remove(lo); + } + if (newLayoutWidget != null) { + super.add(newLayoutWidget, fieldContainer); + } + lo = newLayoutWidget; + } + /** For internal use only. May be removed or replaced in the future. */ @Override public void add(Widget child, Element container) { diff --git a/client/src/com/vaadin/client/ui/form/FormConnector.java b/client/src/com/vaadin/client/ui/form/FormConnector.java index bd7ab6ff6e..7516d49e6c 100644 --- a/client/src/com/vaadin/client/ui/form/FormConnector.java +++ b/client/src/com/vaadin/client/ui/form/FormConnector.java @@ -128,50 +128,6 @@ public class FormConnector extends AbstractComponentContainerConnector } } - // first render footer so it will be easier to handle relative height of - // main layout - if (getState().footer != null) { - // render footer - ComponentConnector newFooter = (ComponentConnector) getState().footer; - Widget newFooterWidget = newFooter.getWidget(); - if (getWidget().footer == null) { - getLayoutManager().addElementResizeListener( - newFooterWidget.getElement(), footerResizeListener); - getWidget().add(newFooter.getWidget(), - getWidget().footerContainer); - getWidget().footer = newFooterWidget; - } else if (newFooter != getWidget().footer) { - getLayoutManager().removeElementResizeListener( - getWidget().footer.getElement(), footerResizeListener); - getLayoutManager().addElementResizeListener( - newFooterWidget.getElement(), footerResizeListener); - getWidget().remove(getWidget().footer); - getWidget().add(newFooter.getWidget(), - getWidget().footerContainer); - } - getWidget().footer = newFooterWidget; - } else { - if (getWidget().footer != null) { - getLayoutManager().removeElementResizeListener( - getWidget().footer.getElement(), footerResizeListener); - getWidget().remove(getWidget().footer); - getWidget().footer = null; - } - } - - ComponentConnector newLayout = (ComponentConnector) getState().layout; - Widget newLayoutWidget = newLayout.getWidget(); - if (getWidget().lo == null) { - // Layout not rendered before - getWidget().lo = newLayoutWidget; - getWidget().add(newLayoutWidget, getWidget().fieldContainer); - } else if (getWidget().lo != newLayoutWidget) { - // Layout has changed - getWidget().remove(getWidget().lo); - getWidget().lo = newLayoutWidget; - getWidget().add(newLayoutWidget, getWidget().fieldContainer); - } - // also recalculates size of the footer if undefined size form - see // #3710 client.runDescendentsLayout(getWidget()); @@ -216,9 +172,38 @@ public class FormConnector extends AbstractComponentContainerConnector return (FormState) super.getState(); } + private ComponentConnector getFooter() { + return (ComponentConnector) getState().footer; + } + + private ComponentConnector getLayout() { + return (ComponentConnector) getState().layout; + } + @Override public void onConnectorHierarchyChange( ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { - // TODO Move code from updateFromUIDL to this method + Widget newFooterWidget = null; + ComponentConnector footer = getFooter(); + + if (footer != null) { + newFooterWidget = footer.getWidget(); + Widget currentFooter = getWidget().footer; + if (currentFooter != null) { + // Remove old listener + getLayoutManager().removeElementResizeListener( + currentFooter.getElement(), footerResizeListener); + } + getLayoutManager().addElementResizeListener( + newFooterWidget.getElement(), footerResizeListener); + } + getWidget().setFooterWidget(newFooterWidget); + + Widget newLayoutWidget = null; + ComponentConnector newLayout = getLayout(); + if (newLayout != null) { + newLayoutWidget = newLayout.getWidget(); + } + getWidget().setLayoutWidget(newLayoutWidget); } } diff --git a/server/src/com/vaadin/ui/Form.java b/server/src/com/vaadin/ui/Form.java index 9668eaf914..94a9f9b73a 100644 --- a/server/src/com/vaadin/ui/Form.java +++ b/server/src/com/vaadin/ui/Form.java @@ -1378,4 +1378,18 @@ public class Form extends AbstractField<Object> implements Item.Editor, public boolean isComponentVisible(Component childComponent) { return true; }; + + @Override + public void setVisible(boolean visible) { + if (isVisible() == visible) { + return; + } + + super.setVisible(visible); + // If the visibility state is toggled it might affect all children + // aswell, e.g. make container visible should make children visible if + // they were only hidden because the container was hidden. + markAsDirtyRecursive(); + } + } |