From dd20841c39b0b30eb2a5c5fddc2eb9cb1cd1e595 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 2 Nov 2016 11:20:23 +0200 Subject: [PATCH] Move read-only to AbstractFieldState (#8514) Change-Id: I0baea991bd80075d63c5d57e3b07f4e9fcb12676 --- .../com/vaadin/client/ComponentConnector.java | 9 ----- .../connectors/AbstractListingConnector.java | 12 +++---- .../client/ui/AbstractComponentConnector.java | 15 -------- .../client/ui/AbstractFieldConnector.java | 12 +++++++ .../client/ui/upload/UploadConnector.java | 2 +- .../vaadin/v7/client/ComponentConnector.java | 36 +++++++++++++++++++ .../ui/AbstractLegacyComponentConnector.java | 18 ++++++++-- .../v7/client/ui/form/FormConnector.java | 11 +++--- .../v7/client/ui/tree/TreeConnector.java | 4 +-- .../shared/AbstractLegacyComponentState.java | 1 + .../java/com/vaadin/ui/AbstractComponent.java | 32 ++++++++++++----- .../vaadin/shared/AbstractComponentState.java | 1 - .../com/vaadin/shared/AbstractFieldState.java | 5 +++ 13 files changed, 108 insertions(+), 50 deletions(-) create mode 100644 compatibility-client/src/main/java/com/vaadin/v7/client/ComponentConnector.java diff --git a/client/src/main/java/com/vaadin/client/ComponentConnector.java b/client/src/main/java/com/vaadin/client/ComponentConnector.java index c9c793d714..e7f29b3b5b 100644 --- a/client/src/main/java/com/vaadin/client/ComponentConnector.java +++ b/client/src/main/java/com/vaadin/client/ComponentConnector.java @@ -85,15 +85,6 @@ public interface ComponentConnector extends ServerConnector { */ public boolean isRelativeHeight(); - /** - * Checks if the connector is read only. - * - * @deprecated This belongs in AbstractFieldConnector, see #8514 - * @return true - */ - @Deprecated - public boolean isReadOnly(); - /** * Return true if parent handles caption, false if the paintable handles the * caption itself. diff --git a/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java b/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java index 6593b5a0be..b89106307e 100644 --- a/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java @@ -17,7 +17,7 @@ package com.vaadin.client.connectors; import com.vaadin.client.connectors.data.HasDataSource; import com.vaadin.client.data.DataSource; -import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.shared.data.DataCommunicatorConstants; import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.ui.AbstractListing; @@ -36,7 +36,7 @@ import elemental.json.JsonValue; * @since 8.0 */ public abstract class AbstractListingConnector> - extends AbstractComponentConnector implements HasDataSource { + extends AbstractFieldConnector implements HasDataSource { private DataSource dataSource = null; @@ -64,7 +64,7 @@ public abstract class AbstractListingConnector tooltipMap = new HashMap(); diff --git a/compatibility-shared/src/main/java/com/vaadin/v7/shared/AbstractLegacyComponentState.java b/compatibility-shared/src/main/java/com/vaadin/v7/shared/AbstractLegacyComponentState.java index adb6d96ae2..5471f6da2e 100644 --- a/compatibility-shared/src/main/java/com/vaadin/v7/shared/AbstractLegacyComponentState.java +++ b/compatibility-shared/src/main/java/com/vaadin/v7/shared/AbstractLegacyComponentState.java @@ -29,4 +29,5 @@ import com.vaadin.shared.annotations.NoLayout; public class AbstractLegacyComponentState extends AbstractComponentState { @NoLayout public boolean immediate = false; + public boolean readOnly = false; } diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index f03f1f438f..dd6e44735d 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -1053,8 +1053,16 @@ public abstract class AbstractComponent extends AbstractClientConnector * read-only mode or not */ protected void setReadOnly(boolean readOnly) { - if (readOnly != isReadOnly()) { - getState().readOnly = readOnly; + if (getState(false) instanceof AbstractFieldState) { + if (readOnly != isReadOnly()) { + ((AbstractFieldState) getState()).readOnly = readOnly; + } + } else { + throw new IllegalStateException( + "This component does not support the read-only mode, since state is of type " + + getStateType().getSimpleName() + + " and does not inherit " + + AbstractFieldState.class.getSimpleName()); } } @@ -1067,7 +1075,14 @@ public abstract class AbstractComponent extends AbstractClientConnector * @see #setReadOnly(boolean) */ protected boolean isReadOnly() { - return getState(false).readOnly; + if (getState(false) instanceof AbstractFieldState) { + return ((AbstractFieldState) getState(false)).readOnly; + } + throw new IllegalStateException( + "This component does not support the read-only mode, since state is of type " + + getStateType().getSimpleName() + + " and does not inherit " + + AbstractFieldState.class.getSimpleName()); } /** @@ -1424,13 +1439,12 @@ public abstract class AbstractComponent extends AbstractClientConnector protected boolean isRequiredIndicatorVisible() { if (getState(false) instanceof AbstractFieldState) { return ((AbstractFieldState) getState(false)).required; - } else { - throw new IllegalStateException( - "This component does not support the required indicator, since state is of type " - + getStateType().getSimpleName() - + " and does not inherit " - + AbstractFieldState.class.getSimpleName()); } + throw new IllegalStateException( + "This component does not support the required indicator, since state is of type " + + getStateType().getSimpleName() + + " and does not inherit " + + AbstractFieldState.class.getSimpleName()); } private static final Logger getLogger() { diff --git a/shared/src/main/java/com/vaadin/shared/AbstractComponentState.java b/shared/src/main/java/com/vaadin/shared/AbstractComponentState.java index bcf2885989..a60ae7aaf5 100644 --- a/shared/src/main/java/com/vaadin/shared/AbstractComponentState.java +++ b/shared/src/main/java/com/vaadin/shared/AbstractComponentState.java @@ -31,7 +31,6 @@ import com.vaadin.shared.communication.SharedState; public class AbstractComponentState extends SharedState { public String height = ""; public String width = ""; - public boolean readOnly = false; @NoLayout public String description = ""; // Note: for the caption, there is a difference between null and an empty diff --git a/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java b/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java index 6ac39efe69..4a94a82fec 100644 --- a/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java +++ b/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java @@ -31,4 +31,9 @@ public class AbstractFieldState extends TabIndexState { */ public boolean required = false; + /** + * Is the field read-only or not. + */ + public boolean readOnly = false; + } -- 2.39.5