aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-11-02 11:20:23 +0200
committerVaadin Code Review <review@vaadin.com>2016-11-02 12:13:18 +0000
commitdd20841c39b0b30eb2a5c5fddc2eb9cb1cd1e595 (patch)
tree6583dff38b14b61b6c008c6625184662b01a4e32
parentabd4e816f795a5bd402e9084d2faa4de15d14faa (diff)
downloadvaadin-framework-dd20841c39b0b30eb2a5c5fddc2eb9cb1cd1e595.tar.gz
vaadin-framework-dd20841c39b0b30eb2a5c5fddc2eb9cb1cd1e595.zip
Move read-only to AbstractFieldState (#8514)
Change-Id: I0baea991bd80075d63c5d57e3b07f4e9fcb12676
-rw-r--r--client/src/main/java/com/vaadin/client/ComponentConnector.java9
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java12
-rw-r--r--client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java15
-rw-r--r--client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java12
-rw-r--r--client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java2
-rw-r--r--compatibility-client/src/main/java/com/vaadin/v7/client/ComponentConnector.java36
-rw-r--r--compatibility-client/src/main/java/com/vaadin/v7/client/ui/AbstractLegacyComponentConnector.java18
-rw-r--r--compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java11
-rw-r--r--compatibility-client/src/main/java/com/vaadin/v7/client/ui/tree/TreeConnector.java4
-rw-r--r--compatibility-shared/src/main/java/com/vaadin/v7/shared/AbstractLegacyComponentState.java1
-rw-r--r--server/src/main/java/com/vaadin/ui/AbstractComponent.java32
-rw-r--r--shared/src/main/java/com/vaadin/shared/AbstractComponentState.java1
-rw-r--r--shared/src/main/java/com/vaadin/shared/AbstractFieldState.java5
13 files changed, 108 insertions, 50 deletions
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
@@ -86,15 +86,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<SELECTIONMODEL extends SelectionModel<?>>
- extends AbstractComponentConnector implements HasDataSource {
+ extends AbstractFieldConnector implements HasDataSource {
private DataSource<JsonObject> dataSource = null;
@@ -64,7 +64,7 @@ public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionM
/**
* Returns the selection model instance used.
- *
+ *
* @return the selection model
*/
public SELECTIONMODEL getSelectionModel() {
@@ -73,7 +73,7 @@ public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionM
/**
* Returns the key of the given data row.
- *
+ *
* @param row
* the row
* @return the row key
@@ -84,7 +84,7 @@ public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionM
/**
* Returns the data of the given data row.
- *
+ *
* @param row
* the row
* @return the row data
@@ -95,7 +95,7 @@ public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionM
/**
* Returns whether the given row is selected.
- *
+ *
* @param row
* the row
* @return {@code true} if the row is selected, {@code false} otherwise
diff --git a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
index 5fff238fd4..c2bf273e7d 100644
--- a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
@@ -628,10 +628,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector
// Set the core 'v' style name for the widget
setWidgetStyleName(StyleConstants.UI_WIDGET, true);
- // should be in AbstractFieldConnector ?
- // add / remove read-only style name
- setWidgetStyleName("v-readonly", isReadOnly());
-
// add / remove error style name
setWidgetStyleNameWithPrefix(primaryStyleName, StyleConstants.ERROR_EXT,
null != state.errorMessage);
@@ -730,17 +726,6 @@ public abstract class AbstractComponentConnector extends AbstractConnector
getWidget().setStyleName(prefix + styleName, add);
}
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.client.ComponentConnector#isReadOnly()
- */
- @Override
- @Deprecated
- public boolean isReadOnly() {
- return getState().readOnly;
- }
-
@Override
public LayoutManager getLayoutManager() {
return LayoutManager.get(getConnection());
diff --git a/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java
index fde1f548a0..7c6c681485 100644
--- a/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java
@@ -35,8 +35,20 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector
protected void updateWidgetStyleNames() {
super.updateWidgetStyleNames();
+ // add / remove read-only style name
+ setWidgetStyleName("v-readonly", isReadOnly());
+
// add / remove error style name to Fields
setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible());
}
+
+ /**
+ * Checks if the connector is read only.
+ *
+ * @return true
+ */
+ public boolean isReadOnly() {
+ return getState().readOnly;
+ }
}
diff --git a/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java b/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java
index f84b07d964..73c672c370 100644
--- a/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java
@@ -84,7 +84,7 @@ public class UploadConnector extends AbstractComponentConnector
}
getWidget().fu.setName(getWidget().paintableId + "_file");
- if (!isEnabled() || isReadOnly()) {
+ if (!isEnabled()) {
getWidget().disableUpload();
} else if (!uidl.getBooleanAttribute("state")) {
// Enable the button only if an upload is not in progress
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ComponentConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ComponentConnector.java
new file mode 100644
index 0000000000..792c435503
--- /dev/null
+++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ComponentConnector.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.v7.client;
+
+/**
+ * Legacy ComponentConnector with {@code isReadOnly}.
+ *
+ * @author teemusa
+ *
+ */
+public interface ComponentConnector
+ extends com.vaadin.client.ComponentConnector {
+
+ /**
+ * Checks if the connector is read only.
+ *
+ * @deprecated This belongs in AbstractFieldConnector, see #8514
+ * @return true
+ */
+ @Deprecated
+ public boolean isReadOnly();
+
+}
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/AbstractLegacyComponentConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/AbstractLegacyComponentConnector.java
index 5e27f26282..62b41cf9d8 100644
--- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/AbstractLegacyComponentConnector.java
+++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/AbstractLegacyComponentConnector.java
@@ -18,6 +18,7 @@ package com.vaadin.v7.client.ui;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.AbstractConnector;
import com.vaadin.shared.communication.ServerRpc;
+import com.vaadin.v7.client.ComponentConnector;
import com.vaadin.v7.shared.AbstractLegacyComponentState;
/**
@@ -30,8 +31,8 @@ import com.vaadin.v7.shared.AbstractLegacyComponentState;
* @deprecated only used for Vaadin 7 compatiblity components
*/
@Deprecated
-public class AbstractLegacyComponentConnector
- extends AbstractComponentConnector {
+public class AbstractLegacyComponentConnector extends AbstractComponentConnector
+ implements ComponentConnector {
// overridden to be visible to VUpload in the same package. Without making
// it public in VUploadConnector
@@ -44,4 +45,17 @@ public class AbstractLegacyComponentConnector
public AbstractLegacyComponentState getState() {
return (AbstractLegacyComponentState) super.getState();
}
+
+ @Override
+ public boolean isReadOnly() {
+ return getState().readOnly;
+ }
+
+ @Override
+ protected void updateWidgetStyleNames() {
+ super.updateWidgetStyleNames();
+
+ // add / remove read-only style name
+ setWidgetStyleName("v-readonly", isReadOnly());
+ }
}
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java
index e3f04aaa59..595a8ac6e8 100644
--- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java
+++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java
@@ -1,12 +1,12 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -40,7 +40,8 @@ import com.vaadin.v7.ui.Form;
@Connect(Form.class)
public class FormConnector extends AbstractComponentContainerConnector
- implements Paintable, MayScrollChildren {
+ implements Paintable, MayScrollChildren,
+ com.vaadin.v7.client.ComponentConnector {
private final ElementResizeListener footerResizeListener = new ElementResizeListener() {
@Override
@@ -179,7 +180,7 @@ public class FormConnector extends AbstractComponentContainerConnector
@Override
public boolean isReadOnly() {
- return super.isReadOnly() || getState().propertyReadOnly;
+ return getState().readOnly || getState().propertyReadOnly;
}
@Override
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/tree/TreeConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/tree/TreeConnector.java
index b4198f52da..a589e75697 100644
--- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/tree/TreeConnector.java
+++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/tree/TreeConnector.java
@@ -31,10 +31,10 @@ import com.vaadin.client.UIDL;
import com.vaadin.client.VConsole;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent;
-import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.MultiSelectMode;
+import com.vaadin.v7.client.ui.AbstractLegacyComponentConnector;
import com.vaadin.v7.client.ui.VTree;
import com.vaadin.v7.client.ui.VTree.TreeNode;
import com.vaadin.v7.shared.ui.tree.TreeConstants;
@@ -43,7 +43,7 @@ import com.vaadin.v7.shared.ui.tree.TreeState;
import com.vaadin.v7.ui.Tree;
@Connect(Tree.class)
-public class TreeConnector extends AbstractComponentConnector
+public class TreeConnector extends AbstractLegacyComponentConnector
implements Paintable {
protected final Map<TreeNode, TooltipInfo> tooltipMap = new HashMap<TreeNode, TooltipInfo>();
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;
+
}