All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fluorumlabs.disconnect.vaadin.CheckboxGroup Maven / Gradle / Ivy

The newest version!
package com.github.fluorumlabs.disconnect.vaadin;

import com.github.fluorumlabs.disconnect.core.annotations.WebComponent;
import com.github.fluorumlabs.disconnect.polymer.types.BooleanPropertyChangeEvent;
import com.github.fluorumlabs.disconnect.polymer.types.StringArrayPropertyChangeEvent;
import com.github.fluorumlabs.disconnect.vaadin.elements.CheckboxGroupElement;
import com.github.fluorumlabs.disconnect.vaadin.mixins.HasThemableMixin;
import com.github.fluorumlabs.disconnect.vaadin.types.ThemeVariant;
import com.github.fluorumlabs.disconnect.zero.component.AbstractComponent;
import com.github.fluorumlabs.disconnect.zero.component.Component;
import com.github.fluorumlabs.disconnect.zero.component.HasComponents;
import com.github.fluorumlabs.disconnect.zero.component.HasStyle;
import com.github.fluorumlabs.disconnect.zero.observable.ObservableEvent;
import com.github.fluorumlabs.disconnect.zero.observable.ObservableValue;
import js.extras.JsEnum;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * <vaadin-checkbox-group> is a Polymer element for grouping vaadin-checkboxes.
 *
 * 
<vaadin-checkbox-group label="Preferred language of contact:">
 *  <vaadin-checkbox value="en">English</vaadin-checkbox>
 *  <vaadin-checkbox value="fr">Français</vaadin-checkbox>
 *  <vaadin-checkbox value="de">Deutsch</vaadin-checkbox>
 * </vaadin-checkbox-group>
 * 
*

Styling

* The following shadow DOM parts are available for styling: * * * * * * * * * * *
Part nameDescription
labelThe label element
group-fieldThe element that wraps checkboxes
error-messageThe error message element
* The following state attributes are available for styling: * * * * * * * * * * * * * *
AttributeDescriptionPart name
disabledSet when the checkbox group and its children are disabled * .:host
focusedSet when the checkbox group contains focus:host
has-labelSet when the element has a label:host
has-valueSet when the element has a value:host
requiredSet when the element is required:host
invalidSet when the element is invalid:host
* See * ThemableMixin – how to apply styles for shadow parts */ @WebComponent public class CheckboxGroup extends AbstractComponent implements HasThemableMixin, HasStyle, HasComponents> { public CheckboxGroup() { super(CheckboxGroupElement.TAGNAME()); } public CheckboxGroup(String label) { this(); label(label); } /** * The current disabled state of the checkbox group. True if group and all internal checkboxes are disabled. */ public boolean disabled() { return getNode().isDisabled(); } /** * The current disabled state of the checkbox group. True if group and all internal checkboxes are disabled. */ public CheckboxGroup disabled(boolean disabled) { getNode().setDisabled(disabled); return this; } /** * String used for the label element. */ @Nullable public String label() { return getNode().getLabel(); } /** * String used for the label element. */ public CheckboxGroup label(String label) { getNode().setLabel(label); return this; } /** * Value of the checkbox group. * Note: toggling the checkboxes modifies the value by creating new * array each time, to override Polymer dirty-checking for arrays. * You can still use Polymer array mutation methods to update the value. */ public ObservableValue> value() { return createObservableValue(this::getValue, this::setValue, valueChangedEvent()); } /** * Value of the checkbox group. * Note: toggling the checkboxes modifies the value by creating new * array each time, to override Polymer dirty-checking for arrays. * You can still use Polymer array mutation methods to update the value. */ private Set getValue() { Set set = new LinkedHashSet<>(); String[] values = getNode().getValue(); if (values != null) { set.addAll(Arrays.asList(values)); } return set; } /** * Value of the checkbox group. * Note: toggling the checkboxes modifies the value by creating new * array each time, to override Polymer dirty-checking for arrays. * You can still use Polymer array mutation methods to update the value. */ private void setValue(Set value) { getNode().setValue(value == null ? null : value.toArray(new String[]{})); } /** * Error to show when the input value is invalid. */ @Nullable public String errorMessage() { return getNode().getErrorMessage(); } /** * Error to show when the input value is invalid. */ public CheckboxGroup errorMessage(String errorMessage) { getNode().setErrorMessage(errorMessage); return this; } /** * Specifies that the user must fill in a value. */ public boolean required() { return getNode().isRequired(); } /** * Specifies that the user must fill in a value. */ public CheckboxGroup required(boolean required) { getNode().setRequired(required); return this; } /** * This property is set to true when the control value is invalid. */ public boolean invalid() { return getNode().isInvalid(); } /** * This property is set to true when the control value is invalid. */ public CheckboxGroup invalid(boolean invalid) { getNode().setInvalid(invalid); return this; } /** * Returns true if value is valid. * <iron-form> uses this to check the validity or all its elements. * * @return True if the value is valid. */ public boolean validate() { return getNode().validate(); } /** * Fired when the value property changes. */ public ObservableEvent valueChangedEvent() { return createEvent("value-changed"); } /** * Fired when the invalid property changes. */ public ObservableEvent invalidChangedEvent() { return createEvent("invalid-changed"); } public abstract static class Variant extends ThemeVariant { public static final Variant VERTICAL = JsEnum.of("vertical"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy