aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Englund <marc.englund@itmill.com>2008-09-25 11:38:18 +0000
committerMarc Englund <marc.englund@itmill.com>2008-09-25 11:38:18 +0000
commit627a866d0a32548d1722c89571fda89ba5633965 (patch)
treea4e9e54d57b4b7c0b92d010f1f251e42c3563476
parent8ae61c179dfc860141dc7d1fb3e2859e441c5a6c (diff)
downloadvaadin-framework-627a866d0a32548d1722c89571fda89ba5633965.tar.gz
vaadin-framework-627a866d0a32548d1722c89571fda89ba5633965.zip
setEnable(false) also disables descendants, for #677 - Table still not fixed.
svn changeset:5513/svn branch:trunk
-rw-r--r--src/com/itmill/toolkit/ui/AbstractComponent.java28
-rw-r--r--src/com/itmill/toolkit/ui/AbstractComponentContainer.java34
-rw-r--r--src/com/itmill/toolkit/ui/Component.java19
-rw-r--r--src/com/itmill/toolkit/ui/ComponentContainer.java9
-rw-r--r--src/com/itmill/toolkit/ui/Form.java23
-rw-r--r--src/com/itmill/toolkit/ui/Panel.java6
6 files changed, 62 insertions, 57 deletions
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
@@ -66,11 +66,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).
*/
private boolean visible = true;
@@ -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 {
* </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
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
@@ -69,6 +69,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>.
*
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.
*