use of com.vaadin.v7.ui.PopupDateField in project SORMAS-Project by hzi-braunschweig.
the class DateTimeField method initContent.
@Override
protected Component initContent() {
HorizontalLayout layout = new HorizontalLayout();
layout.setSpacing(true);
layout.setWidth(100, Unit.PERCENTAGE);
dateField = new PopupDateField();
dateField.setId(this.getId() + "_" + "date");
dateField.setWidth(100, Unit.PERCENTAGE);
dateField.setDateFormat(DateFormatHelper.getDateFormatPattern());
dateField.setLenient(true);
dateField.setInputPrompt(inputPrompt);
layout.addComponent(dateField);
layout.setExpandRatio(dateField, 0.5f);
if (!converterSet) {
dateField.setConverter(converter);
converterSet = true;
}
timeField = ComboBoxHelper.createComboBoxV7();
timeField.setId(this.getId() + "_" + "time");
timeField.addContainerProperty(CAPTION_PROPERTY_ID, String.class, null);
timeField.setItemCaptionPropertyId(CAPTION_PROPERTY_ID);
// fill
for (int hours = 0; hours <= 23; hours++) {
for (int minutes = 0; minutes <= 59; minutes += 15) {
ensureTimeEntry(hours, minutes);
}
}
timeField.setNewItemsAllowed(true);
timeField.setNewItemHandler(new NewItemHandler() {
@Override
public void addNewItem(String newItemCaption) {
Date date = DateHelper.parseTime(newItemCaption);
timeField.setValue(ensureTimeEntry(date));
}
});
timeField.setWidth(100, Unit.PERCENTAGE);
layout.addComponent(timeField);
layout.setExpandRatio(timeField, 0.5f);
// value can't be set on readOnly fields
dateField.setReadOnly(false);
timeField.setReadOnly(false);
// set field values based on internal value
setInternalValue(super.getInternalValue());
dateField.setReadOnly(isReadOnly());
timeField.setReadOnly(isReadOnly());
Property.ValueChangeListener validationValueChangeListener = new Property.ValueChangeListener() {
@Override
public void valueChange(Property.ValueChangeEvent event) {
markAsDirty();
fireValueChange(false);
}
};
dateField.addValueChangeListener(validationValueChangeListener);
timeField.addValueChangeListener(validationValueChangeListener);
return layout;
}
Aggregations