Search in sources :

Example 1 with PopupDateField

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;
}
Also used : PopupDateField(com.vaadin.v7.ui.PopupDateField) NewItemHandler(com.vaadin.v7.ui.AbstractSelect.NewItemHandler) Property(com.vaadin.v7.data.Property) Date(java.util.Date) LocalDate(org.joda.time.LocalDate) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Property (com.vaadin.v7.data.Property)1 NewItemHandler (com.vaadin.v7.ui.AbstractSelect.NewItemHandler)1 PopupDateField (com.vaadin.v7.ui.PopupDateField)1 Date (java.util.Date)1 LocalDate (org.joda.time.LocalDate)1