diff options
author | Sauli Tähkäpää <sauli@vaadin.com> | 2014-10-12 23:42:28 +0300 |
---|---|---|
committer | Anna Koskinen <anna@vaadin.com> | 2014-10-23 14:37:19 +0300 |
commit | 98a6367842b34f9de56fc19d41dfbbe079c248c1 (patch) | |
tree | 1f9d5766c441639cf0b5e2b49ab1a04760327da4 | |
parent | dd682d365ebd79cb0a11791a70cfad9832d5fb29 (diff) | |
download | vaadin-framework-98a6367842b34f9de56fc19d41dfbbe079c248c1.tar.gz vaadin-framework-98a6367842b34f9de56fc19d41dfbbe079c248c1.zip |
Set v-disabled on Button inside Upload when disabled. (#14655)
Change-Id: Ic28c8e4020eddae32a71b5c7f9da0ad61f2f7af9
3 files changed, 104 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/ui/VUpload.java b/client/src/com/vaadin/client/ui/VUpload.java index f234ef6d65..42fb08fb3c 100644 --- a/client/src/com/vaadin/client/ui/VUpload.java +++ b/client/src/com/vaadin/client/ui/VUpload.java @@ -184,7 +184,7 @@ public class VUpload extends SimplePanel { /** For internal use only. May be removed or replaced in the future. */ public void disableUpload() { - submitButton.setEnabled(false); + setEnabledForSubmitButton(false); if (!submitted) { // Cannot disable the fileupload while submitting or the file won't // be submitted at all @@ -195,7 +195,7 @@ public class VUpload extends SimplePanel { /** For internal use only. May be removed or replaced in the future. */ public void enableUpload() { - submitButton.setEnabled(true); + setEnabledForSubmitButton(true); fu.getElement().setPropertyBoolean("disabled", false); enabled = true; if (submitted) { @@ -209,6 +209,12 @@ public class VUpload extends SimplePanel { } } + private void setEnabledForSubmitButton(boolean enabled) { + submitButton.setEnabled(enabled); + submitButton.setStyleName(ApplicationConnection.DISABLED_CLASSNAME, + !enabled); + } + /** * Re-creates file input field and populates panel. This is needed as we * want to clear existing values from our current file input field. diff --git a/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java new file mode 100644 index 0000000000..dcf2ac2784 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButton.java @@ -0,0 +1,41 @@ +package com.vaadin.tests.components.upload; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Upload; + +public class DisabledUploadButton extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + final Upload upload = new Upload(); + + addComponent(upload); + + addButton("Set readonly", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + upload.setReadOnly(true); + } + }); + + addButton("Set disabled", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + upload.setEnabled(false); + } + }); + } + + @Override + public String getDescription() { + return "Upload button should be disabled when upload " + + "is set to readonly and/or disabled"; + } + + @Override + protected Integer getTicketNumber() { + return 14655; + } +} diff --git a/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java new file mode 100644 index 0000000000..cc97b4d7d1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java @@ -0,0 +1,55 @@ +package com.vaadin.tests.components.upload; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.UploadElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class DisabledUploadButtonTest extends MultiBrowserTest { + + @Override + public void setup() throws Exception { + super.setup(); + openTestURL(); + } + + private String getUploadButtonClass() { + WebElement uploadButton = getUploadButton(); + + return uploadButton.getAttribute("class"); + } + + private void clickButton(String caption) { + $(ButtonElement.class).caption(caption).first().click(); + } + + private WebElement getUploadButton() { + UploadElement upload = $(UploadElement.class).first(); + return upload.findElement(By.className("v-button")); + } + + @Test + public void buttonIsReadonly() { + assertThat(getUploadButtonClass(), not(containsString("v-disabled"))); + + clickButton("Set readonly"); + + assertThat(getUploadButtonClass(), containsString("v-disabled")); + } + + @Test + public void buttonIsDisabled() { + assertThat(getUploadButtonClass(), not(containsString("v-disabled"))); + + clickButton("Set disabled"); + + assertThat(getUploadButtonClass(), containsString("v-disabled")); + } +}
\ No newline at end of file |