]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8500 Properly repaint parent (hierarchy) when the visibility of a child
authorArtur Signell <artur@vaadin.com>
Tue, 20 Mar 2012 10:01:28 +0000 (12:01 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Mar 2012 13:27:52 +0000 (15:27 +0200)
changes

src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/Component.java
src/com/vaadin/ui/Form.java

index 500b5afaaf76266b21de6d48227ba4161d47f66d..db6be1e4b85414f054b0684cb9d7072565e9c459 100644 (file)
@@ -440,11 +440,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
     public void setVisible(boolean visible) {
         if (getState().isVisible() != visible) {
             getState().setVisible(visible);
-            // Instead of requesting repaint normally we
-            // fire the event directly to assure that the
-            // event goes through event in the component might
-            // now be invisible
-            fireRequestRepaintEvent(null);
+            requestRepaint();
+            if (getParent() != null) {
+                // Must always repaint the parent (at least the hierarchy) when
+                // visibility of a child component changes.
+                getParent().requestRepaint();
+            }
         }
     }
 
@@ -641,14 +642,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource
     public void attach() {
         getRoot().componentAttached(this);
         requestRepaint();
-        if (!getState().isVisible()) {
-            /*
-             * Bypass the repaint optimization in childRequestedRepaint method
-             * when attaching. When reattaching (possibly moving) -> must
-             * repaint
-             */
-            fireRequestRepaintEvent(null);
-        }
         if (delayedFocus) {
             focus();
         }
@@ -889,22 +882,13 @@ public abstract class AbstractComponent implements Component, MethodEventSource
 
     /* Documentation copied from interface */
     public void requestRepaint() {
-
-        // The effect of the repaint request is identical to case where a
-        // child requests repaint
-        childRequestedRepaint(null);
-    }
-
-    /* Documentation copied from interface */
-    public void childRequestedRepaint(
-            Collection<RepaintRequestListener> alreadyNotified) {
         // Invisible components (by flag in this particular component) do not
         // need repaints
         if (!getState().isVisible()) {
             return;
         }
 
-        fireRequestRepaintEvent(alreadyNotified);
+        fireRequestRepaintEvent();
     }
 
     /**
@@ -912,31 +896,17 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      * 
      * @param alreadyNotified
      */
-    private void fireRequestRepaintEvent(
-            Collection<RepaintRequestListener> alreadyNotified) {
-        // Notify listeners only once
+    // Notify listeners only once
+    private void fireRequestRepaintEvent() {
         // Notify the listeners
         if (repaintRequestListeners != null
                 && !repaintRequestListeners.isEmpty()) {
             final Object[] listeners = repaintRequestListeners.toArray();
             final RepaintRequestEvent event = new RepaintRequestEvent(this);
             for (int i = 0; i < listeners.length; i++) {
-                if (alreadyNotified == null) {
-                    alreadyNotified = new LinkedList<RepaintRequestListener>();
-                }
-                if (!alreadyNotified.contains(listeners[i])) {
-                    ((RepaintRequestListener) listeners[i])
-                            .repaintRequested(event);
-                    alreadyNotified.add((RepaintRequestListener) listeners[i]);
-                }
+                ((RepaintRequestListener) listeners[i]).repaintRequested(event);
             }
         }
-
-        // Notify the parent
-        final Component parent = getParent();
-        if (parent != null) {
-            parent.childRequestedRepaint(alreadyNotified);
-        }
     }
 
     /* Documentation copied from interface */
index c0c43fcec3d9bd7cd37d67a5ad5615e29cb73640..3fe71dfea1de1cfbfe445fad55790b801a4a8662 100644 (file)
@@ -5,7 +5,6 @@
 package com.vaadin.ui;
 
 import java.io.Serializable;
-import java.util.Collection;
 import java.util.EventListener;
 import java.util.EventObject;
 import java.util.Locale;
@@ -707,33 +706,6 @@ public interface Component extends ClientConnector, Paintable, VariableOwner,
      */
     public ComponentState getState();
 
-    /**
-     * The child components of the component must call this method when they
-     * need repainting. The call must be made even in the case in which the
-     * children sent the repaint request themselves.
-     * 
-     * <p>
-     * A repaint request is ignored if the component is invisible.
-     * </p>
-     * 
-     * <p>
-     * This method is called automatically by {@link AbstractComponent}, which
-     * also provides a default implementation of it. As this is a somewhat
-     * internal feature, it is rarely necessary to reimplement this or call it
-     * explicitly.
-     * </p>
-     * 
-     * @param alreadyNotified
-     *            the collection of repaint request listeners that have been
-     *            already notified by the child. This component should not
-     *            re-notify the listed listeners again. The container given as
-     *            parameter must be modifiable as the component might modify it
-     *            and pass it forward. A {@code null} parameter is interpreted
-     *            as an empty collection.
-     */
-    public void childRequestedRepaint(
-            Collection<RepaintRequestListener> alreadyNotified);
-
     /* Component event framework */
 
     /**
index c39f043b2119f887c511ac87254148818427be23..d66fae76ca655c361e69387c43d92287c70b5775 100644 (file)
@@ -851,6 +851,9 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         newLayout.setParent(this);
         layout = newLayout;
 
+        // Hierarchy has changed so we need to repaint (this could be a
+        // hierarchy repaint only)
+        requestRepaint();
     }
 
     /**
@@ -1293,6 +1296,11 @@ public class Form extends AbstractField<Object> implements Item.Editor,
         }
         formFooter = newFormFooter;
         formFooter.setParent(this);
+
+        // Hierarchy has changed so we need to repaint (this could be a
+        // hierarchy repaint only)
+        requestRepaint();
+
     }
 
     @Override