Class AbstractSuperNumberField<T extends Number,​SELF extends AbstractSuperNumberField<T,​SELF>>

    • Constructor Detail

      • AbstractSuperNumberField

        protected AbstractSuperNumberField​(T defaultValue,
                                           com.vaadin.flow.function.SerializablePredicate<T> negativityPredicate,
                                           com.vaadin.flow.function.SerializableFunction<T,​T> turnToPositiveOperator,
                                           String label,
                                           Locale locale,
                                           int maxFractionDigits)
        Creates the field.
        Parameters:
        defaultValue - Default value to use on startup and when there are errors.
        negativityPredicate - Check for whether or not given value is negative.
        turnToPositiveOperator - Operation to turn number into a positive one.
        label - Label of the field.
        locale - Locale to use.
        maxFractionDigits - Max number of fraction digits. Overwrites the settings in format obtained based on locale. Negative value means leaving whatever is supported by the format.
    • Method Detail

      • escapeDot

        protected static String escapeDot​(char character)
        Escapes the DOT for regular expression, if needed.
        Parameters:
        character - Character to escape.
        Returns:
        Dot escaped or the passed character.
      • getLocale

        public Locale getLocale()
        Description copied from interface: HasLocale
        Returns locale associated with this object.
        Specified by:
        getLocale in interface HasLocale
        Overrides:
        getLocale in class com.vaadin.flow.component.Component
        Returns:
        A Locale. Never null.
      • setDecimalFormat

        public void setDecimalFormat​(DecimalFormat format)
        Sets the format definition used to displaying the value. Note: subclasses may overwrite the data in the format to make sure it follows type-specific constraints. Also note: changes to the format object may result in unpredictable behaviour of this component.
        Parameters:
        format - DecimalFormat to use. When null, NumberFormat.getNumberInstance() will be used.
      • isIntegerPartOptional

        protected boolean isIntegerPartOptional()
        Checks whether the integer part of a floating-point number is optional.
        Returns:
        Whether the integer part is optional (false by default - integer part is required).
      • setIntegerPartOptional

        protected void setIntegerPartOptional​(boolean optional)
        Sets whether the integer part of a floating-point number is optional. If it is set as optional, numbers can be entered without the integer part, which will be defaulted to zero.
        Parameters:
        optional - Whether the integer part is optional.
      • setMinimumFractionDigits

        protected void setMinimumFractionDigits​(int digits)
        Sets the minimum number of fraction digits displayed. Overwrites the value in the underlying DecimalFormat. Will be overwritten by calls to setDecimalFormat(DecimalFormat). Calls to setLocale(Locale) will preserve this value. Note: this is non-destructive, the underlying value of the field will not change (even though the representation will).
        Parameters:
        digits - Number of digits to use.
      • setMaximumFractionDigits

        protected void setMaximumFractionDigits​(int digits)
        Sets the maximum number of fraction digits displayed and allowed. Overwrites the value in the underlying DecimalFormat. Will be overwritten by calls to setDecimalFormat(DecimalFormat). Calls to setLocale(Locale) will preserve this value. Note: this is non-destructive, the underlying value of the field will not change (even though the representation will).
        Parameters:
        digits - Number of digits to use.
      • setMaximumIntegerDigits

        public void setMaximumIntegerDigits​(int digits)
        Sets the maximum number of integer digits (before decimal point) displayed and allowed. Overwrites the value in the underlying DecimalFormat. Will be overwritten by calls to setDecimalFormat(DecimalFormat). Calls to setLocale(Locale) will preserve this value. Note: this is non-destructive, the underlying value of the field will not change (even though the representation will).
        Parameters:
        digits - Number of digits to use.
      • updateRegularExpression

        protected final void updateRegularExpression​(boolean ignoreValueChangeFromField)
        Builds the regular expression and optionally ignores value change events from the underlying field. Basically allows the representation of the value to be changed, but not the value itself.
        Parameters:
        ignoreValueChangeFromField - Whether to ignore value change events coming from the underlying field.
      • updateRegularExpression

        protected final void updateRegularExpression()
        Builds the regular expression for matching the input.
      • buildRegularExpression

        protected StringBuilder buildRegularExpression​(StringBuilder builder,
                                                       DecimalFormat format)
        Builds regular expression that allows neat typing of the number already formatted. Overwrite with care.
        Parameters:
        builder - Builder, initially empty.
        format - Information about the format.
        Returns:
        Builder with the regular expression.
      • updateFieldValue

        protected void updateFieldValue()
        This method is called when the field loses its focus. Do not overwrite it without a very good reason.
      • getRegexp

        public String getRegexp()
        Returns the regular expression that matches the numbers as they are typed.
        Returns:
        A string with the regular expression.
      • setPresentationValue

        protected final void setPresentationValue​(T number)
        Specified by:
        setPresentationValue in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • parseRawValue

        protected abstract T parseRawValue​(String rawValue,
                                           DecimalFormat format)
                                    throws ParseException
        Parses (somewhat) raw value from the text field into a proper typed value.
        Parameters:
        rawValue - Value from text field.
        format - Format to use.
        Returns:
        Parsed value.
        Throws:
        ParseException - When parsing goes wrong.
        NullPointerException - This will also be caught by the calling function, so beware.
      • generateModelValue

        protected T generateModelValue()
        Specified by:
        generateModelValue in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • isAutoselect

        public boolean isAutoselect()
        Whether or not the component is auto-selecting upon focus. Defaults to false.
        Returns:
        true when the component will automatically select its text upon receiving focus, false otherwise.
      • setAutoselect

        public void setAutoselect​(boolean autoselect)
        Changes whether or not the component will be auto-selecting upon focus.
        Parameters:
        autoselect - true when the component should automatically select its text upon receiving focus, false otherwise.
      • isGroupingSeparatorHiddenOnFocus

        public boolean isGroupingSeparatorHiddenOnFocus()
        Whether or not grouping separator (used typically for thousands) should be hidden when the component gets focused. Grouping separators are always shown when the component is not focused. Defaults to false.
        Returns:
        true when the value is shown without grouping separator upon focusing, false otherwise.
      • setGroupingSeparatorHiddenOnFocus

        public void setGroupingSeparatorHiddenOnFocus​(boolean groupingSeparatorHiddenOnFocus)
        Changes whether or not grouping separator (used typically for thousands) should be hidden when the component gets focused. Grouping separators are always shown when the component is not focused.
        Parameters:
        groupingSeparatorHiddenOnFocus - true when the value should be shown without grouping separator upon focusing, false otherwise.
      • isNegativeValueAllowed

        public boolean isNegativeValueAllowed()
        Whether or not negative values are allowed. Defaults to true.
        Returns:
        true when negative values are allowed, false when not.
      • setNegativeValueAllowed

        public void setNegativeValueAllowed​(boolean negativeValueAllowed)
        Changes whether or not negative values are allowed. If this is changed while the value entered is negative, it will be switched to positive.
        Parameters:
        negativeValueAllowed - true when negative values should be allowed, false when not.
      • setPrefixComponent

        public void setPrefixComponent​(com.vaadin.flow.component.Component component)
        Specified by:
        setPrefixComponent in interface com.vaadin.flow.component.textfield.HasPrefixAndSuffix
      • getPrefixComponent

        public com.vaadin.flow.component.Component getPrefixComponent()
        Specified by:
        getPrefixComponent in interface com.vaadin.flow.component.textfield.HasPrefixAndSuffix
      • setSuffixComponent

        public void setSuffixComponent​(com.vaadin.flow.component.Component component)
        Specified by:
        setSuffixComponent in interface com.vaadin.flow.component.textfield.HasPrefixAndSuffix
      • getSuffixComponent

        public com.vaadin.flow.component.Component getSuffixComponent()
        Specified by:
        getSuffixComponent in interface com.vaadin.flow.component.textfield.HasPrefixAndSuffix
      • setLabel

        public void setLabel​(String label)
        Specified by:
        setLabel in interface com.vaadin.flow.component.HasLabel
        Overrides:
        setLabel in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • getLabel

        public String getLabel()
        Specified by:
        getLabel in interface com.vaadin.flow.component.HasLabel
        Overrides:
        getLabel in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • setPlaceholder

        public void setPlaceholder​(String placeholder)
        Description copied from interface: HasPlaceholder
        Sets the placeholder text for this object.
        Specified by:
        setPlaceholder in interface HasPlaceholder
        Parameters:
        placeholder - Placeholder text. Can be null, meaning no placeholder.
      • getPlaceholder

        public String getPlaceholder()
        Description copied from interface: HasPlaceholder
        Returns current placeholder text for this object.
        Specified by:
        getPlaceholder in interface HasPlaceholder
        Returns:
        Current placeholder text. Can be null, meaning no placeholder.
      • setId

        public void setId​(String id)
        Description copied from interface: HasId
        Sets this object's id.
        Specified by:
        setId in interface HasId
        Overrides:
        setId in class com.vaadin.flow.component.Component
        Parameters:
        id - A new id. Can be null to remove existing id.
      • getRawValue

        public String getRawValue()
        Returns the raw value, as currently displayed in the underlying text field. This may depend on whether the component has focus, what locale is used, etc.
        Returns:
        Raw value currently displayed in the underlying text field.
      • addThemeVariants

        public void addThemeVariants​(com.vaadin.flow.component.textfield.TextFieldVariant... variants)
        Allows adding theme variants to the underlying text field.
        Parameters:
        variants - Theme variants to add.
        See Also:
        TextField.addThemeVariants(TextFieldVariant...)
      • removeThemeVariants

        public void removeThemeVariants​(com.vaadin.flow.component.textfield.TextFieldVariant... variants)
        Allows removing theme variants from the underlying text field.
        Parameters:
        variants - Theme variants to remove.
        See Also:
        TextField.removeThemeVariants(TextFieldVariant...)
      • setRequiredIndicatorVisible

        public void setRequiredIndicatorVisible​(boolean requiredIndicatorVisible)
        Specified by:
        setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<T extends Number,​SELF extends AbstractSuperNumberField<T,​SELF>>
        Specified by:
        setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<T extends Number,​SELF extends AbstractSuperNumberField<T,​SELF>>
      • isRequiredIndicatorVisible

        public boolean isRequiredIndicatorVisible()
        Specified by:
        isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<T extends Number,​SELF extends AbstractSuperNumberField<T,​SELF>>
        Specified by:
        isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<T extends Number,​SELF extends AbstractSuperNumberField<T,​SELF>>
      • setErrorMessage

        public void setErrorMessage​(String errorMessage)
        Specified by:
        setErrorMessage in interface com.vaadin.flow.component.HasValidation
        Overrides:
        setErrorMessage in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • getErrorMessage

        public String getErrorMessage()
        Specified by:
        getErrorMessage in interface com.vaadin.flow.component.HasValidation
        Overrides:
        getErrorMessage in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • setInvalid

        public void setInvalid​(boolean invalid)
        Specified by:
        setInvalid in interface com.vaadin.flow.component.HasValidation
        Overrides:
        setInvalid in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • isInvalid

        public boolean isInvalid()
        Specified by:
        isInvalid in interface com.vaadin.flow.component.HasValidation
        Overrides:
        isInvalid in class com.vaadin.flow.component.customfield.CustomField<T extends Number>
      • select

        public void select​(int from,
                           int to)
        Description copied from interface: CanSelectText
        Selects text starting from index from (inclusive) and ending at index to (exclusive).
        Specified by:
        select in interface CanSelectText
        Parameters:
        from - Starting index (inclusive).
        to - Ending index (exclusive).
      • selectAll

        public void selectAll()
        Description copied from interface: CanSelectText
        Selects entire text in the component.
        Specified by:
        selectAll in interface CanSelectText
      • selectNone

        public void selectNone()
        Description copied from interface: CanSelectText
        Removes the current selection and selects no text.
        Specified by:
        selectNone in interface CanSelectText
      • setReceivingSelectionEventsFromClient

        public void setReceivingSelectionEventsFromClient​(boolean receivingSelectionEventsFromClient)
        Description copied from interface: CanReceiveSelectionEventsFromClient
        Configures sending events by the client-side component. Note: this feature is by default turned off.
        Specified by:
        setReceivingSelectionEventsFromClient in interface CanReceiveSelectionEventsFromClient
        Parameters:
        receivingSelectionEventsFromClient - When false, selecting text in client-side component will not send an event to server-side component. When true, it will.
      • setHelperComponent

        public void setHelperComponent​(com.vaadin.flow.component.Component component)
        Specified by:
        setHelperComponent in interface com.vaadin.flow.component.HasHelper
      • setHelperText

        public void setHelperText​(String helperText)
        Specified by:
        setHelperText in interface com.vaadin.flow.component.HasHelper
      • getHelperComponent

        public com.vaadin.flow.component.Component getHelperComponent()
        Specified by:
        getHelperComponent in interface com.vaadin.flow.component.HasHelper
      • getHelperText

        public String getHelperText()
        Specified by:
        getHelperText in interface com.vaadin.flow.component.HasHelper
      • setTooltipText

        public com.vaadin.flow.component.shared.Tooltip setTooltipText​(String text)
        Specified by:
        setTooltipText in interface com.vaadin.flow.component.shared.HasTooltip
      • getTooltip

        public com.vaadin.flow.component.shared.Tooltip getTooltip()
        Specified by:
        getTooltip in interface com.vaadin.flow.component.shared.HasTooltip
      • setValueChangeMode

        public void setValueChangeMode​(com.vaadin.flow.data.value.ValueChangeMode valueChangeMode)
        Specified by:
        setValueChangeMode in interface com.vaadin.flow.data.value.HasValueChangeMode
      • getValueChangeMode

        public com.vaadin.flow.data.value.ValueChangeMode getValueChangeMode()
        Specified by:
        getValueChangeMode in interface com.vaadin.flow.data.value.HasValueChangeMode
      • setValueChangeTimeout

        public void setValueChangeTimeout​(int valueChangeTimeout)
        Specified by:
        setValueChangeTimeout in interface com.vaadin.flow.data.value.HasValueChangeMode
      • getValueChangeTimeout

        public int getValueChangeTimeout()
        Specified by:
        getValueChangeTimeout in interface com.vaadin.flow.data.value.HasValueChangeMode
      • isFocused

        protected final boolean isFocused()
        Checks if the field is currently focused (underlying field received a focus event). Blurring the field causes it to lose focus.
        Returns:
        true when the field has focus.
      • focus

        public void focus()
        Specified by:
        focus in interface com.vaadin.flow.component.Focusable<T extends Number>
      • blur

        public void blur()
        Specified by:
        blur in interface com.vaadin.flow.component.Focusable<T extends Number>
      • setClearButtonVisible

        public void setClearButtonVisible​(boolean state)
        Specified by:
        setClearButtonVisible in interface com.vaadin.flow.component.shared.HasClearButton
      • isClearButtonVisible

        public boolean isClearButtonVisible()
        Specified by:
        isClearButtonVisible in interface com.vaadin.flow.component.shared.HasClearButton
      • setRequired

        public void setRequired​(boolean required)
        Description copied from interface: HasRequired
        Sets the new required state.
        Specified by:
        setRequired in interface HasRequired
        Parameters:
        required - Whether this component should be required.
      • isRequired

        public boolean isRequired()
        Description copied from interface: HasRequired
        Checks if this object is required.
        Specified by:
        isRequired in interface HasRequired
        Returns:
        Whether this component is required.