From cff9d87dd9554727a44cf6af535a644706391ab4 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Thu, 27 Oct 2016 14:53:13 +0300 Subject: Move setReadOnly from Component to HasValue Change-Id: Ib867b71cab4cf5cda89f272986930297b7a84ced --- .../com/vaadin/tests/components/AbstractComponentTestCase.java | 10 ++++++++-- .../vaadin/tests/components/select/OptionGroupBaseSelects.java | 4 +++- .../vaadin/tests/components/upload/DisabledUploadButton.java | 7 ------- .../com/vaadin/tests/layouts/CaptionsInLayoutsWaiAria.java | 7 ++++++- uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java | 10 +++++----- .../tests/components/upload/DisabledUploadButtonTest.java | 9 --------- 6 files changed, 22 insertions(+), 25 deletions(-) (limited to 'uitest') diff --git a/uitest/src/main/java/com/vaadin/tests/components/AbstractComponentTestCase.java b/uitest/src/main/java/com/vaadin/tests/components/AbstractComponentTestCase.java index f34c663029..10959a73b1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/AbstractComponentTestCase.java +++ b/uitest/src/main/java/com/vaadin/tests/components/AbstractComponentTestCase.java @@ -12,6 +12,7 @@ import com.vaadin.server.UserError; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Layout.SpacingHandler; +import com.vaadin.v7.ui.AbstractLegacyComponent; import com.vaadin.v7.ui.Field; public abstract class AbstractComponentTestCase @@ -124,8 +125,13 @@ public abstract class AbstractComponentTestCase protected Command descriptionCommand = (c, value, data) -> c .setDescription(value); - protected Command readonlyCommand = (c, enabled, data) -> c - .setReadOnly(enabled); + protected Command readonlyCommand = (c, enabled, data) -> { + if (c instanceof HasValue) { + ((HasValue) c).setReadOnly(enabled); + } else if (c instanceof AbstractLegacyComponent) { + ((AbstractLegacyComponent) c).setReadOnly(enabled); + } + }; protected Command visibleCommand = (c, enabled, data) -> c .setVisible(enabled); diff --git a/uitest/src/main/java/com/vaadin/tests/components/select/OptionGroupBaseSelects.java b/uitest/src/main/java/com/vaadin/tests/components/select/OptionGroupBaseSelects.java index 1d05753815..c98f434d62 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/select/OptionGroupBaseSelects.java +++ b/uitest/src/main/java/com/vaadin/tests/components/select/OptionGroupBaseSelects.java @@ -4,6 +4,7 @@ import com.vaadin.tests.components.ComponentTestCase; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Component; import com.vaadin.ui.HorizontalLayout; +import com.vaadin.v7.ui.AbstractLegacyComponent; import com.vaadin.v7.ui.AbstractSelect; import com.vaadin.v7.ui.ListSelect; import com.vaadin.v7.ui.NativeSelect; @@ -27,7 +28,8 @@ public class OptionGroupBaseSelects cb.addValueChangeListener(event -> { for (Component c : layout) { if (c instanceof AbstractSelect) { - c.setReadOnly(!c.isReadOnly()); + AbstractLegacyComponent legacyComponent = (AbstractLegacyComponent) c; + legacyComponent.setReadOnly(!legacyComponent.isReadOnly()); } } }); diff --git a/uitest/src/main/java/com/vaadin/tests/components/upload/DisabledUploadButton.java b/uitest/src/main/java/com/vaadin/tests/components/upload/DisabledUploadButton.java index adce9c25e5..5a73cd3fbd 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/upload/DisabledUploadButton.java +++ b/uitest/src/main/java/com/vaadin/tests/components/upload/DisabledUploadButton.java @@ -13,13 +13,6 @@ public class DisabledUploadButton extends AbstractReindeerTestUI { 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) { diff --git a/uitest/src/main/java/com/vaadin/tests/layouts/CaptionsInLayoutsWaiAria.java b/uitest/src/main/java/com/vaadin/tests/layouts/CaptionsInLayoutsWaiAria.java index 5c8788f53e..9bcb9cd799 100644 --- a/uitest/src/main/java/com/vaadin/tests/layouts/CaptionsInLayoutsWaiAria.java +++ b/uitest/src/main/java/com/vaadin/tests/layouts/CaptionsInLayoutsWaiAria.java @@ -24,6 +24,7 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.v7.data.Item; import com.vaadin.v7.data.Property.ValueChangeEvent; import com.vaadin.v7.data.Property.ValueChangeListener; +import com.vaadin.v7.ui.AbstractLegacyComponent; import com.vaadin.v7.ui.Field; import com.vaadin.v7.ui.NativeSelect; import com.vaadin.v7.ui.OptionGroup; @@ -163,7 +164,11 @@ public class CaptionsInLayoutsWaiAria extends TestBase { protected void setReadOnly(boolean value) { for (Component c : components) { - c.setReadOnly(value); + if (c instanceof HasValue) { + ((HasValue) c).setReadOnly(value); + } else if (c instanceof AbstractLegacyComponent) { + ((AbstractLegacyComponent) c).setReadOnly(value); + } } } diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java index 1332ec67ad..3a7df7cd90 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java @@ -27,13 +27,13 @@ import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.themes.ValoTheme; import com.vaadin.ui.CheckBox; import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.RichTextArea; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.themes.ValoTheme; import com.vaadin.v7.ui.ComboBox; import com.vaadin.v7.ui.OptionGroup; import com.vaadin.v7.ui.TextArea; @@ -45,6 +45,9 @@ import com.vaadin.v7.ui.TextField; * @author Vaadin Ltd */ public class Forms extends VerticalLayout implements View { + + private boolean readOnly = true; + public Forms() { setSpacing(true); setMargin(true); @@ -150,26 +153,23 @@ public class Forms extends VerticalLayout implements View { "

Integer legentibus erat a ante historiarum dapibus. Vivamus sagittis lacus vel augue laoreet rutrum faucibus. A communi observantia non est recedendum. Morbi fringilla convallis sapien, id pulvinar odio volutpat. Ab illo tempore, ab est sed immemorabili. Quam temere in vitiis, legem sancimus haerentia.

Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh. Quam diu etiam furor iste tuus nos eludet? Cum sociis natoque penatibus et magnis dis parturient. Quam diu etiam furor iste tuus nos eludet? Tityre, tu patulae recubans sub tegmine fagi dolor.

Curabitur blandit tempus ardua ridiculus sed magna. Phasellus laoreet lorem vel dolor tempus vehicula. Etiam habebis sem dicantur magna mollis euismod. Hi omnes lingua, institutis, legibus inter se differunt.

"); form.addComponent(bio); - form.setReadOnly(true); bio.setReadOnly(true); Button edit = new Button("Edit", new ClickListener() { @Override public void buttonClick(ClickEvent event) { - boolean readOnly = form.isReadOnly(); if (readOnly) { bio.setReadOnly(false); - form.setReadOnly(false); form.removeStyleName(ValoTheme.FORMLAYOUT_LIGHT); event.getButton().setCaption("Save"); event.getButton().addStyleName(ValoTheme.BUTTON_PRIMARY); } else { bio.setReadOnly(true); - form.setReadOnly(true); form.addStyleName(ValoTheme.FORMLAYOUT_LIGHT); event.getButton().setCaption("Edit"); event.getButton().removeStyleName(ValoTheme.BUTTON_PRIMARY); } + readOnly = !readOnly; } }); diff --git a/uitest/src/test/java/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java b/uitest/src/test/java/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java index cc97b4d7d1..cbc6423893 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java @@ -35,15 +35,6 @@ public class DisabledUploadButtonTest extends MultiBrowserTest { 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"))); -- cgit v1.2.3