]> source.dussan.org Git - vaadin-framework.git/commitdiff
setEnable(false) also disables descendants, for #677 - Table still not fixed.
authorMarc Englund <marc.englund@itmill.com>
Thu, 25 Sep 2008 11:38:18 +0000 (11:38 +0000)
committerMarc Englund <marc.englund@itmill.com>
Thu, 25 Sep 2008 11:38:18 +0000 (11:38 +0000)
svn changeset:5513/svn branch:trunk

src/com/itmill/toolkit/ui/AbstractComponent.java
src/com/itmill/toolkit/ui/AbstractComponentContainer.java
src/com/itmill/toolkit/ui/Component.java
src/com/itmill/toolkit/ui/ComponentContainer.java
src/com/itmill/toolkit/ui/Form.java
src/com/itmill/toolkit/ui/Panel.java

index 734204bd9f1b7d40afe198b77bf8e009d8e23efe..a4408055e42ec2a92e4f4dbcda24279e44da1709 100644 (file)
@@ -65,11 +65,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      */
     private boolean enabled = true;
 
-    /**
-     * Has the component been disabled by the container
-     */
-    private boolean disabledByContainer = false;
-
     /**
      * Is the component visible (it is rendered).
      */
@@ -316,7 +311,7 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      * here, we use the default documentation from implemented interface.
      */
     public boolean isEnabled() {
-        return enabled && !disabledByContainer && isVisible();
+        return enabled && (parent == null || parent.isEnabled()) && isVisible();
     }
 
     /*
@@ -325,23 +320,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      */
     public void setEnabled(boolean enabled) {
         if (this.enabled != enabled) {
+            boolean wasEnabled = isEnabled();
             this.enabled = enabled;
-            requestRepaint();
-        }
-    }
-
-    /**
-     * Enable or disable the component by the container. Normally used to
-     * disable the component when the container is disabled without altering the
-     * actual enabled state of the component.
-     * 
-     * @param disabledByContainer
-     *            Should the component be disabled
-     */
-    public void setDisabledByContainer(boolean disabledByContainer) {
-        if (disabledByContainer != this.disabledByContainer) {
-            this.disabledByContainer = disabledByContainer;
-            requestRepaint();
+            // don't repaint if ancestor is disabled
+            if (wasEnabled != isEnabled()) {
+                requestRepaint();
+            }
         }
     }
 
index 56febe381561755b5c393452d5aff6f287794202..d6c100e8cdff46a8d2cbf06b17835b06fa7b954c 100644 (file)
@@ -208,25 +208,29 @@ public abstract class AbstractComponentContainer extends AbstractComponent
 
     public void setEnabled(boolean enabled) {
         super.setEnabled(enabled);
-
-        updateComponentDisabledState(!enabled);
-    }
-
-    public void setDisabledByContainer(boolean disabledByContainer) {
-        super.setDisabledByContainer(disabledByContainer);
-
-        updateComponentDisabledState(disabledByContainer);
+        if (getParent() != null && !getParent().isEnabled()) {
+            // some ancestor still disabled, don't update children
+            return;
+        } else {
+            requestRepaintAll();
+        }
     }
 
-    private void updateComponentDisabledState(boolean disabled) {
-        // Update the disabledByContainer state for all subcomponents
-        for (Iterator i = getComponentIterator(); i.hasNext();) {
-            Component c = (Component) i.next();
-            if (c instanceof AbstractComponent) {
-                ((AbstractComponent) c).setDisabledByContainer(disabled);
+    public void requestRepaintAll() {
+        requestRepaint();
+        for (Iterator childIterator = getComponentIterator(); childIterator
+                .hasNext();) {
+            Component c = (Component) 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 ComponentContainer) {
+                ((ComponentContainer) c).requestRepaintAll();
+            } else {
+                c.requestRepaint();
             }
         }
-
     }
 
 }
\ No newline at end of file
index b4a8c02f0f3f49daede8bd7bec7ad1a8a8911de4..dec180cdbacb74ad5b38d9500372d15a160155cf 100644 (file)
@@ -76,11 +76,16 @@ public interface Component extends Paintable, VariableOwner, Sizeable {
      * </p>
      * 
      * <p>
+     * <b>Note</b> The component is considered disabled if it's parent is
+     * disabled.
+     * </p>
+     * 
+     * <p>
      * Components should be enabled by default.
      * </p>
      * 
-     * @return <code>true</code> if the component is enabled, <code>false</code>
-     *         if not.
+     * @return <code>true</code> if the component, and it's parent, is enabled
+     *         <code>false</code> otherwise.
      * @see VariableOwner#isEnabled()
      */
     public boolean isEnabled();
@@ -91,6 +96,16 @@ public interface Component extends Paintable, VariableOwner, Sizeable {
      * {@link com.itmill.toolkit.terminal.Paintable.RepaintRequestEvent
      * RepaintRequestEvent}.
      * 
+     * <p>
+     * <b>Note</b> that after enabling a component, {@link #isEnabled()} might
+     * still return false if the parent is disabled.
+     * </p>
+     * 
+     * <p>
+     * <b>Also note</b> that if the component contains child-components, it
+     * should recursively call requestRepaint() for all descendant components.
+     * </p>
+     * 
      * @param enabled
      *            the boolean value specifying if the component should be
      *            enabled after the call or not
index a513b462fe52b5ecb0cdf64390d004d473df4566..a73c8f4d6eb9a292ce7c143e12180bf04665b370 100644 (file)
@@ -68,6 +68,15 @@ public interface ComponentContainer extends Component {
      */
     public Iterator getComponentIterator();
 
+    /**
+     * 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 d9f452a0e6d67140e6bfb0553df254d11743ada5..62b0daa2a0b72875495e2b961fc31d5e3bff5fea 100644 (file)
@@ -1079,25 +1079,12 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item,
 
     public void setEnabled(boolean enabled) {
         super.setEnabled(enabled);
-
-        updateComponentDisabledState(!enabled);
-    }
-
-    public void setDisabledByContainer(boolean disabledByContainer) {
-        super.setDisabledByContainer(disabledByContainer);
-
-        updateComponentDisabledState(disabledByContainer);
-    }
-
-    private void updateComponentDisabledState(boolean disabled) {
-        // Update the disabledByContainer state for all subcomponents
-        for (Iterator i = fields.values().iterator(); i.hasNext();) {
-            Component c = (Component) i.next();
-            if (c instanceof AbstractComponent) {
-                ((AbstractComponent) c).setDisabledByContainer(disabled);
-            }
+        if (getParent() != null && !getParent().isEnabled()) {
+            // some ancestor still disabled, don't update children
+            return;
+        } else {
+            getLayout().requestRepaintAll();
         }
-
     }
 
 }
index 49a8a01dc67d3d0972f07f89207dbb81f15c1be5..8a37fb6a8394bb6d74812583a95fbb34224e20e3 100644 (file)
@@ -220,6 +220,12 @@ public class Panel extends AbstractComponentContainer implements Scrollable,
         }
     }
 
+    public void requestRepaintAll() {
+        // Panel has odd structure, delegate to layout
+        requestRepaint();
+        getLayout().requestRepaintAll();
+    }
+
     /**
      * Gets the component UIDL tag.
      *