From d627a9667063148b51e675c3c97a8f79c78d777a Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 17 Nov 2009 16:42:46 +0000 Subject: [PATCH] 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 --- src/com/vaadin/ui/AbstractComponent.java | 21 ++++- .../abstractcomponent/EnableState.html | 87 +++++++++++++++++++ .../abstractcomponent/EnableState.java | 77 ++++++++++++++++ 3 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.html create mode 100644 tests/src/com/vaadin/tests/components/abstractcomponent/EnableState.java 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 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.abstractcomponent.EnableState
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]58,5
waitForVaadin
screenCapturedisable-cascade
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[3]/VCheckBox[0]/domChild[0]49,7
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]55,7
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[0]/VCheckBox[0]/domChild[0]76,8
waitForVaadin
mouseClickvaadin=runcomvaadintestscomponentsabstractcomponentEnableState::/VVerticalLayout[0]/ChildComponentContainer[2]/VCheckBox[0]/domChild[0]58,8
waitForVaadin
screenCapturebutton-disabled
+ + 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; + } +} -- 2.39.5