Search in sources :

Example 1 with DateHelper8

use of de.symeda.sormas.ui.utils.DateHelper8 in project SORMAS-Project by hzi-braunschweig.

the class LineListingConfigurationsGrid method buildGrid.

private void buildGrid() {
    setSelectionMode(SelectionMode.NONE);
    if (nationLevel) {
        addColumn(FeatureConfigurationIndexDto::getRegionName).setCaption(I18nProperties.getPrefixCaption(FeatureConfigurationIndexDto.I18N_PREFIX, FeatureConfigurationIndexDto.REGION_NAME));
    }
    addColumn(FeatureConfigurationIndexDto::getDistrictName).setCaption(I18nProperties.getPrefixCaption(FeatureConfigurationIndexDto.I18N_PREFIX, FeatureConfigurationIndexDto.DISTRICT_NAME));
    addComponentColumn(config -> {
        CheckBox cbActive = new CheckBox();
        cbActive.setValue(config.isEnabled());
        cbActive.addValueChangeListener(e -> {
            config.setEnabled(e.getValue());
            if (Boolean.TRUE.equals(e.getValue())) {
                config.setEndDate(DateHelper.addDays(new Date(), 21));
                dateFieldMap.get(config).setValue(DateHelper8.toLocalDate(DateHelper.addDays(new Date(), 21)));
            } else {
                config.setEndDate(null);
                dateFieldMap.get(config).setValue(null);
            }
            changedConfigurations.add(config);
        });
        return cbActive;
    }).setCaption(I18nProperties.getPrefixCaption(FeatureConfigurationIndexDto.I18N_PREFIX, FeatureConfigurationIndexDto.ENABLED));
    addComponentColumn(config -> {
        DateField dfEndDate = new DateField();
        dfEndDate.setValue(DateHelper8.toLocalDate(config.getEndDate()));
        dfEndDate.addValueChangeListener(e -> {
            if (e.getValue() != null && e.getValue().isBefore(LocalDate.now())) {
                Notification errorNotification = new Notification(I18nProperties.getString(Strings.headingInvalidDateEntered), I18nProperties.getValidationError(Validations.noPastDateAllowed), Type.TRAY_NOTIFICATION);
                errorNotification.setStyleName("tray notification-error");
                errorNotification.show(Page.getCurrent());
            } else {
                config.setEndDate(DateHelper8.toDate(e.getValue()));
                changedConfigurations.add(config);
            }
        });
        dfEndDate.setRangeStart(LocalDate.now());
        dateFieldMap.put(config, dfEndDate);
        return dfEndDate;
    }).setCaption(I18nProperties.getPrefixCaption(FeatureConfigurationIndexDto.I18N_PREFIX, FeatureConfigurationIndexDto.END_DATE));
}
Also used : DateField(com.vaadin.ui.DateField) Validations(de.symeda.sormas.api.i18n.Validations) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) DateHelper(de.symeda.sormas.api.utils.DateHelper) Set(java.util.Set) HashMap(java.util.HashMap) HashSet(java.util.HashSet) List(java.util.List) Type(com.vaadin.ui.Notification.Type) CheckBox(com.vaadin.ui.CheckBox) FeatureConfigurationIndexDto(de.symeda.sormas.api.feature.FeatureConfigurationIndexDto) Notification(com.vaadin.ui.Notification) LocalDate(java.time.LocalDate) Map(java.util.Map) Page(com.vaadin.server.Page) DateHelper8(de.symeda.sormas.ui.utils.DateHelper8) Strings(de.symeda.sormas.api.i18n.Strings) Grid(com.vaadin.ui.Grid) CheckBox(com.vaadin.ui.CheckBox) DateField(com.vaadin.ui.DateField) Date(java.util.Date) LocalDate(java.time.LocalDate) Notification(com.vaadin.ui.Notification)

Aggregations

Page (com.vaadin.server.Page)1 CheckBox (com.vaadin.ui.CheckBox)1 DateField (com.vaadin.ui.DateField)1 Grid (com.vaadin.ui.Grid)1 Notification (com.vaadin.ui.Notification)1 Type (com.vaadin.ui.Notification.Type)1 FeatureConfigurationIndexDto (de.symeda.sormas.api.feature.FeatureConfigurationIndexDto)1 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)1 Strings (de.symeda.sormas.api.i18n.Strings)1 Validations (de.symeda.sormas.api.i18n.Validations)1 DateHelper (de.symeda.sormas.api.utils.DateHelper)1 DateHelper8 (de.symeda.sormas.ui.utils.DateHelper8)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1