diff options
author | Artur Signell <artur.signell@itmill.com> | 2009-11-17 16:42:46 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2009-11-17 16:42:46 +0000 |
commit | d627a9667063148b51e675c3c97a8f79c78d777a (patch) | |
tree | d7feb8b52f64d62e905e9c1fc10125b61e6ef453 | |
parent | 69fc4620f0ab6b164e4b083e7c736d5be99c0308 (diff) | |
download | vaadin-framework-d627a9667063148b51e675c3c97a8f79c78d777a.tar.gz vaadin-framework-d627a9667063148b51e675c3c97a8f79c78d777a.zip |
Merged Test case and fix for #3609 - "Enabling/disabling components in a non-visible layout are not updated client side" from 6.1
svn changeset:9851/svn branch:6.2
3 files changed, 182 insertions, 3 deletions
diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 76fcd0ded3..2e6a0d6e19 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -344,10 +344,25 @@ public abstract class AbstractComponent implements Component, MethodEventSource */ public void setEnabled(boolean enabled) { if (this.enabled != enabled) { - boolean wasEnabled = isEnabled(); + boolean wasEnabled = this.enabled; + boolean wasEnabledInContext = isEnabled(); + this.enabled = enabled; - // don't repaint if ancestor is disabled - if (wasEnabled != isEnabled()) { + + boolean isEnabled = enabled; + boolean isEnabledInContext = isEnabled(); + + // If the actual enabled state (as rendered, in context) has not + // changed we do not need to repaint except if the parent is + // invisible. + // If the parent is invisible we must request a repaint so the + // component is repainted with the new enabled state when the parent + // is set visible again. This workaround is needed as isEnabled + // checks isVisible. + boolean needRepaint = (wasEnabledInContext != isEnabledInContext) + || (wasEnabled != isEnabled && !parent.isVisible()); + + if (needRepaint) { requestRepaint(); } } diff --git a/tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.html b/tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.html new file mode 100644 index 0000000000..f4bebcf859 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.html @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.abstractcomponent.EnableState</td>
+ <td></td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
+ <td>58,5</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>disable-cascade</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]</td>
+ <td>49,7</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+ <td>55,7</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]</td>
+ <td>76,8</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]</td>
+ <td>58,8</td>
+</tr>
+<tr>
+ <td>waitForVaadin</td>
+ <td></td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>button-disabled</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.java b/tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.java new file mode 100644 index 0000000000..3c36af8ee9 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.java @@ -0,0 +1,77 @@ +package com.vaadin.tests.components.abstractcomponent;
+
+import com.vaadin.tests.components.AbstractTestCase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Panel;
+import com.vaadin.ui.Window;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class EnableState extends AbstractTestCase {
+ @Override
+ public void init() {
+ Window mainWindow = new Window("Helloworld Application");
+
+ final Panel panel = new Panel("Test");
+ final Button button = new Button("ablebutton");
+ panel.addComponent(button);
+
+ CheckBox enable = new CheckBox("Toggle button enabled", true);
+ enable.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ boolean enabled = (Boolean) event.getButton().getValue();
+ button.setEnabled(enabled);
+ // button.requestRepaint();
+ }
+ });
+ enable.setImmediate(true);
+
+ CheckBox caption = new CheckBox("Toggle button caption", true);
+ caption.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ button.setCaption(button.getCaption() + "+");
+ }
+ });
+ caption.setImmediate(true);
+
+ CheckBox visible = new CheckBox("Toggle panel visibility", true);
+ visible.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ boolean visible = (Boolean) event.getButton().getValue();
+
+ panel.setVisible(visible);
+ }
+ });
+ visible.setImmediate(true);
+
+ CheckBox panelEnable = new CheckBox("Toggle panel enabled", true);
+ panelEnable.addListener(new Button.ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ boolean enabled = (Boolean) event.getButton().getValue();
+ panel.setEnabled(enabled);
+ }
+ });
+ panelEnable.setImmediate(true);
+
+ mainWindow.addComponent(enable);
+ mainWindow.addComponent(caption);
+ mainWindow.addComponent(visible);
+ mainWindow.addComponent(panelEnable);
+ mainWindow.addComponent(panel);
+
+ setMainWindow(mainWindow);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "This tests the enabled/disabled propagation and that enabled/disabled state is updated"
+ + " properly even when the parent is invisible. Disabling the Button while the panel is"
+ + " invisible should be reflected on the screen when the panel is set visible"
+ + " again.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 3609;
+ }
+}
|