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
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;
* @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
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);
}
getMultiSelectWidget().setItems(items);
}
+
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return getState().required && !isReadOnly();
+ }
}
--- /dev/null
+/*
+ * 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();
+ }
+}
*/
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");
}
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();
// add / remove error style name to Fields
setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible());
-
- getWidget().setStyleName(StyleConstants.REQUIRED,
- isRequiredIndicatorVisible());
}
}
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;
@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(
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
dataChangeHandlerRegistration.remove();
}
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return getState().required && !isReadOnly();
+ }
}
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;
* @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;
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;
@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() {
return (CheckBoxGroupState) super.getState();
}
+ // TODO remove once this extends AbstractMultiSelectConnector
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return getState().required && !isReadOnly();
+ }
}
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;
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;
removePropertyListeners();
}
- /**
- * Is this field required. Required fields must filled by the user.
- *
- * If the field is required, it is visually indicated in the user interface.
- * Furthermore, setting field to be required implicitly adds "non-empty"
- * validator and thus isValid() == false or any isEmpty() fields. In those
- * cases validation errors are not painted as it is obvious that the user
- * must fill in the required fields.
- *
- * On the other hand, for the non-required fields isValid() == true if the
- * field isEmpty() regardless of any attached validators.
- *
- *
- * @return <code>true</code> if the field is required, otherwise
- * <code>false</code>.
- */
@Override
public boolean isRequired() {
return getState(false).required;
}
- /**
- * Sets the field required. Required fields must filled by the user.
- *
- * If the field is required, it is visually indicated in the user interface.
- * Furthermore, setting field to be required implicitly adds "non-empty"
- * validator and thus isValid() == false or any isEmpty() fields. In those
- * cases validation errors are not painted as it is obvious that the user
- * must fill in the required fields.
- *
- * On the other hand, for the non-required fields isValid() == true if the
- * field isEmpty() regardless of any attached validators.
- *
- * @param required
- * Is the field required.
- */
@Override
public void setRequired(boolean required) {
getState().required = required;
package com.vaadin.v7.ui;
-import com.vaadin.data.HasRequired;
-import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.ui.Component;
import com.vaadin.ui.Component.Focusable;
import com.vaadin.v7.data.BufferedValidatable;
@Deprecated
public interface Field<T> extends Component, BufferedValidatable, Property<T>,
Property.ValueChangeNotifier, Property.ValueChangeListener,
- Property.Editor, Focusable, HasRequired {
+ Property.Editor, Focusable {
/**
* Is this field required.
*
* <code>false</code>.
* @since 3.1
*/
- @Override
public boolean isRequired();
/**
* Is the field required.
* @since 3.1
*/
- @Override
public void setRequired(boolean required);
/**
+++ /dev/null
-/*
- * 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.data;
-
-import com.vaadin.ui.Component;
-
-/**
- * Interface implemented by field which can be marked as required. A required
- * status is handled by the parent layout.
- *
- * @since 8.0
- * @author Vaadin Ltd
- */
-public interface HasRequired extends Component {
-
- /**
- * Sets whether the field is required or not.
- *
- * If the field is required, it is visually indicated in the user interface.
- *
- * @param required
- * <code>true</code> to make the field required,
- * <code>false</code> otherwise
- */
- public void setRequired(boolean required);
-
- /**
- * Checks whether the field is required.
- *
- * @return <code>true</code> if the field is required, <code>false</code>
- * otherwise
- */
- public boolean isRequired();
-
-}
* This a shorthand method for {@link HasValue#getValue()} for the event
* source {@link #getSource()}. Thus the value is always the most recent
* one, even if has been changed after the firing of this event.
- *
+ *
* @see HasValue#getValue()
*
* @return the new value
public default boolean isEmpty() {
return Objects.equals(getValue(), getEmptyValue());
}
+
+ /**
+ * Sets the required indicator visible or not.
+ * <p>
+ * If set visible, it is visually indicated in the user interface.
+ *
+ * @param requiredIndicatorVisible
+ * <code>true</code> to make the required indicator visible,
+ * <code>false</code> if not
+ */
+ public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible);
+
+ /**
+ * Checks whether the required indicator is visible.
+ *
+ * @return <code>true</code> if visible, <code>false</code> if not
+ */
+ public boolean isRequiredIndicatorVisible();
}
import java.util.Objects;
-import com.vaadin.data.HasRequired;
+import com.vaadin.data.HasValue;
import com.vaadin.data.Result;
import com.vaadin.data.Validator;
import com.vaadin.data.util.converter.ValueContext;
* <p>
* If the field is required, it is visually indicated in the user interface.
* Furthermore, required fields requires "non-empty" validator. So in addition
- * to call {@link HasRequired#setRequired(boolean)} method one should add an
- * instance of this validator explicitly so the code looks like this:
+ * to call {@link HasRequired#setRequiredIndicatorVisible(boolean)} method one
+ * should add an instance of this validator explicitly so the code looks like
+ * this:
*
* <pre>
* <code>
* Binder<Bean,String, String> binder = new Binder<>();
* TextField name = new TextField();
- * name.setRequired(true);
+ * name.setRequiredIndicatorVisible(true);
* binder.forField(name).withValidator(
* new NonEmptyValidator("Name cannot be empty"))
* .bind(Bean::getName, Bean::setName);
* </code>
* </pre>
*
- * @see HasRequired
+ * @see HasValue#setRequiredIndicatorVisible(boolean)
* @author Vaadin Ltd
* @since 8.0
*
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;
}
/**
- * Returns true if the component is responsive
+ * Returns true if the component is responsive.
*
* @since 7.5.0
* @return true if the component is responsive
listener);
}
+ /**
+ * Sets the visibility of the required indicator. <strong>NOTE: Does not
+ * apply for all components!</strong>.
+ * <p>
+ * If the component supports the required indicator (state extends
+ * {@link RequiredIndicatorState}), then expose this method and
+ * {@link #isRequiredIndicatorVisible()} as {@code public} in the component
+ * and call this method.
+ * <p>
+ * This method will throw a {@link IllegalStateException} if the component
+ * state (returned by {@link #getState()}) does not inherit
+ * {@link RequiredIndicatorState}.
+ *
+ * @param visible
+ * <code>true</code> to make the required indicator visible,
+ * <code>false</code> if not
+ */
+ protected void setRequiredIndicatorVisible(boolean visible) {
+ if (getState(false) instanceof RequiredIndicatorState) {
+ ((RequiredIndicatorState) 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());
+ }
+ }
+
+ /**
+ * Checks whether the required indicator is visible or not. <strong>NOTE:
+ * Does not apply for all components!</strong>.
+ * <p>
+ * This method will throw a {@link IllegalStateException} if the component
+ * state (returned by {@link #getState()}) does not inherit
+ * {@link RequiredIndicatorState}.
+ *
+ * @return <code>true</code> if visible, <code>false</code> if not
+ * @see #setRequiredIndicatorVisible(boolean)
+ */
+ protected boolean isRequiredIndicatorVisible() {
+ if (getState(false) instanceof RequiredIndicatorState) {
+ return ((RequiredIndicatorState) 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());
+ }
+ }
+
private static final Logger getLogger() {
return Logger.getLogger(AbstractComponent.class.getName());
}
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
-import com.vaadin.data.HasRequired;
import com.vaadin.data.HasValue;
import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.Registration;
* the input value type
*/
public abstract class AbstractField<T> extends AbstractComponent
- implements HasValue<T>, HasRequired, Focusable {
+ implements HasValue<T>, Focusable {
@Deprecated
private static final Method VALUE_CHANGE_METHOD = ReflectTools.findMethod(
}
@Override
- public void setRequired(boolean required) {
- getState().required = required;
+ public void setRequiredIndicatorVisible(boolean visible) {
+ super.setRequiredIndicatorVisible(visible);
}
@Override
- public boolean isRequired() {
- return getState(false).required;
+ public boolean isRequiredIndicatorVisible() {
+ return super.isRequiredIndicatorVisible();
}
}
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;
this.itemEnabledProvider = itemEnabledProvider;
}
+ @Override
+ public void setRequiredIndicatorVisible(boolean visible) {
+ super.setRequiredIndicatorVisible(visible);
+ }
+
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return super.isRequiredIndicatorVisible();
+ }
+
+ @Override
+ protected RequiredIndicatorState getState() {
+ return (RequiredIndicatorState) super.getState();
+ }
+
+ @Override
+ protected RequiredIndicatorState getState(boolean markAsDirty) {
+ return (RequiredIndicatorState) super.getState(markAsDirty);
+ };
+
}
* The call is delegated to {@link #getSelectedItem()}
*
* @return the current selection, may be {@code null}
- *
+ *
* @see #getSelectedItem()
* @see Single#getSelectedItem
*/
* value is {@code null} then it deselects currently selected item.
* <p>
* The call is delegated to {@link #setSelectedItem(Object)}.
- *
+ *
* @see #setSelectedItem(Object)
* @see Single#setSelectedItem(Object)
*
protected AbstractSingleSelectState getState(boolean markAsDirty) {
return (AbstractSingleSelectState) super.getState(markAsDirty);
}
+
+ @Override
+ public void setRequiredIndicatorVisible(boolean visible) {
+ super.setRequiredIndicatorVisible(visible);
+ }
+
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return super.isRequiredIndicatorVisible();
+ }
}
}
};
+ @Override
+ public void setRequiredIndicatorVisible(boolean visible) {
+ super.setRequiredIndicatorVisible(visible);
+ }
+
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return super.isRequiredIndicatorVisible();
+ }
+
private static Logger getLogger() {
return Logger.getLogger(ColorPickerPopup.class.getName());
}
protected String getCss(Component c) {
return "background: " + color.getCSS();
}
+
+ @Override
+ public void setRequiredIndicatorVisible(boolean visible) {
+ super.setRequiredIndicatorVisible(visible);
+ }
+
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return super.isRequiredIndicatorVisible();
+ }
}
* declarative test for a real component should extend it and implement abstract
* methods to be able to test the common properties. Components specific
* properties should be tested additionally in the subclasses implementations.
- *
+ *
* @author Vaadin Ltd
*
*/
public void requiredDeserialization()
throws InstantiationException, IllegalAccessException {
boolean isRequired = true;
- String design = String.format("<%s required/>", getComponentTag());
+ String design = String.format("<%s required-indicator-visible/>",
+ getComponentTag());
T component = getComponentClass().newInstance();
- component.setRequired(isRequired);
+ component.setRequiredIndicatorVisible(isRequired);
testRead(design, component);
testWrite(design, component);
}
*/
package com.vaadin.shared;
-import com.vaadin.shared.ui.TabIndexState;
+import com.vaadin.shared.ui.RequiredIndicatorState;
/**
* Shared state for {@link com.vaadin.ui.AbstractField}.
* @since 7.0.0
*
*/
-public class AbstractFieldState extends TabIndexState {
+public class AbstractFieldState extends RequiredIndicatorState {
public boolean hideErrors = false;
- public boolean required = false;
public boolean modified = false;
}
/*
* 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
*
* @since 8.0
*/
-public class AbstractSingleSelectState extends TabIndexState {
+public class AbstractSingleSelectState extends RequiredIndicatorState {
/**
* The key of the currently selected item or {@code null} if no item is
--- /dev/null
+/*
+ * 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;
+
+}
import com.vaadin.shared.annotations.NoLayout;
/**
- * Interface implemented by state classes that support tab indexes.
+ * State for components that support tab indexes.
*
* @author Vaadin Ltd
* @since 7.0.0
package com.vaadin.shared.ui.listselect;
import com.vaadin.shared.annotations.DelegateToWidget;
-import com.vaadin.shared.ui.TabIndexState;
+import com.vaadin.shared.ui.RequiredIndicatorState;
/**
* Shared state for ListSelect component.
* @author Vaadin Ltd
*
*/
-public class ListSelectState extends TabIndexState {
+public class ListSelectState extends RequiredIndicatorState {
{
primaryStyleName = "v-select";
}
package com.vaadin.shared.ui.optiongroup;
import com.vaadin.shared.annotations.DelegateToWidget;
-import com.vaadin.shared.AbstractFieldState;
+import com.vaadin.shared.ui.RequiredIndicatorState;
/**
* Shared state for the CheckBoxGroup component.
* @author Vaadin Ltd.
* @since 8.0
*/
-public class CheckBoxGroupState extends AbstractFieldState {
+public class CheckBoxGroupState extends RequiredIndicatorState {
{
primaryStyleName = "v-select-optiongroup";
package com.vaadin.shared.ui.twincolselect;
import com.vaadin.shared.annotations.DelegateToWidget;
-import com.vaadin.shared.ui.TabIndexState;
+import com.vaadin.shared.ui.RequiredIndicatorState;
/**
* Shared state for the TwinColSelect component.
*
* @since 7.0
*/
-public class TwinColSelectState extends TabIndexState {
+public class TwinColSelectState extends RequiredIndicatorState {
{
primaryStyleName = "v-select-twincol";
}
import java.util.List;
import java.util.Locale;
-import com.vaadin.data.HasRequired;
+import com.vaadin.data.HasValue;
import com.vaadin.server.Resource;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.UserError;
// TODO Move to AbstractFieldTestCase
protected Command<T, Boolean> requiredCommand = (c, enabled, data) -> {
- if (c instanceof HasRequired) {
- ((HasRequired) c).setRequired(enabled);
+ if (c instanceof HasValue) {
+ ((HasValue) c).setRequiredIndicatorVisible(enabled);
+ } else if (c instanceof Field) {
+ ((Field) c).setRequired(enabled);
} else {
throw new IllegalArgumentException(c.getClass().getName()
+ " is not a field and cannot be set to required");
import java.util.LinkedHashMap;
import java.util.List;
-import com.vaadin.data.HasRequired;
+import com.vaadin.data.HasValue;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.v7.data.Item;
+import com.vaadin.v7.ui.Field;
import com.vaadin.v7.ui.NativeSelect;
public abstract class ComponentTestCase<T extends AbstractComponent>
actions.add(createReadonlyAction(false));
actions.add(createErrorIndicatorAction(false));
- if (HasRequired.class.isAssignableFrom(getTestClass())) {
+ if (HasValue.class.isAssignableFrom(getTestClass())
+ || Field.class.isAssignableFrom(getTestClass())) {
actions.add(createRequiredAction(false));
}
final AbstractDateField df = new TestDateField();
df.setValue(LocalDate.of(1970, 1, 15));
df.setWidth("200px");
- df.setRequired(true);
+ df.setRequiredIndicatorVisible(true);
df.setComponentError(new UserError("abc"));
df.addStyleName("popup-style");
addComponent(df);
import java.util.ArrayList;
import java.util.List;
-import com.vaadin.data.HasRequired;
+import com.vaadin.data.HasValue;
import com.vaadin.server.ThemeResource;
import com.vaadin.server.UserError;
import com.vaadin.tests.components.TestBase;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
+import com.vaadin.v7.ui.Field;
import com.vaadin.v7.ui.NativeSelect;
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.PasswordField;
protected void setRequired(boolean value) {
for (AbstractComponent c : components) {
- if (c instanceof HasRequired) {
- ((HasRequired) c).setRequired(value);
+ if (c instanceof HasValue) {
+ ((HasValue) c).setRequiredIndicatorVisible(value);
+ } else if (c instanceof Field) {
+ ((Field) c).setRequired(value);
}
}
CheckBox control = new CheckBox("Messages On/Off");
control.addValueChangeListener(event -> {
messages.setVisible(event.getValue());
- messages.setRequired(true);
+ messages.setRequiredIndicatorVisible(true);
messages.setCaption("Messages visible");
});
formLayout.addComponent(control);
tf = new TextArea("100% high TextField");
tf.setCaption(null);
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setValue("100% high Field");
tf.setHeight("100%");
tf.setWidth("100px");
tf = new TextArea("100% high TextField");
tf.setCaption("100% high TextField");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setValue("100% high Field");
tf.setHeight("100%");
tf.setWidth("100px");
tf.setValue("60% x 100% TextField");
tf.setWidth("100%");
tf.setHeight("100%");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
// tf.setComponentError(new UserError("It's broken!"));
// tf.setHeight("100%");
tf.setValue("60% x 60% TextField");
tf.setWidth("100%");
tf.setHeight("60%");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
ol.addComponent(tf);
ol.setExpandRatio(tf, 1f);
ol.setComponentAlignment(tf, Alignment.MIDDLE_LEFT);
tf.setValue("200x200 TextField");
tf.setWidth("200px");
tf.setHeight("200px");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
// tf.setComponentError(new UserError("It's broken!"));
// tf.setHeight("100%");
tf = new TextArea("200x200px Field");
tf.setCaption("This one has a caption");
tf.setWidth("200px");
- tf.setHeight(((i + 1) * 50) + "px");
+ tf.setHeight((i + 1) * 50 + "px");
tf.setValue(tf.getWidth() + "x" + tf.getHeight() + " TextField");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
// tf.setComponentError(new UserError("It's broken!"));
// tf.setHeight("100%");
tf = new TextField(
"A very long caption which is probably much longer than the field and includes indicators");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("abc123"));
ol.addComponent(tf);
tf = new TextField(
"A long caption which is probably much longer than the field");
tf.setValue("Undefined width");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("123"));
ol.addComponent(tf);
ol.setComponentAlignment(tf, Alignment.BOTTOM_RIGHT);
"A very long caption which is probably much longer than the field and includes indicators");
tf.setValue("Undefined width");
tf.setIcon(new ThemeResource("icons/16/document-add.png"));
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("abc123"));
ol.addComponent(tf);
ol.setComponentAlignment(tf, Alignment.BOTTOM_RIGHT);
"A long caption which is probably much longer than the field");
tf.setValue("100% wide field, ratio 2");
tf.setSizeFull();
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("123"));
ol.addComponent(tf);
ol.setComponentAlignment(tf, Alignment.BOTTOM_RIGHT);
tf.setValue("100% wide field, ratio 3");
tf.setSizeFull();
tf.setIcon(new ThemeResource("icons/16/document-add.png"));
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("abc123"));
ol.addComponent(tf);
ol.setComponentAlignment(tf, Alignment.BOTTOM_RIGHT);
"A long caption which is probably much longer than the field");
tf.setWidth("250px");
tf.setValue("250px wide field");
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("123"));
ol.addComponent(tf);
ol.setComponentAlignment(tf, Alignment.BOTTOM_RIGHT);
tf.setValue("200px wide field");
tf.setWidth("200px");
tf.setIcon(new ThemeResource("icons/16/document-add.png"));
- tf.setRequired(true);
+ tf.setRequiredIndicatorVisible(true);
tf.setComponentError(new UserError("abc123"));
ol.addComponent(tf);
ol.setComponentAlignment(tf, Alignment.BOTTOM_RIGHT);
ta.setValue("60% x 100% TextField");
ta.setWidth("60%");
ta.setHeight("100%");
- ta.setRequired(true);
+ ta.setRequiredIndicatorVisible(true);
ta.setRows(2);
ol.addComponent(ta);
}
public void validate() {
- if (isRequired() && !getValue()) {
+ if (isRequiredIndicatorVisible() && !getValue()) {
throw new InvalidValueException(
"Required CheckBox should be checked");
}