com.holonplatform.vaadin.internal.components.LocalDateTimeField Maven / Gradle / Ivy
/*
* Copyright 2016-2017 Axioma srl.
*
* 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.holonplatform.vaadin.internal.components;
import java.time.LocalDateTime;
import com.holonplatform.vaadin.components.Field;
import com.holonplatform.vaadin.components.Input;
import com.holonplatform.vaadin.components.builders.TemporalInputBuilder.TemporalWithTimeFieldBuilder;
import com.vaadin.shared.ui.datefield.DateTimeResolution;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.AbstractLocalDateTimeField;
import com.vaadin.ui.DateField;
import com.vaadin.ui.DateTimeField;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.InlineDateTimeField;
/**
* Temporal Field implementation handling {@link LocalDateTime} value types.
*
*
* This field is rendered using a {@link DateField} or an {@link InlineDateField} with MINUTE or SECOND resolution.
*
*
* @since 5.0.0
*/
public class LocalDateTimeField extends AbstractTemporalField {
private static final long serialVersionUID = -6110526230713711558L;
/**
* Constructor
* @param inline true
to render the field using and inline calendar input
*/
public LocalDateTimeField(boolean inline) {
this(inline, null);
}
/**
* Constructor
* @param inline true
to render the field using and inline calendar input
* @param caption Field caption
*/
public LocalDateTimeField(boolean inline, String caption) {
super(LocalDateTime.class, inline);
setCaption(caption);
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.internal.components.AbstractCustomField#buildInternalField(java.lang.Class)
*/
@Override
protected AbstractDateField buildInternalField(Class extends LocalDateTime> type) {
return isInline() ? new InlineDateTimeField() : new DateTimeField();
}
/**
* Set whether to show time seconds
* @param showSeconds showSeconds true
to handle time seconds, false otherwise (handle only hours and
* minutes)
*/
public void setShowSeconds(boolean showSeconds) {
((AbstractLocalDateTimeField) getInternalField())
.setResolution(showSeconds ? DateTimeResolution.SECOND : DateTimeResolution.MINUTE);
}
// Builder
public static class Builder extends
AbstractTemporalFieldBuilder>
implements TemporalWithTimeFieldBuilder {
/**
* Constructor
* @param inline True to render the field as an inline calendar
*/
public Builder(boolean inline) {
super(new LocalDateTimeField(inline));
}
/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.components.builders.TemporalFieldBuilder.TemporalWithTimeFieldBuilder#showSeconds()
*/
@Override
public TemporalWithTimeFieldBuilder showSeconds() {
getInstance().setShowSeconds(true);
return builder();
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.internal.components.builders.AbstractComponentBuilder#builder()
*/
@Override
protected TemporalWithTimeFieldBuilder builder() {
return this;
}
/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.internal.components.builders.AbstractFieldBuilder#build(com.vaadin.ui.AbstractField)
*/
@Override
protected Input build(LocalDateTimeField instance) {
return instance;
}
/*
* (non-Javadoc)
* @see com.holonplatform.vaadin.internal.components.builders.AbstractFieldBuilder#buildAsField(com.vaadin.ui.
* AbstractField)
*/
@Override
protected Field buildAsField(LocalDateTimeField instance) {
return instance;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy