*/
private boolean enabled = true;
- /**
- * Has the component been disabled by the container
- */
- private boolean disabledByContainer = false;
-
/**
* Is the component visible (it is rendered).
*/
* here, we use the default documentation from implemented interface.
*/
public boolean isEnabled() {
- return enabled && !disabledByContainer && isVisible();
+ return enabled && (parent == null || parent.isEnabled()) && isVisible();
}
/*
*/
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();
+ }
}
}
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
* </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();
* {@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
*/
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>.
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();
}
-
}
}
}
}
+ public void requestRepaintAll() {
+ // Panel has odd structure, delegate to layout
+ requestRepaint();
+ getLayout().requestRepaintAll();
+ }
+
/**
* Gets the component UIDL tag.
*