summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-10-27 14:53:13 +0300
committerVaadin Code Review <review@vaadin.com>2016-11-02 10:03:23 +0000
commitcff9d87dd9554727a44cf6af535a644706391ab4 (patch)
treec1731b600e86beb5005662fd25350a9ee29a71e1
parent2cb106ce095edd5fc8a72b38a856c76ece05684e (diff)
downloadvaadin-framework-cff9d87dd9554727a44cf6af535a644706391ab4.tar.gz
vaadin-framework-cff9d87dd9554727a44cf6af535a644706391ab4.zip
Move setReadOnly from Component to HasValue
Change-Id: Ib867b71cab4cf5cda89f272986930297b7a84ced
-rw-r--r--client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java2
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractLegacyComponent.java60
-rw-r--r--server/src/main/java/com/vaadin/data/HasValue.java22
-rw-r--r--server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java7
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractComponent.java46
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractField.java18
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java11
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java10
-rw-r--r--server/src/main/java/com/vaadin/ui/Button.java4
-rw-r--r--server/src/main/java/com/vaadin/ui/Component.java50
-rw-r--r--server/src/main/java/com/vaadin/ui/Window.java20
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java10
-rw-r--r--server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java10
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java14
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java8
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/window/WindowState.java2
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/AbstractComponentTestCase.java10
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/select/OptionGroupBaseSelects.java4
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/upload/DisabledUploadButton.java7
-rw-r--r--uitest/src/main/java/com/vaadin/tests/layouts/CaptionsInLayoutsWaiAria.java7
-rw-r--r--uitest/src/main/java/com/vaadin/tests/themes/valo/Forms.java10
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/upload/DisabledUploadButtonTest.java9
22 files changed, 193 insertions, 148 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java b/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java
index eed89f090c..3d5d7bbcfd 100644
--- a/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java
@@ -388,7 +388,7 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector
clickEventHandler.handleEventHandlerRegistration();
- window.setClosable(!isReadOnly());
+ window.setClosable(state.closable);
// initialize position from state
updateWindowPosition();
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractLegacyComponent.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractLegacyComponent.java
index 28c1078de7..c4136f633b 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractLegacyComponent.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/AbstractLegacyComponent.java
@@ -26,8 +26,8 @@ import com.vaadin.v7.shared.AbstractLegacyComponentState;
/**
* An abstract base class for compatibility components.
* <p>
- * Used since immediate property has been removed in Vaadin 8 from
- * {@link AbstractComponent}.
+ * Used since immediate and read-only properties has been removed in Vaadin 8
+ * from {@link AbstractComponent}.
*
* @author Vaadin Ltd
* @since 8.0
@@ -78,6 +78,62 @@ public class AbstractLegacyComponent extends AbstractComponent {
getState().immediate = immediate;
}
+ /**
+ * Tests whether the component is in the read-only mode. The user can not
+ * change the value of a read-only component. As only {@code AbstractField}
+ * or {@code LegacyField} components normally have a value that can be input
+ * or changed by the user, this is mostly relevant only to field components,
+ * though not restricted to them.
+ *
+ * <p>
+ * Notice that the read-only mode only affects whether the user can change
+ * the <i>value</i> of the component; it is possible to, for example, scroll
+ * a read-only table.
+ * </p>
+ *
+ * <p>
+ * The method will return {@code true} if the component or any of its
+ * parents is in the read-only mode.
+ * </p>
+ *
+ * @return <code>true</code> if the component or any of its parents is in
+ * read-only mode, <code>false</code> if not.
+ * @see #setReadOnly(boolean)
+ */
+ @Override
+ public boolean isReadOnly() {
+ return getState(false).readOnly;
+ }
+
+ /**
+ * Sets the read-only mode of the component to the specified mode. The user
+ * can not change the value of a read-only component.
+ *
+ * <p>
+ * As only {@code AbstractField} or {@code LegacyField} components normally
+ * have a value that can be input or changed by the user, this is mostly
+ * relevant only to field components, though not restricted to them.
+ * </p>
+ *
+ * <p>
+ * Notice that the read-only mode only affects whether the user can change
+ * the <i>value</i> of the component; it is possible to, for example, scroll
+ * a read-only table.
+ * </p>
+ *
+ * <p>
+ * In Vaadin 8 the read-only property is part of {@link HasValue} API.
+ * </p>
+ *
+ * @param readOnly
+ * a boolean value specifying whether the component is put
+ * read-only mode or not
+ */
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ getState().readOnly = readOnly;
+ }
+
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
diff --git a/server/src/main/java/com/vaadin/data/HasValue.java b/server/src/main/java/com/vaadin/data/HasValue.java
index e02297b7f4..1a612dbb80 100644
--- a/server/src/main/java/com/vaadin/data/HasValue.java
+++ b/server/src/main/java/com/vaadin/data/HasValue.java
@@ -235,4 +235,26 @@ public interface HasValue<V> extends Serializable {
* @return <code>true</code> if visible, <code>false</code> if not
*/
public boolean isRequiredIndicatorVisible();
+
+ /**
+ * Sets the read-only mode of this {@code HasValue} to given mode. The user
+ * can't change the value when in read-only mode.
+ * <p>
+ * A {@code HasValue} with a visual component in read-only mode typically
+ * looks visually different to signal to the user that the value cannot be
+ * edited.
+ *
+ * @param readOnly
+ * a boolean value specifying whether the component is put
+ * read-only mode or not
+ */
+ public void setReadOnly(boolean readOnly);
+
+ /**
+ * Returns whether this {@code HasValue} is in read-only mode or not.
+ *
+ * @return {@code false} if the user can modify the value, {@code true} if
+ * not.
+ */
+ public boolean isReadOnly();
}
diff --git a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
index 7f6bd3a2cc..19c3d45fa9 100644
--- a/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
+++ b/server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
@@ -36,7 +36,6 @@ import com.vaadin.server.UploadException;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
import com.vaadin.server.VaadinSession;
-import com.vaadin.ui.Component;
import com.vaadin.ui.UI;
import com.vaadin.ui.Upload.FailedEvent;
@@ -444,12 +443,6 @@ public class FileUploadHandler implements RequestHandler {
+ connector.getConnectorId()
+ " because the component was disabled");
}
- if ((connector instanceof Component)
- && ((Component) connector).isReadOnly()) {
- // Only checked for legacy reasons
- throw new UploadException(
- "File upload ignored because the component is read-only");
- }
} finally {
session.unlock();
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
index 8711b601e6..5d8c422a7c 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java
@@ -35,6 +35,7 @@ import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
+import com.vaadin.data.HasValue;
import com.vaadin.event.ActionManager;
import com.vaadin.event.ConnectorActionManager;
import com.vaadin.event.ContextClickEvent;
@@ -602,24 +603,6 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
/*
- * Tests if the component is in read-only mode. Don't add a JavaDoc comment
- * here, we use the default documentation from implemented interface.
- */
- @Override
- public boolean isReadOnly() {
- return getState(false).readOnly;
- }
-
- /*
- * Sets the component's read-only mode. Don't add a JavaDoc comment here, we
- * use the default documentation from implemented interface.
- */
- @Override
- public void setReadOnly(boolean readOnly) {
- getState().readOnly = readOnly;
- }
-
- /*
* Notify the component that it's attached to a window. Don't add a JavaDoc
* comment here, we use the default documentation from implemented
* interface.
@@ -1061,6 +1044,33 @@ public abstract class AbstractComponent extends AbstractClientConnector
}
/**
+ * Sets the read-only status in the state of this {@code AbstractComponent}.
+ * This method should be made public in {@link Component Components} that
+ * implement {@link HasValue}.
+ *
+ * @param readOnly
+ * a boolean value specifying whether the component is put
+ * read-only mode or not
+ */
+ protected void setReadOnly(boolean readOnly) {
+ if (readOnly != isReadOnly()) {
+ getState().readOnly = readOnly;
+ }
+ }
+
+ /**
+ * Returns the read-only status from the state of this
+ * {@code AbstractComponent}. This method should be made public in
+ * {@link Component Components} that implement {@link HasValue}.
+ *
+ * @return {@code true} if state has read-only on; {@code false} if not
+ * @see #setReadOnly(boolean)
+ */
+ protected boolean isReadOnly() {
+ return getState(false).readOnly;
+ }
+
+ /**
* Reads the size of this component from the given design attributes. If the
* attributes do not contain relevant size information, defaults is
* consulted.
diff --git a/server/src/main/java/com/vaadin/ui/AbstractField.java b/server/src/main/java/com/vaadin/ui/AbstractField.java
index 065825b5ad..45f7b4fa0b 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractField.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractField.java
@@ -59,24 +59,13 @@ public abstract class AbstractField<T> extends AbstractComponent
setValue(value, false);
}
- /**
- * Returns whether the value of this field can be changed by the user or
- * not. By default fields are not read-only.
- *
- * @return {@code true} if this field is in read-only mode, {@code false}
- * otherwise.
- *
- * @see #setReadOnly(boolean)
- */
@Override
public boolean isReadOnly() {
return super.isReadOnly();
}
/**
- * Sets whether the value of this field can be changed by the user or not. A
- * field in read-only mode typically looks visually different to signal to
- * the user that the value cannot be edited.
+ * {@inheritDoc}
* <p>
* The server ignores (potentially forged) value change requests from the
* client to fields that are read-only. Programmatically changing the field
@@ -119,9 +108,8 @@ public abstract class AbstractField<T> extends AbstractComponent
super.writeDesign(design, designContext);
AbstractField<T> def = designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
- DesignAttributeHandler.writeAttribute("readonly", attr,
- super.isReadOnly(), def.isReadOnly(), Boolean.class,
- designContext);
+ DesignAttributeHandler.writeAttribute("readonly", attr, isReadOnly(),
+ def.isReadOnly(), Boolean.class, designContext);
}
@Override
diff --git a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
index 99c1682536..52cd02481c 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java
@@ -491,6 +491,15 @@ public abstract class AbstractMultiSelect<T>
@Override
protected RequiredIndicatorState getState(boolean markAsDirty) {
return (RequiredIndicatorState) super.getState(markAsDirty);
- };
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
diff --git a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
index 272acf3b09..e23ef105c8 100644
--- a/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
+++ b/server/src/main/java/com/vaadin/ui/AbstractSingleSelect.java
@@ -359,4 +359,14 @@ public abstract class AbstractSingleSelect<T> extends
public boolean isRequiredIndicatorVisible() {
return super.isRequiredIndicatorVisible();
}
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
diff --git a/server/src/main/java/com/vaadin/ui/Button.java b/server/src/main/java/com/vaadin/ui/Button.java
index 86321f357c..c4d30c6100 100644
--- a/server/src/main/java/com/vaadin/ui/Button.java
+++ b/server/src/main/java/com/vaadin/ui/Button.java
@@ -325,7 +325,7 @@ public class Button extends AbstractFocusable
*
* @param listener
* the Listener to be removed.
- *
+ *
* @deprecated As of 8.0, replaced by {@link Registration#remove()} in the
* registration object returned from
* {@link #addClickListener(ClickListener)}.
@@ -342,7 +342,7 @@ public class Button extends AbstractFocusable
* No action is taken is the button is disabled.
*/
public void click() {
- if (isEnabled() && !isReadOnly()) {
+ if (isEnabled()) {
fireClick();
}
}
diff --git a/server/src/main/java/com/vaadin/ui/Component.java b/server/src/main/java/com/vaadin/ui/Component.java
index b5ffebef12..5ffdf600b3 100644
--- a/server/src/main/java/com/vaadin/ui/Component.java
+++ b/server/src/main/java/com/vaadin/ui/Component.java
@@ -370,56 +370,6 @@ public interface Component extends ClientConnector, Sizeable, Serializable {
public HasComponents getParent();
/**
- * Tests whether the component is in the read-only mode. The user can not
- * change the value of a read-only component. As only {@code AbstractField}
- * or {@code LegacyField} components normally have a value that can be input
- * or changed by the user, this is mostly relevant only to field components,
- * though not restricted to them.
- *
- * <p>
- * Notice that the read-only mode only affects whether the user can change
- * the <i>value</i> of the component; it is possible to, for example, scroll
- * a read-only table.
- * </p>
- *
- * <p>
- * The method will return {@code true} if the component or any of its
- * parents is in the read-only mode.
- * </p>
- *
- * @return <code>true</code> if the component or any of its parents is in
- * read-only mode, <code>false</code> if not.
- * @see #setReadOnly(boolean)
- */
- public boolean isReadOnly();
-
- /**
- * Sets the read-only mode of the component to the specified mode. The user
- * can not change the value of a read-only component.
- *
- * <p>
- * As only {@code AbstractField} or{@code LegacyField} components normally
- * have a value that can be input or changed by the user, this is mostly
- * relevant only to field components, though not restricted to them.
- * </p>
- *
- * <p>
- * Notice that the read-only mode only affects whether the user can change
- * the <i>value</i> of the component; it is possible to, for example, scroll
- * a read-only table.
- * </p>
- *
- * <p>
- * This method will trigger a {@link RepaintRequestEvent}.
- * </p>
- *
- * @param readOnly
- * a boolean value specifying whether the component is put
- * read-only mode or not
- */
- public void setReadOnly(boolean readOnly);
-
- /**
* Gets the caption of the component.
*
* <p>
diff --git a/server/src/main/java/com/vaadin/ui/Window.java b/server/src/main/java/com/vaadin/ui/Window.java
index df06e54457..f41a127b0f 100644
--- a/server/src/main/java/com/vaadin/ui/Window.java
+++ b/server/src/main/java/com/vaadin/ui/Window.java
@@ -736,15 +736,10 @@ public class Window extends Panel
* close event to the server. Setting closable to false will remove the X
* from the window and prevent the user from closing the window.
*
- * Note! For historical reasons readonly controls the closability of the
- * window and therefore readonly and closable affect each other. Setting
- * readonly to true will set closable to false and vice versa.
- * <p/>
- *
* @return true if the window can be closed by the user.
*/
public boolean isClosable() {
- return !isReadOnly();
+ return getState(false).closable;
}
/**
@@ -753,25 +748,20 @@ public class Window extends Panel
* close event to the server. Setting closable to false will remove the X
* from the window and prevent the user from closing the window.
*
- * Note! For historical reasons readonly controls the closability of the
- * window and therefore readonly and closable affect each other. Setting
- * readonly to true will set closable to false and vice versa.
- * <p/>
- *
* @param closable
* determines if the window can be closed by the user.
*/
public void setClosable(boolean closable) {
- setReadOnly(!closable);
+ if (closable != isClosable()) {
+ getState().closable = closable;
+ }
}
/**
* Indicates whether a window can be dragged or not. By default a window is
* draggable.
- * <p/>
*
- * @param draggable
- * true if the window can be dragged by the user
+ * @return {@code true} if window is draggable; {@code false} if not
*/
public boolean isDraggable() {
return getState(false).draggable;
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
index f474e51e99..c86b139520 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPopup.java
@@ -723,4 +723,14 @@ public class ColorPickerPopup extends Window implements HasValue<Color> {
private static Logger getLogger() {
return Logger.getLogger(ColorPickerPopup.class.getName());
}
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
diff --git a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
index 27e5690e3c..023d54c7f4 100644
--- a/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
+++ b/server/src/main/java/com/vaadin/ui/components/colorpicker/ColorPickerPreview.java
@@ -195,4 +195,14 @@ public class ColorPickerPreview extends CssLayout implements HasValue<Color> {
public boolean isRequiredIndicatorVisible() {
return super.isRequiredIndicatorVisible();
}
+
+ @Override
+ public void setReadOnly(boolean readOnly) {
+ super.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly();
+ }
}
diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java
index 2722dae51a..d4b5901922 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java
@@ -39,7 +39,7 @@ import com.vaadin.ui.declarative.DesignContext;
* declarative test for a real component should extend it and implement abstract
* methods to be able to test the common properties. Components specific
* properties should be tested additionally in the subclasses implementations.
- *
+ *
* @author Vaadin Ltd
*
*/
@@ -48,14 +48,14 @@ public abstract class AbstractComponentDeclarativeTestBase<T extends AbstractCom
/**
* Returns expected element tag for the tested component.
- *
+ *
* @return expected element tag
*/
protected abstract String getComponentTag();
/**
* Returns component class which is a subject to test
- *
+ *
* @return the component class
*/
protected abstract Class<? extends T> getComponentClass();
@@ -110,7 +110,13 @@ public abstract class AbstractComponentDeclarativeTestBase<T extends AbstractCom
component.setIcon(new FileResource(new File(icon)));
component.setLocale(locale);
component.setPrimaryStyleName(primaryStyle);
- component.setReadOnly(readOnly);
+ try {
+ component.getClass()
+ .getMethod("setReadOnly", new Class[] { boolean.class })
+ .invoke(component, readOnly);
+ } catch (Exception e) {
+ // Ignore
+ }
component.setResponsive(responsive);
component.setStyleName(styleName);
component.setVisible(visible);
diff --git a/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java b/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java
index 9ffc861373..eea4e3e6e3 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java
@@ -47,14 +47,6 @@ public class ButtonClickTest {
Assert.assertFalse("Disabled button fires click events", clicked);
}
- @Test
- public void testClickReadOnly() {
- Button b = getButton();
- b.setReadOnly(true);
- b.click();
- Assert.assertFalse("Read only button fires click events", clicked);
- }
-
private Button getButton() {
Button b = new Button();
UI ui = createUI();
diff --git a/shared/src/main/java/com/vaadin/shared/ui/window/WindowState.java b/shared/src/main/java/com/vaadin/shared/ui/window/WindowState.java
index a086f9bc92..b57c6a20cf 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/window/WindowState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/window/WindowState.java
@@ -35,6 +35,8 @@ public class WindowState extends PanelState {
@NoLayout
public boolean centered = false;
@NoLayout
+ public boolean closable = true;
+ @NoLayout
public int positionX = -1;
@NoLayout
public int positionY = -1;
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<T extends AbstractComponent>
@@ -124,8 +125,13 @@ public abstract class AbstractComponentTestCase<T extends AbstractComponent>
protected Command<T, String> descriptionCommand = (c, value, data) -> c
.setDescription(value);
- protected Command<T, Boolean> readonlyCommand = (c, enabled, data) -> c
- .setReadOnly(enabled);
+ protected Command<T, Boolean> readonlyCommand = (c, enabled, data) -> {
+ if (c instanceof HasValue) {
+ ((HasValue) c).setReadOnly(enabled);
+ } else if (c instanceof AbstractLegacyComponent) {
+ ((AbstractLegacyComponent) c).setReadOnly(enabled);
+ }
+ };
protected Command<T, Boolean> 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<String>) 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 {
"<div><p><span>Integer legentibus erat a ante historiarum dapibus.</span> <span>Vivamus sagittis lacus vel augue laoreet rutrum faucibus.</span> <span>A communi observantia non est recedendum.</span> <span>Morbi fringilla convallis sapien, id pulvinar odio volutpat.</span> <span>Ab illo tempore, ab est sed immemorabili.</span> <span>Quam temere in vitiis, legem sancimus haerentia.</span></p><p><span>Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Cum sociis natoque penatibus et magnis dis parturient.</span> <span>Quam diu etiam furor iste tuus nos eludet?</span> <span>Tityre, tu patulae recubans sub tegmine fagi dolor.</span></p><p><span>Curabitur blandit tempus ardua ridiculus sed magna.</span> <span>Phasellus laoreet lorem vel dolor tempus vehicula.</span> <span>Etiam habebis sem dicantur magna mollis euismod.</span> <span>Hi omnes lingua, institutis, legibus inter se differunt.</span></p></div>");
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
@@ -36,15 +36,6 @@ public class DisabledUploadButtonTest extends MultiBrowserTest {
}
@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")));