]> source.dussan.org Git - vaadin-framework.git/commitdiff
Moved Form child component references to state
authorArtur Signell <artur@vaadin.com>
Wed, 4 Apr 2012 21:43:10 +0000 (00:43 +0300)
committerArtur Signell <artur@vaadin.com>
Wed, 4 Apr 2012 21:43:10 +0000 (00:43 +0300)
src/com/vaadin/terminal/gwt/client/ui/FormConnector.java
src/com/vaadin/ui/Form.java

index 4822ec734d41f82e23477f341f09212bcad96617..0ac6f0cb699618a431eae9231bf5091667dbef82 100644 (file)
@@ -10,6 +10,7 @@ import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.AbstractFieldState;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.ComponentConnector;
+import com.vaadin.terminal.gwt.client.Connector;
 import com.vaadin.terminal.gwt.client.LayoutManager;
 import com.vaadin.terminal.gwt.client.Paintable;
 import com.vaadin.terminal.gwt.client.UIDL;
@@ -19,6 +20,28 @@ import com.vaadin.ui.Form;
 public class FormConnector extends AbstractComponentContainerConnector
         implements Paintable, SimpleManagedLayout {
 
+    public static class FormState extends AbstractFieldState {
+        private Connector layout;
+        private Connector footer;
+
+        public Connector getLayout() {
+            return layout;
+        }
+
+        public void setLayout(Connector layout) {
+            this.layout = layout;
+        }
+
+        public Connector getFooter() {
+            return footer;
+        }
+
+        public void setFooter(Connector footer) {
+            this.footer = footer;
+        }
+
+    }
+
     @Override
     public void init() {
         VForm form = getWidget();
@@ -86,11 +109,10 @@ public class FormConnector extends AbstractComponentContainerConnector
 
         // first render footer so it will be easier to handle relative height of
         // main layout
-        if (uidl.getChildCount() > 1
-                && !uidl.getChildUIDL(1).getTag().equals("actions")) {
+        if (getState().getFooter() != null) {
             // render footer
-            ComponentConnector newFooter = client.getPaintable(uidl
-                    .getChildUIDL(1));
+            ComponentConnector newFooter = (ComponentConnector) getState()
+                    .getFooter();
             Widget newFooterWidget = newFooter.getWidget();
             if (getWidget().footer == null) {
                 getWidget().add(newFooter.getWidget(),
@@ -108,8 +130,8 @@ public class FormConnector extends AbstractComponentContainerConnector
             }
         }
 
-        final UIDL layoutUidl = uidl.getChildUIDL(0);
-        ComponentConnector newLayout = client.getPaintable(layoutUidl);
+        ComponentConnector newLayout = (ComponentConnector) getState()
+                .getLayout();
         Widget newLayoutWidget = newLayout.getWidget();
         if (getWidget().lo == null) {
             // Layout not rendered before
@@ -127,7 +149,7 @@ public class FormConnector extends AbstractComponentContainerConnector
         client.runDescendentsLayout(getWidget());
 
         // We may have actions attached
-        if (uidl.getChildCount() > 1) {
+        if (uidl.getChildCount() >= 1) {
             UIDL childUidl = uidl.getChildByTagName("actions");
             if (childUidl != null) {
                 if (getWidget().shortcutHandler == null) {
@@ -177,8 +199,8 @@ public class FormConnector extends AbstractComponentContainerConnector
     }
 
     @Override
-    public AbstractFieldState getState() {
-        return (AbstractFieldState) super.getState();
+    public FormState getState() {
+        return (FormState) super.getState();
     }
 
 }
index 74607b65d0044e37b0e0c56e7bb331933434c887..be8c64d5e8e307b7e86869e441f9e723be390f2a 100644 (file)
@@ -30,6 +30,7 @@ import com.vaadin.terminal.ErrorMessage;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.UserError;
+import com.vaadin.terminal.gwt.client.ui.FormConnector.FormState;
 
 /**
  * Form component provides easy way of creating and managing sets fields.
@@ -70,11 +71,6 @@ public class Form extends AbstractField<Object> implements Item.Editor,
 
     private Object propertyValue;
 
-    /**
-     * Layout of the form.
-     */
-    private Layout layout;
-
     /**
      * Item connected to this form as datasource.
      */
@@ -133,8 +129,6 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         }
     };
 
-    private Layout formFooter;
-
     /**
      * If this is true, commit implicitly calls setValidationVisible(true).
      */
@@ -191,16 +185,16 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         setWidth(100, UNITS_PERCENTAGE);
     }
 
+    @Override
+    public FormState getState() {
+        return (FormState) super.getState();
+    }
+
     /* Documented in interface */
     @Override
     public void paintContent(PaintTarget target) throws PaintException {
         super.paintContent(target);
 
-        layout.paint(target);
-        if (formFooter != null) {
-            formFooter.paint(target);
-        }
-
         if (ownActionManager != null) {
             ownActionManager.paintActions(null, target);
         }
@@ -587,6 +581,7 @@ public class Form extends AbstractField<Object> implements Item.Editor,
             return;
         }
 
+        Layout layout = getLayout();
         if (layout instanceof CustomLayout) {
             ((CustomLayout) layout).addComponent(field, propertyId.toString());
         } else {
@@ -729,8 +724,8 @@ public class Form extends AbstractField<Object> implements Item.Editor,
      */
     public void setItemDataSource(Item newDataSource, Collection<?> propertyIds) {
 
-        if (layout instanceof GridLayout) {
-            GridLayout gl = (GridLayout) layout;
+        if (getLayout() instanceof GridLayout) {
+            GridLayout gl = (GridLayout) getLayout();
             if (gridlayoutCursorX == -1) {
                 // first setItemDataSource, remember initial cursor
                 gridlayoutCursorX = gl.getCursorX();
@@ -806,25 +801,24 @@ public class Form extends AbstractField<Object> implements Item.Editor,
      * @return the Layout of the form.
      */
     public Layout getLayout() {
-        return layout;
+        return (Layout) getState().getLayout();
     }
 
     /**
      * Sets the layout of the form.
      * 
      * <p>
-     * By default form uses <code>OrderedLayout</code> with <code>form</code>
-     * -style.
+     * If set to null then Form uses a FormLayout by default.
      * </p>
      * 
-     * @param newLayout
-     *            the Layout of the form.
+     * @param layout
+     *            the layout of the form.
      */
-    public void setLayout(Layout newLayout) {
+    public void setLayout(Layout layout) {
 
         // Use orderedlayout by default
-        if (newLayout == null) {
-            newLayout = new FormLayout();
+        if (layout == null) {
+            layout = new FormLayout();
         }
 
         // reset cursor memory
@@ -832,25 +826,25 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         gridlayoutCursorY = -1;
 
         // Move fields from previous layout
-        if (layout != null) {
+        if (getLayout() != null) {
             final Object[] properties = propertyIds.toArray();
             for (int i = 0; i < properties.length; i++) {
                 Field<?> f = getField(properties[i]);
                 detachField(f);
-                if (newLayout instanceof CustomLayout) {
-                    ((CustomLayout) newLayout).addComponent(f,
+                if (layout instanceof CustomLayout) {
+                    ((CustomLayout) layout).addComponent(f,
                             properties[i].toString());
                 } else {
-                    newLayout.addComponent(f);
+                    layout.addComponent(f);
                 }
             }
 
-            layout.setParent(null);
+            getLayout().setParent(null);
         }
 
         // Replace the previous layout
-        newLayout.setParent(this);
-        layout = newLayout;
+        layout.setParent(this);
+        getState().setLayout(layout);
 
         // Hierarchy has changed so we need to repaint (this could be a
         // hierarchy repaint only)
@@ -968,7 +962,7 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         newField.setPropertyDataSource(property);
 
         // Replaces the old field with new one
-        layout.replaceComponent(oldField, newField);
+        getLayout().replaceComponent(oldField, newField);
         fields.put(propertyId, newField);
         newField.addListener(fieldValueChangeListener);
         oldField.removeListener(fieldValueChangeListener);
@@ -984,9 +978,9 @@ public class Form extends AbstractField<Object> implements Item.Editor,
     @Override
     public void attach() {
         super.attach();
-        layout.attach();
-        if (formFooter != null) {
-            formFooter.attach();
+        getLayout().attach();
+        if (getFooter() != null) {
+            getFooter().attach();
         }
     }
 
@@ -998,9 +992,9 @@ public class Form extends AbstractField<Object> implements Item.Editor,
     @Override
     public void detach() {
         super.detach();
-        layout.detach();
-        if (formFooter != null) {
-            formFooter.detach();
+        getLayout().detach();
+        if (getFooter() != null) {
+            getFooter().detach();
         }
     }
 
@@ -1278,25 +1272,27 @@ public class Form extends AbstractField<Object> implements Item.Editor,
      * @return layout rendered below normal form contents.
      */
     public Layout getFooter() {
-        if (formFooter == null) {
-            formFooter = new HorizontalLayout();
-            formFooter.setParent(this);
-        }
-        return formFooter;
+        return (Layout) getState().getFooter();
     }
 
     /**
-     * Sets the layout that is rendered below normal form contens.
+     * Sets the layout that is rendered below normal form contents. Setting this
+     * to null will cause an empty HorizontalLayout to be rendered in the
+     * footer.
      * 
-     * @param newFormFooter
-     *            the new Layout
+     * @param footer
+     *            the new footer layout
      */
-    public void setFooter(Layout newFormFooter) {
-        if (formFooter != null) {
-            formFooter.setParent(null);
+    public void setFooter(Layout footer) {
+        if (getFooter() != null) {
+            getFooter().setParent(null);
+        }
+        if (footer == null) {
+            footer = new HorizontalLayout();
         }
-        formFooter = newFormFooter;
-        formFooter.setParent(this);
+
+        getState().setFooter(footer);
+        footer.setParent(this);
 
         // Hierarchy has changed so we need to repaint (this could be a
         // hierarchy repaint only)
@@ -1393,16 +1389,16 @@ public class Form extends AbstractField<Object> implements Item.Editor,
             }
             i++;
             if (i == 1) {
-                return layout != null ? layout : formFooter;
+                return getLayout() != null ? getLayout() : getFooter();
             } else if (i == 2) {
-                return formFooter;
+                return getFooter();
             }
             return null;
         }
 
         public void remove() {
             if (i == 1) {
-                if (layout != null) {
+                if (getLayout() != null) {
                     setLayout(null);
                     i = 0;
                 } else {
@@ -1424,10 +1420,10 @@ public class Form extends AbstractField<Object> implements Item.Editor,
 
     public int getComponentCount() {
         int count = 0;
-        if (layout != null) {
+        if (getLayout() != null) {
             count++;
         }
-        if (formFooter != null) {
+        if (getFooter() != null) {
             count++;
         }