]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated Form to use hierarchy change event (#9923) 51/251/2
authorArtur Signell <artur@vaadin.com>
Mon, 12 Nov 2012 17:09:14 +0000 (19:09 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 14 Nov 2012 13:20:43 +0000 (15:20 +0200)
Change-Id: I33475b5445b4f4724d5af84206d22d0c8e71dad1

client/src/com/vaadin/client/ui/VForm.java
client/src/com/vaadin/client/ui/form/FormConnector.java
server/src/com/vaadin/ui/Form.java

index 14dc574f71920f7cbb8050630599cdf181918841..82e2f7d3aa65c7433edbb9bb797e0b4c2ab038cc 100644 (file)
@@ -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) {
index bd7ab6ff6e354154eb45392ada22bebab7ae448e..7516d49e6ce8c3f774be6f61741ef42e10bb7e50 100644 (file)
@@ -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);
     }
 }
index 9668eaf914d2016b0ed8f1df1eaee119fc6638dc..94a9f9b73a49b25743198562a9d70b82a4840122 100644 (file)
@@ -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();
+    }
+
 }