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

com.vaadin.ui.DateField Maven / Gradle / Ivy

There is a newer version: 8.27.3
Show newest version
/*
 * Copyright (C) 2000-2024 Vaadin Ltd
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  for the full
 * license.
 */
package com.vaadin.ui;

import java.time.LocalDate;

import com.vaadin.shared.ui.datefield.LocalDateFieldState;

/**
 * A date entry component, which displays the actual date selector as a popup.
 *
 * @see AbstractLocalDateField
 * @see InlineDateField
 * @author Vaadin Ltd.
 * @since 8.0
 */
public class DateField extends AbstractLocalDateField {

    /**
     * Constructs an empty DateField with no caption.
     */
    public DateField() {
        super();
    }

    /**
     * Constructs a new DateField with the given caption and
     * initial text contents.
     *
     * @param caption
     *            the caption String for the editor.
     * @param value
     *            the LocalDate value.
     */
    public DateField(String caption, LocalDate value) {
        super(caption, value);
    }

    /**
     * Constructs a new DateField with initial date value.
     *
     * @param value
     *            the LocalDate value.
     */
    public DateField(LocalDate value) {
        super();
        setValue(value);
    }

    /**
     * Constructs an empty DateField with caption.
     *
     * @param caption
     *            the caption of the datefield.
     */
    public DateField(String caption) {
        super(caption);
    }

    /**
     * Constructs a new {@code DateField} with a value change listener.
     * 

* The listener is called when the value of this {@code DateField} is * changed either by the user or programmatically. * * @param valueChangeListener * the value change listener, not {@code null} */ public DateField(ValueChangeListener valueChangeListener) { super(); addValueChangeListener(valueChangeListener); } /** * Constructs a new {@code DateField} with the given caption and a value * change listener. *

* The listener is called when the value of this {@code DateField} is * changed either by the user or programmatically. * * @param caption * the caption for the field * @param valueChangeListener * the value change listener, not {@code null} */ public DateField(String caption, ValueChangeListener valueChangeListener) { this(valueChangeListener); setCaption(caption); } /** * Constructs a new {@code DateField} with the given caption, initial text * contents and a value change listener. *

* The listener is called when the value of this {@code DateField} is * changed either by the user or programmatically. * * @param caption * the caption for the field * @param value * the value for the field, not {@code null} * @param valueChangeListener * the value change listener, not {@code null} */ public DateField(String caption, LocalDate value, ValueChangeListener valueChangeListener) { this(caption, value); addValueChangeListener(valueChangeListener); } /** * Returns the current placeholder text. * * @see #setPlaceholder(String) * @return the placeholder text */ public String getPlaceholder() { return getState(false).placeholder; } /** * Sets the placeholder text. The placeholder is text that is displayed when * the field would otherwise be empty, to prompt the user for input. * * @param placeholder * the placeholder text to set */ public void setPlaceholder(String placeholder) { getState().placeholder = placeholder; } @Override protected LocalDateFieldState getState() { return (LocalDateFieldState) super.getState(); } @Override protected LocalDateFieldState getState(boolean markAsDirty) { return (LocalDateFieldState) super.getState(markAsDirty); } /** * Checks whether the text field is enabled (default) or not. * * @see #setTextFieldEnabled(boolean) * * @return true if the text field is enabled, false otherwise. */ public boolean isTextFieldEnabled() { return getState(false).textFieldEnabled; } /** * Enables or disables the text field. By default the text field is enabled. * Disabling it causes only the button for date selection to be active, thus * preventing the user from entering invalid dates. * * See issue 6790. * * @param state * true to enable text field, false to disable it. */ public void setTextFieldEnabled(boolean state) { getState().textFieldEnabled = state; } /** * Set a description that explains the usage of the Widget for users of * assistive devices. * * @param description * String with the description */ public void setAssistiveText(String description) { getState().descriptionForAssistiveDevices = description; } /** * Get the description that explains the usage of the Widget for users of * assistive devices. * * @return String with the description */ public String getAssistiveText() { return getState(false).descriptionForAssistiveDevices; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy