svn changeset:5513/svn branch:trunktags/6.7.0.beta1
@@ -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(); | |||
} | |||
} | |||
} | |||
@@ -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(); | |||
} | |||
} | |||
} | |||
} |
@@ -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 |
@@ -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>. |
@@ -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(); | |||
} | |||
} | |||
} |
@@ -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. | |||
* |