]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #5955. A bit more intelligent removal of fields from Form + a method that can...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 5 Nov 2010 12:20:07 +0000 (12:20 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 5 Nov 2010 12:20:07 +0000 (12:20 +0000)
svn changeset:15880/svn branch:6.5

src/com/vaadin/ui/Form.java

index 0e487da603f55db0437429b4cfc90cdeb7c6c9a2..8aa06d34cc8f982e3d7df395ca2547361215654c 100644 (file)
@@ -639,7 +639,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
         if (field != null) {
             propertyIds.remove(id);
             fields.remove(id);
-            layout.removeComponent(field);
+            detachField(field);
             field.removeListener(fieldValueChangeListener);
             return true;
         }
@@ -647,6 +647,25 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
         return false;
     }
 
+    /**
+     * Called when a form field is detached from a Form. Typically when a new
+     * Item is assigned to Form via {@link #setItemDataSource(Item)} *
+     * <p>
+     * Override this method to control how the fields are removed from the
+     * layout.
+     * </p>
+     * 
+     * 
+     * @param field
+     *            the field to be detached from the forms layout.
+     */
+    protected void detachField(final Field field) {
+        Component p = field.getParent();
+        if (p instanceof ComponentContainer) {
+            ((ComponentContainer) p).removeComponent(field);
+        }
+    }
+
     /**
      * Removes all properties and fields from the form.
      * 
@@ -781,7 +800,7 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
             final Object[] properties = propertyIds.toArray();
             for (int i = 0; i < properties.length; i++) {
                 Field f = getField(properties[i]);
-                layout.removeComponent(f);
+                detachField(f);
                 if (newLayout instanceof CustomLayout) {
                     ((CustomLayout) newLayout).addComponent(f,
                             properties[i].toString());