From: Marc Englund Date: Thu, 25 Sep 2008 11:38:18 +0000 (+0000) Subject: setEnable(false) also disables descendants, for #677 - Table still not fixed. X-Git-Tag: 6.7.0.beta1~4091 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=627a866d0a32548d1722c89571fda89ba5633965;p=vaadin-framework.git setEnable(false) also disables descendants, for #677 - Table still not fixed. svn changeset:5513/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/ui/AbstractComponent.java b/src/com/itmill/toolkit/ui/AbstractComponent.java index 734204bd9f..a4408055e4 100644 --- a/src/com/itmill/toolkit/ui/AbstractComponent.java +++ b/src/com/itmill/toolkit/ui/AbstractComponent.java @@ -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(); + } } } diff --git a/src/com/itmill/toolkit/ui/AbstractComponentContainer.java b/src/com/itmill/toolkit/ui/AbstractComponentContainer.java index 56febe3815..d6c100e8cd 100644 --- a/src/com/itmill/toolkit/ui/AbstractComponentContainer.java +++ b/src/com/itmill/toolkit/ui/AbstractComponentContainer.java @@ -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 diff --git a/src/com/itmill/toolkit/ui/Component.java b/src/com/itmill/toolkit/ui/Component.java index b4a8c02f0f..dec180cdba 100644 --- a/src/com/itmill/toolkit/ui/Component.java +++ b/src/com/itmill/toolkit/ui/Component.java @@ -76,11 +76,16 @@ public interface Component extends Paintable, VariableOwner, Sizeable { *

* *

+ * Note The component is considered disabled if it's parent is + * disabled. + *

+ * + *

* Components should be enabled by default. *

* - * @return true if the component is enabled, false - * if not. + * @return true if the component, and it's parent, is enabled + * false 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}. * + *

+ * Note that after enabling a component, {@link #isEnabled()} might + * still return false if the parent is disabled. + *

+ * + *

+ * Also note that if the component contains child-components, it + * should recursively call requestRepaint() for all descendant components. + *

+ * * @param enabled * the boolean value specifying if the component should be * enabled after the call or not diff --git a/src/com/itmill/toolkit/ui/ComponentContainer.java b/src/com/itmill/toolkit/ui/ComponentContainer.java index a513b462fe..a73c8f4d6e 100644 --- a/src/com/itmill/toolkit/ui/ComponentContainer.java +++ b/src/com/itmill/toolkit/ui/ComponentContainer.java @@ -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 source. diff --git a/src/com/itmill/toolkit/ui/Form.java b/src/com/itmill/toolkit/ui/Form.java index d9f452a0e6..62b0daa2a0 100644 --- a/src/com/itmill/toolkit/ui/Form.java +++ b/src/com/itmill/toolkit/ui/Form.java @@ -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(); } - } } diff --git a/src/com/itmill/toolkit/ui/Panel.java b/src/com/itmill/toolkit/ui/Panel.java index 49a8a01dc6..8a37fb6a83 100644 --- a/src/com/itmill/toolkit/ui/Panel.java +++ b/src/com/itmill/toolkit/ui/Panel.java @@ -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. *