]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move read-only to AbstractFieldState (#8514)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Wed, 2 Nov 2016 09:20:23 +0000 (11:20 +0200)
committerVaadin Code Review <review@vaadin.com>
Wed, 2 Nov 2016 12:13:18 +0000 (12:13 +0000)
Change-Id: I0baea991bd80075d63c5d57e3b07f4e9fcb12676

13 files changed:
client/src/main/java/com/vaadin/client/ComponentConnector.java
client/src/main/java/com/vaadin/client/connectors/AbstractListingConnector.java
client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java
client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java
client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java
compatibility-client/src/main/java/com/vaadin/v7/client/ComponentConnector.java [new file with mode: 0644]
compatibility-client/src/main/java/com/vaadin/v7/client/ui/AbstractLegacyComponentConnector.java
compatibility-client/src/main/java/com/vaadin/v7/client/ui/form/FormConnector.java
compatibility-client/src/main/java/com/vaadin/v7/client/ui/tree/TreeConnector.java
compatibility-shared/src/main/java/com/vaadin/v7/shared/AbstractLegacyComponentState.java
server/src/main/java/com/vaadin/ui/AbstractComponent.java
shared/src/main/java/com/vaadin/shared/AbstractComponentState.java
shared/src/main/java/com/vaadin/shared/AbstractFieldState.java

index c9c793d7143add1177e3d3a5f148c68b3ea8c07b..e7f29b3b5bbba2a75579bb2efee3d6e588b08f20 100644 (file)
@@ -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.
index 6593b5a0be68e878a2ac789820b5727acd64cdc3..b89106307e76bdaa30e09c3b1a140ca0dc8c1051 100644 (file)
@@ -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
index 5fff238fd4ec784e323f8500e507266ee2c706a6..c2bf273e7dbadc0937798742658834886b11930f 100644 (file)
@@ -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());
index fde1f548a07463bbbcca647c4ee3471671f8a437..7c6c6814857e89c2eb2cbc5bd8619d0b6d530d9e 100644 (file)
@@ -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;
+    }
 }
index f84b07d9646f1b56f19685203e999aaa161e07a9..73c672c370eb8814eb8ccffcc3f49ee6db5881e0 100644 (file)
@@ -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 (file)
index 0000000..792c435
--- /dev/null
@@ -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();
+
+}
index 5e27f26282bf7cce025e6be51a5c9885627db433..62b41cf9d85eebedfd7cf1c0e194bc61102897f5 100644 (file)
@@ -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());
+    }
 }
index e3f04aaa59ef5a88fc0db3dc9f06e0c7927b69e9..595a8ac6e8cf1b0fff89de77e396da41ffe85e6f 100644 (file)
@@ -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
index b4198f52da428572b8c25d337ffef04a1ad5c9ab..a589e75697c8512fc9d3e81b56db5bf9d8916fcf 100644 (file)
@@ -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>();
index adb6d96ae2118d48ab6d1221c022d253de9b5a54..5471f6da2e81265f35fda668537ef9f829eb7bc0 100644 (file)
@@ -29,4 +29,5 @@ import com.vaadin.shared.annotations.NoLayout;
 public class AbstractLegacyComponentState extends AbstractComponentState {
     @NoLayout
     public boolean immediate = false;
+    public boolean readOnly = false;
 }
index f03f1f438f53f8d0cbee97be67f237f2255e631a..dd6e44735d41c27c7b0f7a8df789602401e1179a 100644 (file)
@@ -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() {
index bcf28859893f769922068c70c04761316c36694a..a60ae7aaf53ed1a2d2a3197261ef014c9707d3b9 100644 (file)
@@ -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
index 6ac39efe693e9f4eb1bb361274197bc0ddf2133a..4a94a82fecab0d3e0f60c518434c2310b3470506 100644 (file)
@@ -31,4 +31,9 @@ public class AbstractFieldState extends TabIndexState {
      */
     public boolean required = false;
 
+    /**
+     * Is the field read-only or not.
+     */
+    public boolean readOnly = false;
+
 }