Skip to content

Commit

Permalink
Move read-only to AbstractFieldState (#8514)
Browse files Browse the repository at this point in the history
Change-Id: I0baea991bd80075d63c5d57e3b07f4e9fcb12676
  • Loading branch information
Teemu Suo-Anttila authored and Vaadin Code Review committed Nov 2, 2016
1 parent abd4e81 commit dd20841
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 50 deletions.
Expand Up @@ -85,15 +85,6 @@ public interface ComponentConnector extends ServerConnector {
*/ */
public boolean isRelativeHeight(); 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 * Return true if parent handles caption, false if the paintable handles the
* caption itself. * caption itself.
Expand Down
Expand Up @@ -17,7 +17,7 @@


import com.vaadin.client.connectors.data.HasDataSource; import com.vaadin.client.connectors.data.HasDataSource;
import com.vaadin.client.data.DataSource; 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.DataCommunicatorConstants;
import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.shared.data.selection.SelectionModel;
import com.vaadin.ui.AbstractListing; import com.vaadin.ui.AbstractListing;
Expand All @@ -36,7 +36,7 @@
* @since 8.0 * @since 8.0
*/ */
public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionModel<?>> public abstract class AbstractListingConnector<SELECTIONMODEL extends SelectionModel<?>>
extends AbstractComponentConnector implements HasDataSource { extends AbstractFieldConnector implements HasDataSource {


private DataSource<JsonObject> dataSource = null; private DataSource<JsonObject> dataSource = null;


Expand Down Expand Up @@ -64,7 +64,7 @@ public void setSelectionModel(SELECTIONMODEL selectionModel) {


/** /**
* Returns the selection model instance used. * Returns the selection model instance used.
* *
* @return the selection model * @return the selection model
*/ */
public SELECTIONMODEL getSelectionModel() { public SELECTIONMODEL getSelectionModel() {
Expand All @@ -73,7 +73,7 @@ public SELECTIONMODEL getSelectionModel() {


/** /**
* Returns the key of the given data row. * Returns the key of the given data row.
* *
* @param row * @param row
* the row * the row
* @return the row key * @return the row key
Expand All @@ -84,7 +84,7 @@ protected static String getRowKey(JsonObject row) {


/** /**
* Returns the data of the given data row. * Returns the data of the given data row.
* *
* @param row * @param row
* the row * the row
* @return the row data * @return the row data
Expand All @@ -95,7 +95,7 @@ protected static JsonValue getRowData(JsonObject row) {


/** /**
* Returns whether the given row is selected. * Returns whether the given row is selected.
* *
* @param row * @param row
* the row * the row
* @return {@code true} if the row is selected, {@code false} otherwise * @return {@code true} if the row is selected, {@code false} otherwise
Expand Down
Expand Up @@ -628,10 +628,6 @@ protected void updateWidgetStyleNames() {
// Set the core 'v' style name for the widget // Set the core 'v' style name for the widget
setWidgetStyleName(StyleConstants.UI_WIDGET, true); setWidgetStyleName(StyleConstants.UI_WIDGET, true);


// should be in AbstractFieldConnector ?
// add / remove read-only style name
setWidgetStyleName("v-readonly", isReadOnly());

// add / remove error style name // add / remove error style name
setWidgetStyleNameWithPrefix(primaryStyleName, StyleConstants.ERROR_EXT, setWidgetStyleNameWithPrefix(primaryStyleName, StyleConstants.ERROR_EXT,
null != state.errorMessage); null != state.errorMessage);
Expand Down Expand Up @@ -730,17 +726,6 @@ protected void setWidgetStyleNameWithPrefix(String prefix, String styleName,
getWidget().setStyleName(prefix + styleName, add); getWidget().setStyleName(prefix + styleName, add);
} }


/*
* (non-Javadoc)
*
* @see com.vaadin.client.ComponentConnector#isReadOnly()
*/
@Override
@Deprecated
public boolean isReadOnly() {
return getState().readOnly;
}

@Override @Override
public LayoutManager getLayoutManager() { public LayoutManager getLayoutManager() {
return LayoutManager.get(getConnection()); return LayoutManager.get(getConnection());
Expand Down
Expand Up @@ -35,8 +35,20 @@ public boolean isRequiredIndicatorVisible() {
protected void updateWidgetStyleNames() { protected void updateWidgetStyleNames() {
super.updateWidgetStyleNames(); super.updateWidgetStyleNames();


// add / remove read-only style name
setWidgetStyleName("v-readonly", isReadOnly());

// add / remove error style name to Fields // add / remove error style name to Fields
setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(), setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible()); StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible());
} }

/**
* Checks if the connector is read only.
*
* @return true
*/
public boolean isReadOnly() {
return getState().readOnly;
}
} }
Expand Up @@ -84,7 +84,7 @@ public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
} }
getWidget().fu.setName(getWidget().paintableId + "_file"); getWidget().fu.setName(getWidget().paintableId + "_file");


if (!isEnabled() || isReadOnly()) { if (!isEnabled()) {
getWidget().disableUpload(); getWidget().disableUpload();
} else if (!uidl.getBooleanAttribute("state")) { } else if (!uidl.getBooleanAttribute("state")) {
// Enable the button only if an upload is not in progress // Enable the button only if an upload is not in progress
Expand Down
@@ -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();

}
Expand Up @@ -18,6 +18,7 @@
import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.AbstractConnector; import com.vaadin.client.ui.AbstractConnector;
import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.v7.client.ComponentConnector;
import com.vaadin.v7.shared.AbstractLegacyComponentState; import com.vaadin.v7.shared.AbstractLegacyComponentState;


/** /**
Expand All @@ -30,8 +31,8 @@
* @deprecated only used for Vaadin 7 compatiblity components * @deprecated only used for Vaadin 7 compatiblity components
*/ */
@Deprecated @Deprecated
public class AbstractLegacyComponentConnector public class AbstractLegacyComponentConnector extends AbstractComponentConnector
extends AbstractComponentConnector { implements ComponentConnector {


// overridden to be visible to VUpload in the same package. Without making // overridden to be visible to VUpload in the same package. Without making
// it public in VUploadConnector // it public in VUploadConnector
Expand All @@ -44,4 +45,17 @@ protected <T extends ServerRpc> T getRpcProxy(Class<T> rpcInterface) {
public AbstractLegacyComponentState getState() { public AbstractLegacyComponentState getState() {
return (AbstractLegacyComponentState) super.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());
}
} }
@@ -1,12 +1,12 @@
/* /*
* Copyright 2000-2016 Vaadin Ltd. * Copyright 2000-2016 Vaadin Ltd.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
Expand Down Expand Up @@ -40,7 +40,8 @@


@Connect(Form.class) @Connect(Form.class)
public class FormConnector extends AbstractComponentContainerConnector public class FormConnector extends AbstractComponentContainerConnector
implements Paintable, MayScrollChildren { implements Paintable, MayScrollChildren,
com.vaadin.v7.client.ComponentConnector {


private final ElementResizeListener footerResizeListener = new ElementResizeListener() { private final ElementResizeListener footerResizeListener = new ElementResizeListener() {
@Override @Override
Expand Down Expand Up @@ -179,7 +180,7 @@ public VForm getWidget() {


@Override @Override
public boolean isReadOnly() { public boolean isReadOnly() {
return super.isReadOnly() || getState().propertyReadOnly; return getState().readOnly || getState().propertyReadOnly;
} }


@Override @Override
Expand Down
Expand Up @@ -31,10 +31,10 @@
import com.vaadin.client.VConsole; import com.vaadin.client.VConsole;
import com.vaadin.client.WidgetUtil; import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.MultiSelectMode; 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;
import com.vaadin.v7.client.ui.VTree.TreeNode; import com.vaadin.v7.client.ui.VTree.TreeNode;
import com.vaadin.v7.shared.ui.tree.TreeConstants; import com.vaadin.v7.shared.ui.tree.TreeConstants;
Expand All @@ -43,7 +43,7 @@
import com.vaadin.v7.ui.Tree; import com.vaadin.v7.ui.Tree;


@Connect(Tree.class) @Connect(Tree.class)
public class TreeConnector extends AbstractComponentConnector public class TreeConnector extends AbstractLegacyComponentConnector
implements Paintable { implements Paintable {


protected final Map<TreeNode, TooltipInfo> tooltipMap = new HashMap<TreeNode, TooltipInfo>(); protected final Map<TreeNode, TooltipInfo> tooltipMap = new HashMap<TreeNode, TooltipInfo>();
Expand Down
Expand Up @@ -29,4 +29,5 @@
public class AbstractLegacyComponentState extends AbstractComponentState { public class AbstractLegacyComponentState extends AbstractComponentState {
@NoLayout @NoLayout
public boolean immediate = false; public boolean immediate = false;
public boolean readOnly = false;
} }
32 changes: 23 additions & 9 deletions server/src/main/java/com/vaadin/ui/AbstractComponent.java
Expand Up @@ -1053,8 +1053,16 @@ public boolean isResponsive() {
* read-only mode or not * read-only mode or not
*/ */
protected void setReadOnly(boolean readOnly) { protected void setReadOnly(boolean readOnly) {
if (readOnly != isReadOnly()) { if (getState(false) instanceof AbstractFieldState) {
getState().readOnly = readOnly; 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());
} }
} }


Expand All @@ -1067,7 +1075,14 @@ protected void setReadOnly(boolean readOnly) {
* @see #setReadOnly(boolean) * @see #setReadOnly(boolean)
*/ */
protected boolean isReadOnly() { 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());
} }


/** /**
Expand Down Expand Up @@ -1424,13 +1439,12 @@ protected void setRequiredIndicatorVisible(boolean visible) {
protected boolean isRequiredIndicatorVisible() { protected boolean isRequiredIndicatorVisible() {
if (getState(false) instanceof AbstractFieldState) { if (getState(false) instanceof AbstractFieldState) {
return ((AbstractFieldState) getState(false)).required; 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() { private static final Logger getLogger() {
Expand Down
Expand Up @@ -31,7 +31,6 @@
public class AbstractComponentState extends SharedState { public class AbstractComponentState extends SharedState {
public String height = ""; public String height = "";
public String width = ""; public String width = "";
public boolean readOnly = false;
@NoLayout @NoLayout
public String description = ""; public String description = "";
// Note: for the caption, there is a difference between null and an empty // Note: for the caption, there is a difference between null and an empty
Expand Down
Expand Up @@ -31,4 +31,9 @@ public class AbstractFieldState extends TabIndexState {
*/ */
public boolean required = false; public boolean required = false;


/**
* Is the field read-only or not.
*/
public boolean readOnly = false;

} }

0 comments on commit dd20841

Please sign in to comment.