com.holonplatform.vaadin7.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.vaadin7.internal.components;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.TimeZone;
import com.holonplatform.vaadin7.components.Input;
import com.holonplatform.vaadin7.components.builders.TemporalInputBuilder.TemporalWithTimeFieldBuilder;
import com.holonplatform.vaadin7.internal.converters.DateToLocalDateTimeConverter;
import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.ui.DateField;
import com.vaadin.ui.Field;
import com.vaadin.ui.InlineDateField;
/**
* 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);
// init
init();
}
/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.internal.components.AbstractTemporalField#configureDateField(com.vaadin.ui.DateField)
*/
@Override
protected void configureDateField(DateField field) {
field.setResolution(Resolution.MINUTE);
field.setConverter(new DateToLocalDateTimeConverter());
}
/**
* 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) {
getInternalField().setResolution(showSeconds ? Resolution.SECOND : Resolution.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#timeZone(java.time.ZoneId)
*/
@Override
public TemporalWithTimeFieldBuilder timeZone(ZoneId zoneId) {
getInstance().setTimeZone((zoneId == null) ? null : TimeZone.getTimeZone(zoneId));
return builder();
}
/*
* (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 - 2024 Weber Informatics LLC | Privacy Policy