From: Teemu Suo-Anttila Date: Wed, 2 Nov 2016 09:02:16 +0000 (+0200) Subject: Clean up state hierarchy for AbstractFieldState X-Git-Tag: 8.0.0.alpha6~22 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=35c0e4dc46d9ef420e4cc45806cbb9f7e3fc85d8;p=vaadin-framework.git Clean up state hierarchy for AbstractFieldState Change-Id: I33c8c977bf8cd2d4c637d7988586496ce963465f --- diff --git a/client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java b/client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java index 0dbe3cb331..60966c39a9 100644 --- a/client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java @@ -26,12 +26,12 @@ import com.google.gwt.user.client.ui.IsWidget; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.data.DataSource; import com.vaadin.client.ui.HasRequiredIndicator; +import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.Range; import com.vaadin.shared.Registration; import com.vaadin.shared.data.selection.MultiSelectServerRpc; import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.shared.ui.ListingJsonConstants; -import com.vaadin.shared.ui.RequiredIndicatorState; import elemental.json.JsonObject; @@ -158,8 +158,8 @@ public abstract class AbstractMultiSelectConnector } @Override - public RequiredIndicatorState getState() { - return (RequiredIndicatorState) super.getState(); + public AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); } @Override 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 015b805ee1..fde1f548a0 100644 --- a/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java @@ -26,27 +26,15 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector return (AbstractFieldState) super.getState(); } - public boolean isModified() { - return getState().modified; - } - @Override public boolean isRequiredIndicatorVisible() { return getState().required && !isReadOnly(); } - @Override - public boolean isErrorIndicatorVisible() { - return super.isErrorIndicatorVisible() && !getState().hideErrors; - } - @Override protected void updateWidgetStyleNames() { super.updateWidgetStyleNames(); - // add / remove modified style name to Fields - setWidgetStyleName(StyleConstants.MODIFIED, isModified()); - // add / remove error style name to Fields setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(), StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible()); diff --git a/server/src/main/java/com/vaadin/ui/AbstractComponent.java b/server/src/main/java/com/vaadin/ui/AbstractComponent.java index 5d8c422a7c..f03f1f438f 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractComponent.java +++ b/server/src/main/java/com/vaadin/ui/AbstractComponent.java @@ -55,13 +55,13 @@ import com.vaadin.server.Sizeable; import com.vaadin.server.UserError; import com.vaadin.server.VaadinSession; import com.vaadin.shared.AbstractComponentState; +import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ContextClickRpc; import com.vaadin.shared.EventId; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.Registration; import com.vaadin.shared.ui.ComponentStateUtil; -import com.vaadin.shared.ui.RequiredIndicatorState; import com.vaadin.shared.util.SharedUtil; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; @@ -1386,27 +1386,27 @@ public abstract class AbstractComponent extends AbstractClientConnector * apply for all components!. *

* If the component supports the required indicator (state extends - * {@link RequiredIndicatorState}), then expose this method and + * {@link AbstractFieldState}), then expose this method and * {@link #isRequiredIndicatorVisible()} as {@code public} in the component * and call this method. *

* This method will throw a {@link IllegalStateException} if the component * state (returned by {@link #getState()}) does not inherit - * {@link RequiredIndicatorState}. + * {@link AbstractFieldState}. * * @param visible * true to make the required indicator visible, * false if not */ protected void setRequiredIndicatorVisible(boolean visible) { - if (getState(false) instanceof RequiredIndicatorState) { - ((RequiredIndicatorState) getState()).required = visible; + if (getState(false) instanceof AbstractFieldState) { + ((AbstractFieldState) getState()).required = visible; } else { throw new IllegalStateException( "This component does not support the required indicator, since state is of type " + getStateType().getSimpleName() + " and does not inherit " - + RequiredIndicatorState.class.getSimpleName()); + + AbstractFieldState.class.getSimpleName()); } } @@ -1416,20 +1416,20 @@ public abstract class AbstractComponent extends AbstractClientConnector *

* This method will throw a {@link IllegalStateException} if the component * state (returned by {@link #getState()}) does not inherit - * {@link RequiredIndicatorState}. + * {@link AbstractFieldState}. * * @return true if visible, false if not * @see #setRequiredIndicatorVisible(boolean) */ protected boolean isRequiredIndicatorVisible() { - if (getState(false) instanceof RequiredIndicatorState) { - return ((RequiredIndicatorState) getState(false)).required; + 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 " - + RequiredIndicatorState.class.getSimpleName()); + + AbstractFieldState.class.getSimpleName()); } } diff --git a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java index 52cd02481c..bd1fc8937a 100644 --- a/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java +++ b/server/src/main/java/com/vaadin/ui/AbstractMultiSelect.java @@ -32,12 +32,12 @@ import com.vaadin.server.Resource; import com.vaadin.server.ResourceReference; import com.vaadin.server.SerializablePredicate; import com.vaadin.server.data.DataGenerator; +import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.Registration; import com.vaadin.shared.data.selection.MultiSelectServerRpc; import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.shared.data.selection.SelectionModel.Multi; import com.vaadin.shared.ui.ListingJsonConstants; -import com.vaadin.shared.ui.RequiredIndicatorState; import com.vaadin.util.ReflectTools; import elemental.json.JsonObject; @@ -484,13 +484,13 @@ public abstract class AbstractMultiSelect } @Override - protected RequiredIndicatorState getState() { - return (RequiredIndicatorState) super.getState(); + protected AbstractFieldState getState() { + return (AbstractFieldState) super.getState(); } @Override - protected RequiredIndicatorState getState(boolean markAsDirty) { - return (RequiredIndicatorState) super.getState(markAsDirty); + protected AbstractFieldState getState(boolean markAsDirty) { + return (AbstractFieldState) super.getState(markAsDirty); } @Override diff --git a/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java b/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java index e24880c3af..6ac39efe69 100644 --- a/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java +++ b/shared/src/main/java/com/vaadin/shared/AbstractFieldState.java @@ -15,16 +15,20 @@ */ package com.vaadin.shared; -import com.vaadin.shared.ui.RequiredIndicatorState; +import com.vaadin.shared.ui.TabIndexState; /** - * Shared state for {@link com.vaadin.ui.AbstractField}. + * State for components that can show the required indicator. * * @author Vaadin Ltd - * @since 7.0.0 + * @since 8.0.0 * */ -public class AbstractFieldState extends RequiredIndicatorState { - public boolean hideErrors = false; - public boolean modified = false; +public class AbstractFieldState extends TabIndexState { + + /** + * Is the required indicator visible or not. + */ + public boolean required = false; + } diff --git a/shared/src/main/java/com/vaadin/shared/ui/AbstractSingleSelectState.java b/shared/src/main/java/com/vaadin/shared/ui/AbstractSingleSelectState.java index da4510bfdb..4cd9bdc9a2 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/AbstractSingleSelectState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/AbstractSingleSelectState.java @@ -15,6 +15,8 @@ */ package com.vaadin.shared.ui; +import com.vaadin.shared.AbstractFieldState; + /** * Shared state for {@code AbstractSingleSelect}. * @@ -22,7 +24,7 @@ package com.vaadin.shared.ui; * * @since 8.0 */ -public class AbstractSingleSelectState extends RequiredIndicatorState { +public class AbstractSingleSelectState extends AbstractFieldState { /** * The key of the currently selected item or {@code null} if no item is diff --git a/shared/src/main/java/com/vaadin/shared/ui/RequiredIndicatorState.java b/shared/src/main/java/com/vaadin/shared/ui/RequiredIndicatorState.java deleted file mode 100644 index b26a8ceb2b..0000000000 --- a/shared/src/main/java/com/vaadin/shared/ui/RequiredIndicatorState.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.shared.ui; - -/** - * State for components that can show the required indicator. - * - * @author Vaadin Ltd - * @since 8.0.0 - * - */ -public class RequiredIndicatorState extends TabIndexState { - - /** - * Is the required indicator visible or not. - */ - public boolean required; - -} diff --git a/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java b/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java index 8992dc6647..f90ca79368 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/listselect/ListSelectState.java @@ -15,8 +15,8 @@ */ package com.vaadin.shared.ui.listselect; +import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.annotations.DelegateToWidget; -import com.vaadin.shared.ui.RequiredIndicatorState; /** * Shared state for ListSelect component. @@ -24,7 +24,7 @@ import com.vaadin.shared.ui.RequiredIndicatorState; * @author Vaadin Ltd * */ -public class ListSelectState extends RequiredIndicatorState { +public class ListSelectState extends AbstractFieldState { { primaryStyleName = "v-select"; } diff --git a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupState.java b/shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupState.java index 82695a913c..93647c2a22 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/optiongroup/CheckBoxGroupState.java @@ -15,8 +15,8 @@ */ package com.vaadin.shared.ui.optiongroup; +import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.annotations.DelegateToWidget; -import com.vaadin.shared.ui.RequiredIndicatorState; /** * Shared state for the CheckBoxGroup component. @@ -24,7 +24,7 @@ import com.vaadin.shared.ui.RequiredIndicatorState; * @author Vaadin Ltd. * @since 8.0 */ -public class CheckBoxGroupState extends RequiredIndicatorState { +public class CheckBoxGroupState extends AbstractFieldState { { primaryStyleName = "v-select-optiongroup"; diff --git a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupState.java b/shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupState.java index bdd007613c..a7282b146d 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/optiongroup/RadioButtonGroupState.java @@ -15,7 +15,6 @@ */ package com.vaadin.shared.ui.optiongroup; -import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.ui.AbstractSingleSelectState; diff --git a/shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java b/shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java index fe1f1fab23..b0e148e656 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/twincolselect/TwinColSelectState.java @@ -15,15 +15,15 @@ */ package com.vaadin.shared.ui.twincolselect; +import com.vaadin.shared.AbstractFieldState; import com.vaadin.shared.annotations.DelegateToWidget; -import com.vaadin.shared.ui.RequiredIndicatorState; /** * Shared state for the TwinColSelect component. * * @since 7.0 */ -public class TwinColSelectState extends RequiredIndicatorState { +public class TwinColSelectState extends AbstractFieldState { { primaryStyleName = "v-select-twincol"; }