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

com.vaadin.ui.DateTimeField 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.LocalDateTime;

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

/**
 * A date time entry component, which displays the actual date selector as a
 * popup.
 *
 * @see AbstractLocalDateTimeField
 * @see InlineDateTimeField
 * @author Vaadin Ltd.
 * @since 8.0
 */
public class DateTimeField extends AbstractLocalDateTimeField {

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

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

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

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

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

* The listener is called when the value of this {@code DateTimeField} 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 DateTimeField(String caption, ValueChangeListener valueChangeListener) { this(valueChangeListener); setCaption(caption); } /** * Constructs a new {@code DateTimeField} with the given caption, initial * text contents and a value change listener. *

* The listener is called when the value of this {@code DateTimeField} 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 DateTimeField(String caption, LocalDateTime 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 LocalDateTimeFieldState getState() { return (LocalDateTimeFieldState) super.getState(); } @Override protected LocalDateTimeFieldState getState(boolean markAsDirty) { return (LocalDateTimeFieldState) 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