]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added requestRepaintall helper to AbstractComponentContainer and use the
authorArtur Signell <artur@vaadin.com>
Tue, 20 Mar 2012 12:43:24 +0000 (14:43 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Mar 2012 13:28:05 +0000 (15:28 +0200)
same helper and logic in all component containers including Form,
Table and CustomField

src/com/vaadin/ui/AbstractComponentContainer.java
src/com/vaadin/ui/ComponentContainer.java
src/com/vaadin/ui/CustomField.java
src/com/vaadin/ui/Form.java
src/com/vaadin/ui/HasComponents.java
src/com/vaadin/ui/Table.java

index 66e7c180471bfcf4f14ee6c0812749071f44f851..b597451a57547c0e1a35724e40a30791a5b65b31 100644 (file)
@@ -367,18 +367,23 @@ public abstract class AbstractComponentContainer extends AbstractComponent
     }
 
     public void requestRepaintAll() {
-        requestRepaint();
-        for (Iterator<Component> childIterator = getComponentIterator(); childIterator
-                .hasNext();) {
+        requestRepaintAll(this);
+    }
+
+    /**
+     * Helper that implements the logic needed by requestRepaintAll. Calls
+     * requestRepaintAll/requestRepaint for the component container and all its
+     * children recursively.
+     * 
+     * @param container
+     */
+    public static void requestRepaintAll(HasComponents container) {
+        container.requestRepaint();
+        for (Iterator<Component> childIterator = container
+                .getComponentIterator(); childIterator.hasNext();) {
             Component c = childIterator.next();
-            if (c instanceof Form) {
-                // Form has children in layout, but is not ComponentContainer
-                c.requestRepaint();
-                ((Form) c).getLayout().requestRepaintAll();
-            } else if (c instanceof Table) {
-                ((Table) c).requestRepaintAll();
-            } else if (c instanceof ComponentContainer) {
-                ((ComponentContainer) c).requestRepaintAll();
+            if (c instanceof HasComponents) {
+                requestRepaintAll((HasComponents) c);
             } else {
                 c.requestRepaint();
             }
index 9487d23ee01e70f81bd27e30d9f42460b776ad6a..8182d54b561d8a160c445334040e624bab8392e5 100644 (file)
@@ -68,15 +68,6 @@ public interface ComponentContainer extends HasComponents {
      */
     public int getComponentCount();
 
-    /**
-     * Causes a repaint of this component, and all components below it.
-     * 
-     * This should only be used in special cases, e.g when the state of a
-     * descendant depends on the state of a ancestor.
-     * 
-     */
-    public void requestRepaintAll();
-
     /**
      * Moves all components from an another container into this container. The
      * components are removed from <code>source</code>.
index a462cccfb47491265020e3f0c44ed209c0dadc11..685092904a9a984c4f37418804ea36c9ad89619d 100644 (file)
@@ -121,18 +121,6 @@ public abstract class CustomField<T> extends AbstractField<T> implements
      */
     protected abstract Component initContent();
 
-    private void requestContentRepaint() {
-        if (getParent() == null) {
-            // skip repaint - not yet attached
-            return;
-        }
-        if (getContent() instanceof ComponentContainer) {
-            ((ComponentContainer) getContent()).requestRepaintAll();
-        } else {
-            getContent().requestRepaint();
-        }
-    }
-
     // Size related methods
     // TODO might not be necessary to override but following the pattern from
     // AbstractComponentContainer
@@ -140,13 +128,13 @@ public abstract class CustomField<T> extends AbstractField<T> implements
     @Override
     public void setHeight(float height, Unit unit) {
         super.setHeight(height, unit);
-        requestContentRepaint();
+        requestRepaintAll();
     }
 
     @Override
     public void setWidth(float height, Unit unit) {
         super.setWidth(height, unit);
-        requestContentRepaint();
+        requestRepaintAll();
     }
 
     // ComponentContainer methods
@@ -182,9 +170,7 @@ public abstract class CustomField<T> extends AbstractField<T> implements
     }
 
     public void requestRepaintAll() {
-        requestRepaint();
-
-        requestContentRepaint();
+        AbstractComponentContainer.requestRepaintAll(this);
     }
 
     /**
index d66fae76ca655c361e69387c43d92287c70b5775..1abfefbc582f186c15f79fbbe6c81a42b1714945 100644 (file)
@@ -1417,6 +1417,10 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         return new ComponentIterator();
     }
 
+    public void requestRepaintAll() {
+        AbstractComponentContainer.requestRepaintAll(this);
+    }
+
     public int getComponentCount() {
         int count = 0;
         if (layout != null) {
index de9e392b0d7e0487bf5df65aed7d60c4b4b4d564..eca89ddcd2e6294cb1e4e5b41eaa01d48b805134 100644 (file)
@@ -42,4 +42,13 @@ public interface HasComponents extends Component, Iterable<Component> {
      *         otherwise
      */
     public boolean isComponentVisible(Component childComponent);
+
+    /**
+     * Causes a repaint of this component, and all components below it.
+     * 
+     * This should only be used in special cases, e.g when the state of a
+     * descendant depends on the state of a ancestor.
+     */
+    public void requestRepaintAll();
+
 }
index 079082cc25bf1e650d5fa96229becb1d78f4d882..32d67939e32044eb390ff3ca3ed2bc354e56ba69 100644 (file)
@@ -4460,27 +4460,8 @@ public class Table extends AbstractSelect implements Action.Container,
         }
     }
 
-    // Virtually identical to AbstractCompoenentContainer.setEnabled();
     public void requestRepaintAll() {
-        requestRepaint();
-        if (visibleComponents != null) {
-            for (Iterator<Component> childIterator = visibleComponents
-                    .iterator(); childIterator.hasNext();) {
-                Component c = childIterator.next();
-                if (c instanceof Form) {
-                    // Form has children in layout, but is not
-                    // ComponentContainer
-                    c.requestRepaint();
-                    ((Form) c).getLayout().requestRepaintAll();
-                } else if (c instanceof Table) {
-                    ((Table) c).requestRepaintAll();
-                } else if (c instanceof ComponentContainer) {
-                    ((ComponentContainer) c).requestRepaintAll();
-                } else {
-                    c.requestRepaint();
-                }
-            }
-        }
+        AbstractComponentContainer.requestRepaintAll(this);
     }
 
     /**