diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2016-10-27 16:13:44 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-11-01 10:26:33 +0000 |
commit | 48c249a13ecca8c4c8bd68814850e5e3cdd37d81 (patch) | |
tree | b1f066b2bdd48b09b38b27bd677abba1b0d5d5fc /client | |
parent | 92d697b9886896f1dad41026ba3519563838f93e (diff) | |
download | vaadin-framework-48c249a13ecca8c4c8bd68814850e5e3cdd37d81.tar.gz vaadin-framework-48c249a13ecca8c4c8bd68814850e5e3cdd37d81.zip |
Replace setRequired & HasRequired with setRequiredIndicator
Vaadin 7 compatiblity fields still use setRequired via AbstractField (legacy).
Public setRequiredIndicator is added to AbstractField, AbstractMultiSelect and AbstractSingleSelect.
Internally it is still handled on AbstractComponent & -Connector level.
Changes the declarative syntax, required -> required-indicator-visible.
Fixes vaadin/framework8-issue#419
Change-Id: I940dc66944d27584bd78e5452aee627ee3abd03a
Diffstat (limited to 'client')
8 files changed, 91 insertions, 26 deletions
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 86dbe672e0..0dbe3cb331 100644 --- a/client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/AbstractMultiSelectConnector.java @@ -25,11 +25,13 @@ import com.google.gwt.user.client.ui.Composite; 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.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; @@ -44,7 +46,8 @@ import elemental.json.JsonObject; * @since 8.0 */ public abstract class AbstractMultiSelectConnector - extends AbstractListingConnector<SelectionModel.Multi<?>> { + extends AbstractListingConnector<SelectionModel.Multi<?>> + implements HasRequiredIndicator { /** * Abstraction layer to help populate different multiselect widgets based on @@ -148,14 +151,18 @@ public abstract class AbstractMultiSelectConnector protected void init() { super.init(); - MultiSelectServerRpc rpcProxy = getRpcProxy( - MultiSelectServerRpc.class); + MultiSelectServerRpc rpcProxy = getRpcProxy(MultiSelectServerRpc.class); getMultiSelectWidget().addSelectionChangeListener( (addedItems, removedItems) -> rpcProxy .updateSelection(addedItems, removedItems)); } @Override + public RequiredIndicatorState getState() { + return (RequiredIndicatorState) super.getState(); + } + + @Override public void setDataSource(DataSource<JsonObject> dataSource) { dataSource.addDataChangeHandler(this::onDataChange); super.setDataSource(dataSource); @@ -179,4 +186,9 @@ public abstract class AbstractMultiSelectConnector } getMultiSelectWidget().setItems(items); } + + @Override + public boolean isRequiredIndicatorVisible() { + return getState().required && !isReadOnly(); + } } diff --git a/client/src/main/java/com/vaadin/client/connectors/AbstractSingleSelectConnector.java b/client/src/main/java/com/vaadin/client/connectors/AbstractSingleSelectConnector.java new file mode 100644 index 0000000000..5554b8421c --- /dev/null +++ b/client/src/main/java/com/vaadin/client/connectors/AbstractSingleSelectConnector.java @@ -0,0 +1,44 @@ +/* + * 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.client.connectors; + +import com.google.gwt.event.dom.client.HasAllFocusHandlers; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.ui.HasRequiredIndicator; +import com.vaadin.shared.data.selection.SelectionModel; +import com.vaadin.shared.ui.AbstractSingleSelectState; + +/** + * An abstract class for single selection connectors. + * + * @author Vaadin Ltd + * @since 8.0.0 + */ +public abstract class AbstractSingleSelectConnector<WIDGET extends Widget & HasAllFocusHandlers> + extends + AbstractFocusableListingConnector<WIDGET, SelectionModel.Single<?>> + implements HasRequiredIndicator { + + @Override + public AbstractSingleSelectState getState() { + return (AbstractSingleSelectState) super.getState(); + } + + @Override + public boolean isRequiredIndicatorVisible() { + return getState().required && !isReadOnly(); + } +} 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 a6d73be0c8..5fff238fd4 100644 --- a/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/AbstractComponentConnector.java @@ -668,6 +668,13 @@ public abstract class AbstractComponentConnector extends AbstractConnector */ getWidget().setStylePrimaryName(state.primaryStyleName); } + + // set required style name if components supports that + if (this instanceof HasRequiredIndicator) { + getWidget().setStyleName(StyleConstants.REQUIRED, + ((HasRequiredIndicator) this).isRequiredIndicatorVisible()); + } + Profiler.leave("AbstractComponentConnector.updateWidgetStyleNames"); } 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 18834b2f8b..015b805ee1 100644 --- a/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/AbstractFieldConnector.java @@ -30,14 +30,6 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector return getState().modified; } - /** - * Checks whether the required indicator should be shown for the field. - * - * Required indicators are hidden if the field or its data source is - * read-only. - * - * @return true if required indicator should be shown - */ @Override public boolean isRequiredIndicatorVisible() { return getState().required && !isReadOnly(); @@ -58,8 +50,5 @@ public abstract class AbstractFieldConnector extends AbstractComponentConnector // add / remove error style name to Fields setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(), StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible()); - - getWidget().setStyleName(StyleConstants.REQUIRED, - isRequiredIndicatorVisible()); } } diff --git a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java index 96fa5ea3cd..97f382453f 100644 --- a/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/combobox/ComboBoxConnector.java @@ -22,6 +22,7 @@ import com.vaadin.client.connectors.AbstractListingConnector; import com.vaadin.client.connectors.data.HasDataSource; import com.vaadin.client.data.DataSource; import com.vaadin.client.ui.HasErrorIndicator; +import com.vaadin.client.ui.HasRequiredIndicator; import com.vaadin.client.ui.SimpleManagedLayout; import com.vaadin.client.ui.VComboBox; import com.vaadin.client.ui.VComboBox.DataReceivedHandler; @@ -42,7 +43,8 @@ import elemental.json.JsonObject; @Connect(ComboBox.class) public class ComboBoxConnector extends AbstractListingConnector<SelectionModel.Single<?>> - implements HasDataSource, SimpleManagedLayout, HasErrorIndicator { + implements HasRequiredIndicator, HasDataSource, SimpleManagedLayout, + HasErrorIndicator { private ComboBoxServerRpc rpc = getRpcProxy(ComboBoxServerRpc.class); private SelectionServerRpc selectionRpc = getRpcProxy( @@ -181,8 +183,8 @@ public class ComboBoxConnector page = 0; } } - int adjustment = (getWidget().nullSelectionAllowed - && "".equals(getWidget().lastFilter)) ? 1 : 0; + int adjustment = getWidget().nullSelectionAllowed + && "".equals(getWidget().lastFilter) ? 1 : 0; int startIndex = Math.max(0, page * getWidget().pageLength - adjustment); int pageLength = getWidget().pageLength > 0 ? getWidget().pageLength @@ -331,4 +333,8 @@ public class ComboBoxConnector dataChangeHandlerRegistration.remove(); } + @Override + public boolean isRequiredIndicatorVisible() { + return getState().required && !isReadOnly(); + } } diff --git a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java index 20c625a40d..18764f8b86 100644 --- a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java @@ -18,12 +18,11 @@ package com.vaadin.client.ui.nativeselect; import com.google.gwt.event.shared.HandlerRegistration; import com.vaadin.client.annotations.OnStateChange; -import com.vaadin.client.connectors.AbstractFocusableListingConnector; +import com.vaadin.client.connectors.AbstractSingleSelectConnector; import com.vaadin.client.data.DataSource; import com.vaadin.client.ui.VNativeSelect; import com.vaadin.shared.Range; import com.vaadin.shared.Registration; -import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.shared.data.selection.SelectionServerRpc; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.nativeselect.NativeSelectState; @@ -41,8 +40,8 @@ import elemental.json.JsonObject; * @since 8.0 */ @Connect(com.vaadin.ui.NativeSelect.class) -public class NativeSelectConnector extends - AbstractFocusableListingConnector<VNativeSelect, SelectionModel.Single<?>> { +public class NativeSelectConnector + extends AbstractSingleSelectConnector<VNativeSelect> { private HandlerRegistration selectionChangeRegistration; private Registration dataChangeRegistration; diff --git a/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java b/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java index 5955037e65..940287d583 100644 --- a/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/optiongroup/CheckBoxGroupConnector.java @@ -24,6 +24,7 @@ import java.util.List; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.connectors.AbstractFocusableListingConnector; import com.vaadin.client.data.DataSource; +import com.vaadin.client.ui.HasRequiredIndicator; import com.vaadin.client.ui.VCheckBoxGroup; import com.vaadin.shared.data.selection.MultiSelectServerRpc; import com.vaadin.shared.data.selection.SelectionModel; @@ -35,8 +36,11 @@ import elemental.json.JsonObject; @Connect(CheckBoxGroup.class) // We don't care about the framework-provided selection model at this point +// TODO refactor to extend AbstractMultiSelectConnector, maybe when +// SelectionModel is removed from client side framwork8-issues#421 public class CheckBoxGroupConnector extends - AbstractFocusableListingConnector<VCheckBoxGroup, SelectionModel<?>> { + AbstractFocusableListingConnector<VCheckBoxGroup, SelectionModel<?>> + implements HasRequiredIndicator { @Override protected void init() { @@ -84,4 +88,9 @@ public class CheckBoxGroupConnector extends return (CheckBoxGroupState) super.getState(); } + // TODO remove once this extends AbstractMultiSelectConnector + @Override + public boolean isRequiredIndicatorVisible() { + return getState().required && !isReadOnly(); + } } diff --git a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java index 4f3cad3c4c..13e39677d3 100644 --- a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java @@ -21,12 +21,11 @@ import java.util.List; import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.communication.StateChangeEvent; -import com.vaadin.client.connectors.AbstractFocusableListingConnector; +import com.vaadin.client.connectors.AbstractSingleSelectConnector; import com.vaadin.client.data.DataSource; import com.vaadin.client.ui.VRadioButtonGroup; import com.vaadin.shared.Range; import com.vaadin.shared.Registration; -import com.vaadin.shared.data.selection.SelectionModel; import com.vaadin.shared.data.selection.SelectionServerRpc; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.optiongroup.RadioButtonGroupState; @@ -35,8 +34,8 @@ import com.vaadin.ui.RadioButtonGroup; import elemental.json.JsonObject; @Connect(RadioButtonGroup.class) -public class RadioButtonGroupConnector extends - AbstractFocusableListingConnector<VRadioButtonGroup, SelectionModel.Single<?>> { +public class RadioButtonGroupConnector + extends AbstractSingleSelectConnector<VRadioButtonGroup> { private Registration selectionChangeRegistration; private Registration dataChangeRegistration; |