Example usage for com.vaadin.ui Notification setDelayMsec

List of usage examples for com.vaadin.ui Notification setDelayMsec

Introduction

In this page you can find the example usage for com.vaadin.ui Notification setDelayMsec.

Prototype

public void setDelayMsec(int delayMsec) 

Source Link

Document

Sets the delay before the notification disappears.

Usage

From source file:de.metas.procurement.webui.ui.view.LoginView.java

License:Open Source License

protected void onForgotPassword(final String email) {
    if (Strings.isNullOrEmpty(email)) {
        throw new PasswordResetFailedException(email, i18n.get("LoginView.passwordReset.error.fillEmail"));
    }/*from www  .  j  a va 2s.c  o  m*/

    final String passwordResetKey = loginService.generatePasswordResetKey(email);
    final URI passwordResetURI = PasswordResetView.buildPasswordResetURI(passwordResetKey);
    loginService.sendPasswordResetKey(email, passwordResetURI);

    final Notification notification = new Notification(i18n.get("LoginView.passwordReset.notification.title") // "Password reset"
            , i18n.get("LoginView.passwordReset.notification.message") // "Your password has been reset. Please check your email and click on that link"
            , Type.HUMANIZED_MESSAGE);
    notification.setDelayMsec(15 * 1000);
    notification.show(Page.getCurrent());
}

From source file:de.symeda.sormas.ui.caze.CaseController.java

License:Open Source License

private void saveCase(CaseDataDto cazeDto) {
    // Compare old and new case
    CaseDataDto existingDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(cazeDto.getUuid());
    onCaseChanged(existingDto, cazeDto);

    CaseDataDto resultDto = FacadeProvider.getCaseFacade().saveCase(cazeDto);

    if (resultDto.getPlagueType() != cazeDto.getPlagueType()) {
        // TODO would be much better to have a notification for this triggered in the backend
        Window window = VaadinUiUtil.showSimplePopupWindow(
                I18nProperties.getString(Strings.headingSaveNotification),
                String.format(I18nProperties.getString(Strings.messagePlagueTypeChange),
                        resultDto.getPlagueType().toString(), resultDto.getPlagueType().toString()));
        window.addCloseListener(new CloseListener() {
            private static final long serialVersionUID = 1L;

            @Override//from  ww w  . j  a  v a 2 s . c  o m
            public void windowClose(CloseEvent e) {
                if (existingDto.getCaseClassification() != resultDto.getCaseClassification()
                        && resultDto.getClassificationUser() == null) {
                    Notification notification = new Notification(String.format(
                            I18nProperties.getString(Strings.messageCaseSavedClassificationChanged),
                            resultDto.getCaseClassification().toString()), Type.WARNING_MESSAGE);
                    notification.setDelayMsec(-1);
                    notification.show(Page.getCurrent());
                } else {
                    Notification.show(I18nProperties.getString(Strings.messageCaseSaved), Type.WARNING_MESSAGE);
                }
                SormasUI.refreshView();
            }
        });
    } else {
        // Notify user about an automatic case classification change
        if (existingDto != null && existingDto.getCaseClassification() != resultDto.getCaseClassification()
                && resultDto.getClassificationUser() == null) {
            Notification notification = new Notification(
                    String.format(I18nProperties.getString(Strings.messageCaseSavedClassificationChanged),
                            resultDto.getCaseClassification().toString()),
                    Type.WARNING_MESSAGE);
            notification.setDelayMsec(-1);
            notification.show(Page.getCurrent());
        } else {
            Notification.show(I18nProperties.getString(Strings.messageCaseSaved), Type.WARNING_MESSAGE);
        }
        SormasUI.refreshView();
    }
}

From source file:de.symeda.sormas.ui.caze.CasesView.java

License:Open Source License

public VerticalLayout createFilterBar() {
    VerticalLayout filterLayout = new VerticalLayout();
    filterLayout.setSpacing(false);/*from  ww w  . jav a  2s .c om*/
    filterLayout.setMargin(false);
    filterLayout.setWidth(100, Unit.PERCENTAGE);

    firstFilterRowLayout = new HorizontalLayout();
    firstFilterRowLayout.setMargin(false);
    firstFilterRowLayout.setSpacing(true);
    firstFilterRowLayout.setSizeUndefined();
    {
        if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
            caseOriginFilter = new ComboBox();
            caseOriginFilter.setId(CaseDataDto.CASE_ORIGIN);
            caseOriginFilter.setWidth(140, Unit.PIXELS);
            caseOriginFilter.setInputPrompt(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.CASE_ORIGIN));
            caseOriginFilter.addItems((Object[]) CaseOrigin.values());
            caseOriginFilter.addValueChangeListener(e -> {
                criteria.caseOrigin(((CaseOrigin) e.getProperty().getValue()));
                if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) {
                    pointOfEntryFilter.setEnabled(e.getProperty().getValue() != CaseOrigin.IN_COUNTRY);
                    portHealthCasesWithoutFacilityFilter
                            .setEnabled(e.getProperty().getValue() != CaseOrigin.IN_COUNTRY);
                }
                navigateTo(criteria);
            });
            firstFilterRowLayout.addComponent(caseOriginFilter);
        }

        outcomeFilter = new ComboBox();
        outcomeFilter.setId(CaseDataDto.OUTCOME);
        outcomeFilter.setWidth(140, Unit.PIXELS);
        outcomeFilter
                .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.OUTCOME));
        outcomeFilter.addItems((Object[]) CaseOutcome.values());
        outcomeFilter.addValueChangeListener(e -> {
            criteria.outcome(((CaseOutcome) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        firstFilterRowLayout.addComponent(outcomeFilter);

        diseaseFilter = new ComboBox();
        diseaseFilter.setId(CaseDataDto.DISEASE);
        diseaseFilter.setWidth(140, Unit.PIXELS);
        diseaseFilter
                .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISEASE));
        diseaseFilter.addItems(
                FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases().toArray());
        diseaseFilter.addValueChangeListener(e -> {
            criteria.disease(((Disease) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        firstFilterRowLayout.addComponent(diseaseFilter);

        classificationFilter = new ComboBox();
        classificationFilter.setId(CaseDataDto.CASE_CLASSIFICATION);
        classificationFilter.setWidth(140, Unit.PIXELS);
        classificationFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.CASE_CLASSIFICATION));
        classificationFilter.addItems((Object[]) CaseClassification.values());
        classificationFilter.addValueChangeListener(e -> {
            criteria.caseClassification(((CaseClassification) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        firstFilterRowLayout.addComponent(classificationFilter);

        searchField = new TextField();
        searchField.setId("search");
        searchField.setWidth(200, Unit.PIXELS);
        searchField.setNullRepresentation("");
        searchField.setInputPrompt(I18nProperties.getString(Strings.promptCasesSearchField));
        searchField.addTextChangeListener(e -> {
            criteria.nameUuidEpidNumberLike(e.getText());
            grid.reload();
        });
        firstFilterRowLayout.addComponent(searchField);

        addShowMoreOrLessFiltersButtons(firstFilterRowLayout);

        resetButton = new Button(I18nProperties.getCaption(Captions.actionResetFilters));
        resetButton.setId("reset");
        resetButton.setVisible(false);
        resetButton.addClickListener(event -> {
            ViewModelProviders.of(CasesView.class).remove(CaseCriteria.class);
            navigateTo(null);
        });
        firstFilterRowLayout.addComponent(resetButton);
    }
    filterLayout.addComponent(firstFilterRowLayout);

    secondFilterRowLayout = new HorizontalLayout();
    secondFilterRowLayout.setMargin(false);
    secondFilterRowLayout.setSpacing(true);
    secondFilterRowLayout.setSizeUndefined();
    {
        presentConditionFilter = new ComboBox();
        presentConditionFilter.setWidth(140, Unit.PIXELS);
        presentConditionFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.PRESENT_CONDITION));
        presentConditionFilter.addItems((Object[]) PresentCondition.values());
        presentConditionFilter.addValueChangeListener(e -> {
            criteria.presentCondition(((PresentCondition) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        secondFilterRowLayout.addComponent(presentConditionFilter);

        UserDto user = UserProvider.getCurrent().getUser();

        regionFilter = new ComboBox();
        if (user.getRegion() == null) {
            regionFilter.setWidth(140, Unit.PIXELS);
            regionFilter.setInputPrompt(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REGION));
            regionFilter.addItems(FacadeProvider.getRegionFacade().getAllAsReference());
            regionFilter.addValueChangeListener(e -> {
                RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
                criteria.region(region);
                navigateTo(criteria);
            });
            secondFilterRowLayout.addComponent(regionFilter);
        }

        districtFilter = new ComboBox();
        districtFilter.setWidth(140, Unit.PIXELS);
        districtFilter
                .setInputPrompt(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISTRICT));
        districtFilter.setDescription(I18nProperties.getDescription(Descriptions.descDistrictFilter));
        districtFilter.addValueChangeListener(e -> {
            DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue();
            criteria.district(district);
            navigateTo(criteria);
        });

        if (user.getRegion() != null && user.getDistrict() == null) {
            districtFilter
                    .addItems(FacadeProvider.getDistrictFacade().getAllByRegion(user.getRegion().getUuid()));
            districtFilter.setEnabled(true);
        } else {
            regionFilter.addValueChangeListener(e -> {
                RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
                districtFilter.removeAllItems();
                if (region != null) {
                    districtFilter
                            .addItems(FacadeProvider.getDistrictFacade().getAllByRegion(region.getUuid()));
                    districtFilter.setEnabled(true);
                } else {
                    districtFilter.setEnabled(false);
                }
            });
            districtFilter.setEnabled(false);
        }
        secondFilterRowLayout.addComponent(districtFilter);

        if (!UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
            facilityFilter = new ComboBox();
            facilityFilter.setWidth(140, Unit.PIXELS);
            facilityFilter.setInputPrompt(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_FACILITY));
            facilityFilter.setDescription(I18nProperties.getDescription(Descriptions.descFacilityFilter));
            facilityFilter.addValueChangeListener(e -> {
                criteria.healthFacility(((FacilityReferenceDto) e.getProperty().getValue()));
                navigateTo(criteria);
            });
            facilityFilter.setEnabled(false);
            secondFilterRowLayout.addComponent(facilityFilter);
        }

        if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) {
            pointOfEntryFilter = new ComboBox();
            pointOfEntryFilter.setWidth(140, Unit.PIXELS);
            pointOfEntryFilter.setInputPrompt(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.POINT_OF_ENTRY));
            pointOfEntryFilter
                    .setDescription(I18nProperties.getDescription(Descriptions.descPointOfEntryFilter));
            pointOfEntryFilter.addValueChangeListener(e -> {
                criteria.pointOfEntry(((PointOfEntryReferenceDto) e.getProperty().getValue()));
                navigateTo(criteria);
            });
            secondFilterRowLayout.addComponent(pointOfEntryFilter);
        }

        districtFilter.addValueChangeListener(e -> {
            if (facilityFilter != null) {
                facilityFilter.removeAllItems();
                DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue();
                if (district != null) {
                    facilityFilter.addItems(
                            FacadeProvider.getFacilityFacade().getHealthFacilitiesByDistrict(district, true));
                    facilityFilter.setEnabled(true);
                } else {
                    facilityFilter.setEnabled(false);
                }
            }
            if (pointOfEntryFilter != null) {
                pointOfEntryFilter.removeAllItems();
                DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue();
                if (district != null) {
                    pointOfEntryFilter.addItems(
                            FacadeProvider.getPointOfEntryFacade().getAllByDistrict(district.getUuid(), true));
                    pointOfEntryFilter.setEnabled(
                            caseOriginFilter == null || caseOriginFilter.getValue() != CaseOrigin.IN_COUNTRY);
                } else {
                    pointOfEntryFilter.setEnabled(false);
                }
            }
        });

        officerFilter = new ComboBox();
        officerFilter.setWidth(140, Unit.PIXELS);
        officerFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.SURVEILLANCE_OFFICER));
        if (user.getRegion() != null) {
            officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(user.getRegion(),
                    UserRole.SURVEILLANCE_OFFICER));
        }
        officerFilter.addValueChangeListener(e -> {
            criteria.surveillanceOfficer(((UserReferenceDto) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        secondFilterRowLayout.addComponent(officerFilter);

        reportedByFilter = new ComboBox();
        reportedByFilter.setWidth(140, Unit.PIXELS);
        reportedByFilter.setInputPrompt(I18nProperties.getString(Strings.reportedBy));
        reportedByFilter.addItems((Object[]) UserRole.values());
        reportedByFilter.addValueChangeListener(e -> {
            criteria.reportingUserRole((UserRole) e.getProperty().getValue());
            navigateTo(criteria);
        });
        secondFilterRowLayout.addComponent(reportedByFilter);

        reportingUserFilter = new TextField();
        reportingUserFilter.setWidth(200, Unit.PIXELS);
        reportingUserFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REPORTING_USER));
        reportingUserFilter.setNullRepresentation("");
        reportingUserFilter.addTextChangeListener(e -> {
            criteria.reportingUserLike(e.getText());
            grid.reload();
        });
        secondFilterRowLayout.addComponent(reportingUserFilter);
    }
    filterLayout.addComponent(secondFilterRowLayout);
    secondFilterRowLayout.setVisible(false);

    thirdFilterRowLayout = new HorizontalLayout();
    thirdFilterRowLayout.setMargin(false);
    thirdFilterRowLayout.setSpacing(true);
    thirdFilterRowLayout.setSizeUndefined();
    CssStyles.style(thirdFilterRowLayout, CssStyles.VSPACE_3);
    {
        casesWithoutGeoCoordsFilter = new CheckBox();
        CssStyles.style(casesWithoutGeoCoordsFilter, CssStyles.CHECKBOX_FILTER_INLINE);
        casesWithoutGeoCoordsFilter.setCaption(I18nProperties.getCaption(Captions.caseFilterWithoutGeo));
        casesWithoutGeoCoordsFilter
                .setDescription(I18nProperties.getDescription(Descriptions.descCaseFilterWithoutGeo));
        casesWithoutGeoCoordsFilter.addValueChangeListener(e -> {
            criteria.mustHaveNoGeoCoordinates((Boolean) e.getProperty().getValue());
            navigateTo(criteria);
        });
        thirdFilterRowLayout.addComponent(casesWithoutGeoCoordsFilter);

        if (UserProvider.getCurrent().hasUserRight(UserRight.PORT_HEALTH_INFO_VIEW)) {
            portHealthCasesWithoutFacilityFilter = new CheckBox();
            CssStyles.style(portHealthCasesWithoutFacilityFilter, CssStyles.CHECKBOX_FILTER_INLINE);
            portHealthCasesWithoutFacilityFilter
                    .setCaption(I18nProperties.getCaption(Captions.caseFilterPortHealthWithoutFacility));
            portHealthCasesWithoutFacilityFilter.setDescription(
                    I18nProperties.getDescription(Descriptions.descCaseFilterPortHealthWithoutFacility));
            portHealthCasesWithoutFacilityFilter.addValueChangeListener(e -> {
                criteria.mustBePortHealthCaseWithoutFacility((Boolean) e.getProperty().getValue());
                navigateTo(criteria);
            });
            thirdFilterRowLayout.addComponent(portHealthCasesWithoutFacilityFilter);
        }
    }
    filterLayout.addComponent(thirdFilterRowLayout);
    thirdFilterRowLayout.setVisible(false);

    dateFilterRowLayout = new HorizontalLayout();
    dateFilterRowLayout.setSpacing(true);
    dateFilterRowLayout.setSizeUndefined();
    {
        Button applyButton = new Button(I18nProperties.getCaption(Captions.actionApplyDateFilter));

        weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(applyButton, false, false,
                I18nProperties.getString(Strings.infoCaseDate), NewCaseDateType.class,
                I18nProperties.getString(Strings.promptNewCaseDateType), NewCaseDateType.MOST_RELEVANT);
        weekAndDateFilter.getWeekFromFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptCasesEpiWeekFrom));
        weekAndDateFilter.getWeekToFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptCasesEpiWeekTo));
        weekAndDateFilter.getDateFromFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptCasesDateFrom));
        weekAndDateFilter.getDateToFilter().setInputPrompt(I18nProperties.getString(Strings.promptDateTo));
        dateFilterRowLayout.addComponent(weekAndDateFilter);
        dateFilterRowLayout.addComponent(applyButton);

        applyButton.addClickListener(e -> {
            DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter()
                    .getValue();
            Date fromDate, toDate;
            if (dateFilterOption == DateFilterOption.DATE) {
                fromDate = DateHelper.getStartOfDay(weekAndDateFilter.getDateFromFilter().getValue());
                toDate = DateHelper.getEndOfDay(weekAndDateFilter.getDateToFilter().getValue());
            } else {
                fromDate = DateHelper
                        .getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
                toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
            }
            if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
                applyButton.removeStyleName(ValoTheme.BUTTON_PRIMARY);
                NewCaseDateType newCaseDateType = (NewCaseDateType) weekAndDateFilter.getDateTypeSelector()
                        .getValue();
                criteria.newCaseDateBetween(fromDate, toDate,
                        newCaseDateType != null ? newCaseDateType : NewCaseDateType.MOST_RELEVANT);
                navigateTo(criteria);
            } else {
                if (dateFilterOption == DateFilterOption.DATE) {
                    Notification notification = new Notification(
                            I18nProperties.getString(Strings.headingMissingDateFilter),
                            I18nProperties.getString(Strings.messageMissingDateFilter), Type.WARNING_MESSAGE,
                            false);
                    notification.setDelayMsec(-1);
                    notification.show(Page.getCurrent());
                } else {
                    Notification notification = new Notification(
                            I18nProperties.getString(Strings.headingMissingEpiWeekFilter),
                            I18nProperties.getString(Strings.messageMissingEpiWeekFilter), Type.WARNING_MESSAGE,
                            false);
                    notification.setDelayMsec(-1);
                    notification.show(Page.getCurrent());
                }
            }
        });
    }
    filterLayout.addComponent(dateFilterRowLayout);
    dateFilterRowLayout.setVisible(false);

    return filterLayout;
}

From source file:de.symeda.sormas.ui.contact.ContactsView.java

License:Open Source License

public VerticalLayout createFilterBar() {
    VerticalLayout filterLayout = new VerticalLayout();
    filterLayout.setSpacing(false);//  w  w w .  ja v a 2s  .co  m
    filterLayout.setMargin(false);
    filterLayout.setWidth(100, Unit.PERCENTAGE);

    firstFilterRowLayout = new HorizontalLayout();
    firstFilterRowLayout.setMargin(false);
    firstFilterRowLayout.setSpacing(true);
    firstFilterRowLayout.setSizeUndefined();
    {
        classificationFilter = new ComboBox();
        classificationFilter.setWidth(140, Unit.PIXELS);
        classificationFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX,
                ContactIndexDto.CONTACT_CLASSIFICATION));
        classificationFilter.addItems((Object[]) ContactClassification.values());
        classificationFilter.addValueChangeListener(e -> {
            criteria.contactClassification((ContactClassification) e.getProperty().getValue());
            navigateTo(criteria);
        });
        firstFilterRowLayout.addComponent(classificationFilter);

        diseaseFilter = new ComboBox();
        diseaseFilter.setWidth(140, Unit.PIXELS);
        diseaseFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.CASE_DISEASE));
        diseaseFilter.addItems(
                FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases().toArray());
        diseaseFilter.addValueChangeListener(e -> {
            criteria.caseDisease(((Disease) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        firstFilterRowLayout.addComponent(diseaseFilter);

        followUpStatusFilter = new ComboBox();
        followUpStatusFilter.setWidth(140, Unit.PIXELS);
        followUpStatusFilter.setInputPrompt(
                I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX, ContactIndexDto.FOLLOW_UP_STATUS));
        followUpStatusFilter.addItems((Object[]) FollowUpStatus.values());
        followUpStatusFilter.addValueChangeListener(e -> {
            criteria.followUpStatus(((FollowUpStatus) e.getProperty().getValue()));
            navigateTo(criteria);
        });
        firstFilterRowLayout.addComponent(followUpStatusFilter);

        searchField = new TextField();
        searchField.setWidth(200, Unit.PIXELS);
        searchField.setNullRepresentation("");
        searchField.setInputPrompt(I18nProperties.getString(Strings.promptContactsSearchField));
        searchField.addTextChangeListener(e -> {
            criteria.nameUuidCaseLike(e.getText());
            grid.reload();
        });
        firstFilterRowLayout.addComponent(searchField);

        addShowMoreOrLessFiltersButtons(firstFilterRowLayout);

        resetButton = new Button(I18nProperties.getCaption(Captions.actionResetFilters));
        resetButton.setVisible(false);
        resetButton.addClickListener(event -> {
            ViewModelProviders.of(ContactsView.class).remove(ContactCriteria.class);
            navigateTo(null);
        });
        firstFilterRowLayout.addComponent(resetButton);
    }
    filterLayout.addComponent(firstFilterRowLayout);

    secondFilterRowLayout = new HorizontalLayout();
    secondFilterRowLayout.setMargin(false);
    secondFilterRowLayout.setSpacing(true);
    secondFilterRowLayout.setSizeUndefined();
    {
        UserDto user = UserProvider.getCurrent().getUser();
        regionFilter = new ComboBox();
        if (user.getRegion() == null) {
            regionFilter.setWidth(140, Unit.PIXELS);
            regionFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX,
                    ContactIndexDto.CASE_REGION_UUID));
            regionFilter.addItems(FacadeProvider.getRegionFacade().getAllAsReference());
            regionFilter.addValueChangeListener(e -> {
                RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
                criteria.caseRegion(region);
                navigateTo(criteria);
            });
            secondFilterRowLayout.addComponent(regionFilter);
        }

        districtFilter = new ComboBox();
        districtFilter.setWidth(140, Unit.PIXELS);
        districtFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX,
                ContactIndexDto.CASE_DISTRICT_UUID));
        districtFilter.setDescription(I18nProperties.getDescription(Descriptions.descDistrictFilter));
        districtFilter.addValueChangeListener(e -> {
            DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue();
            criteria.caseDistrict(district);
            navigateTo(criteria);
        });

        if (user.getRegion() != null && user.getDistrict() == null) {
            districtFilter
                    .addItems(FacadeProvider.getDistrictFacade().getAllByRegion(user.getRegion().getUuid()));
            districtFilter.setEnabled(true);
        } else {
            regionFilter.addValueChangeListener(e -> {
                RegionReferenceDto region = (RegionReferenceDto) e.getProperty().getValue();
                districtFilter.removeAllItems();
                if (region != null) {
                    districtFilter
                            .addItems(FacadeProvider.getDistrictFacade().getAllByRegion(region.getUuid()));
                    districtFilter.setEnabled(true);
                } else {
                    districtFilter.setEnabled(false);
                }
            });
            districtFilter.setEnabled(false);
        }
        secondFilterRowLayout.addComponent(districtFilter);

        facilityFilter = new ComboBox();
        facilityFilter.setWidth(140, Unit.PIXELS);
        facilityFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX,
                ContactIndexDto.CASE_HEALTH_FACILITY_UUID));
        facilityFilter.setDescription(I18nProperties.getDescription(Descriptions.descFacilityFilter));
        facilityFilter.addValueChangeListener(e -> {
            FacilityReferenceDto facility = (FacilityReferenceDto) e.getProperty().getValue();
            criteria.caseFacility(facility);
            navigateTo(criteria);
        });
        facilityFilter.setEnabled(false);
        secondFilterRowLayout.addComponent(facilityFilter);

        districtFilter.addValueChangeListener(e -> {
            facilityFilter.removeAllItems();
            DistrictReferenceDto district = (DistrictReferenceDto) e.getProperty().getValue();
            if (district != null) {
                facilityFilter.addItems(
                        FacadeProvider.getFacilityFacade().getHealthFacilitiesByDistrict(district, true));
                facilityFilter.setEnabled(true);
            } else {
                facilityFilter.setEnabled(false);
            }
        });

        officerFilter = new ComboBox();
        officerFilter.setWidth(140, Unit.PIXELS);
        officerFilter.setInputPrompt(I18nProperties.getPrefixCaption(ContactIndexDto.I18N_PREFIX,
                ContactIndexDto.CONTACT_OFFICER_UUID));
        if (user.getRegion() != null) {
            officerFilter.addItems(FacadeProvider.getUserFacade().getUsersByRegionAndRoles(user.getRegion(),
                    UserRole.CONTACT_OFFICER));
        }
        officerFilter.addValueChangeListener(e -> {
            UserReferenceDto officer = (UserReferenceDto) e.getProperty().getValue();
            criteria.contactOfficer(officer);
            navigateTo(criteria);
        });
        secondFilterRowLayout.addComponent(officerFilter);

        reportedByFilter = new ComboBox();
        reportedByFilter.setWidth(140, Unit.PIXELS);
        reportedByFilter.setInputPrompt(I18nProperties.getString(Strings.reportedBy));
        reportedByFilter.addItems((Object[]) UserRole.values());
        reportedByFilter.addValueChangeListener(e -> {
            criteria.reportingUserRole((UserRole) e.getProperty().getValue());
            navigateTo(criteria);
        });
        secondFilterRowLayout.addComponent(reportedByFilter);
    }
    filterLayout.addComponent(secondFilterRowLayout);
    secondFilterRowLayout.setVisible(false);

    dateFilterRowLayout = new HorizontalLayout();
    dateFilterRowLayout.setSpacing(true);
    dateFilterRowLayout.setSizeUndefined();
    {
        Button applyButton = new Button(I18nProperties.getCaption(Captions.actionApplyDateFilter));

        weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(applyButton, false, false, null,
                ContactDateType.class, I18nProperties.getString(Strings.promptContactDateType),
                ContactDateType.REPORT_DATE);
        weekAndDateFilter.getWeekFromFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptContactEpiWeekFrom));
        weekAndDateFilter.getWeekToFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptContactEpiWeekTo));
        weekAndDateFilter.getDateFromFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptContactDateFrom));
        weekAndDateFilter.getDateToFilter()
                .setInputPrompt(I18nProperties.getString(Strings.promptContactDateTo));
        dateFilterRowLayout.addComponent(weekAndDateFilter);
        dateFilterRowLayout.addComponent(applyButton);

        applyButton.addClickListener(e -> {
            DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter()
                    .getValue();
            Date fromDate, toDate;
            if (dateFilterOption == DateFilterOption.DATE) {
                fromDate = DateHelper.getStartOfDay(weekAndDateFilter.getDateFromFilter().getValue());
                toDate = DateHelper.getEndOfDay(weekAndDateFilter.getDateToFilter().getValue());
            } else {
                fromDate = DateHelper
                        .getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue());
                toDate = DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue());
            }
            if ((fromDate != null && toDate != null) || (fromDate == null && toDate == null)) {
                applyButton.removeStyleName(ValoTheme.BUTTON_PRIMARY);
                ContactDateType contactDateType = (ContactDateType) weekAndDateFilter.getDateTypeSelector()
                        .getValue();
                if (contactDateType == ContactDateType.LAST_CONTACT_DATE) {
                    criteria.lastContactDateBetween(fromDate, toDate);
                    criteria.reportDateBetween(null, null);
                } else {
                    criteria.reportDateBetween(fromDate, toDate);
                    criteria.lastContactDateBetween(null, null);
                }
                navigateTo(criteria);
            } else {
                if (dateFilterOption == DateFilterOption.DATE) {
                    Notification notification = new Notification(
                            I18nProperties.getString(Strings.headingMissingDateFilter),
                            I18nProperties.getString(Strings.messageMissingDateFilter), Type.WARNING_MESSAGE,
                            false);
                    notification.setDelayMsec(-1);
                    notification.show(Page.getCurrent());
                } else {
                    Notification notification = new Notification(
                            I18nProperties.getString(Strings.headingMissingEpiWeekFilter),
                            I18nProperties.getString(Strings.messageMissingEpiWeekFilter), Type.WARNING_MESSAGE,
                            false);
                    notification.setDelayMsec(-1);
                    notification.show(Page.getCurrent());
                }
            }
        });
    }
    filterLayout.addComponent(dateFilterRowLayout);
    dateFilterRowLayout.setVisible(false);

    return filterLayout;
}

From source file:de.symeda.sormas.ui.person.PersonController.java

License:Open Source License

private void savePerson(PersonDto personDto) {

    PersonDto existingPerson = FacadeProvider.getPersonFacade().getPersonByUuid(personDto.getUuid());
    List<CaseDataDto> personCases = FacadeProvider.getCaseFacade().getAllCasesOfPerson(personDto.getUuid(),
            UserProvider.getCurrent().getUserReference().getUuid());

    onPersonChanged(existingPerson, personDto);

    personFacade.savePerson(personDto);//from w  ww  .j  a  v  a2s  .  c  o  m

    // Check whether the classification of any of this person's cases has changed
    CaseClassification newClassification = null;
    for (CaseDataDto personCase : personCases) {
        CaseDataDto updatedPersonCase = FacadeProvider.getCaseFacade().getCaseDataByUuid(personCase.getUuid());
        if (personCase.getCaseClassification() != updatedPersonCase.getCaseClassification()
                && updatedPersonCase.getClassificationUser() == null) {
            newClassification = updatedPersonCase.getCaseClassification();
            break;
        }
    }

    if (newClassification != null) {
        Notification notification = new Notification(
                String.format(I18nProperties.getString(Strings.messagePersonSavedClassificationChanged),
                        newClassification.toString()),
                Type.WARNING_MESSAGE);
        notification.setDelayMsec(-1);
        notification.show(Page.getCurrent());
    } else {
        Notification.show(I18nProperties.getString(Strings.messagePersonSaved), Type.WARNING_MESSAGE);
    }

    SormasUI.refreshView();
}

From source file:de.symeda.sormas.ui.samples.PathogenTestController.java

License:Open Source License

private void showSaveNotification(CaseDataDto existingCaseDto, CaseDataDto newCaseDto) {
    if (existingCaseDto.getCaseClassification() != newCaseDto.getCaseClassification()
            && newCaseDto.getClassificationUser() == null) {
        Notification notification = new Notification(
                String.format(I18nProperties.getString(Strings.messagePathogenTestSaved),
                        newCaseDto.getCaseClassification().toString()),
                Type.WARNING_MESSAGE);
        notification.setDelayMsec(-1);
        notification.show(Page.getCurrent());
    } else {/* www.j  av a2  s. c om*/
        Notification.show(I18nProperties.getString(Strings.messagePathogenTestSavedShort),
                Type.TRAY_NOTIFICATION);
    }
}

From source file:de.symeda.sormas.ui.SormasErrorHandler.java

License:Open Source License

public static void handleError(ErrorEvent event) {
    final Throwable t = event.getThrowable();
    if (t instanceof SocketException) {
        // Most likely client browser closed socket
        logger.info(//from   ww w . j  a va 2 s . com
                "SocketException in CommunicationManager." + " Most likely client (browser) closed socket.");
        return;
    }

    ErrorMessage errorMessage = getErrorMessageForException(t);

    if (t != null) {
        // log the error or warning
        if (errorMessage instanceof SystemError) {
            logger.error(t.getMessage(), t);
        } else {
            logger.warn(t.getMessage(), t);
        }
    }

    // finds the original source of the error/exception
    AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event);
    if (errorMessage != null && component != null) {
        // Shows the error in AbstractComponent
        if (errorMessage instanceof SystemError) {
            Notification.show(
                    I18nProperties.getString(Strings.errorOccurred,
                            I18nProperties.getString(Strings.errorOccurred)),
                    I18nProperties.getString(Strings.errorWasReported), Notification.Type.ERROR_MESSAGE);
        } else {

            // to prevent the original message from appearing, if necessary
            if (component instanceof AbstractField<?>) {
                ((AbstractField<?>) component).setCurrentBufferedSourceException(null);
            }

            Notification notification = new Notification(
                    I18nProperties.getString(Strings.errorProblemOccurred,
                            I18nProperties.getString(Strings.errorProblemOccurred)),
                    errorMessage.getFormattedHtmlMessage(), Notification.Type.WARNING_MESSAGE, true);
            notification.setDelayMsec(-1);
            notification.show(Page.getCurrent());
            component.setComponentError(errorMessage);
        }
    }
}

From source file:de.symeda.sormas.ui.statistics.StatisticsView.java

License:Open Source License

private void addGenerateButton(VerticalLayout statisticsLayout) {
    Button generateButton = new Button(I18nProperties.getCaption(Captions.actionGenerate));
    CssStyles.style(generateButton, ValoTheme.BUTTON_PRIMARY);
    generateButton.addClickListener(e -> {
        // Check whether there is any invalid empty filter or grouping data
        Notification errorNotification = null;
        for (StatisticsFilterComponent filterComponent : filterComponents) {
            if (filterComponent.getSelectedAttribute() != StatisticsCaseAttribute.REGION_DISTRICT
                    && (filterComponent.getSelectedAttribute() == null
                            || filterComponent.getSelectedAttribute().getSubAttributes().length > 0
                                    && filterComponent.getSelectedSubAttribute() == null)) {
                errorNotification = new Notification(
                        I18nProperties.getString(Strings.messageSpecifyFilterAttributes), Type.WARNING_MESSAGE);
                break;
            }/*from   w  w w . j a  va  2s .co  m*/
        }

        if (errorNotification == null && visualizationComponent.getRowsAttribute() != null
                && visualizationComponent.getRowsAttribute().getSubAttributes().length > 0
                && visualizationComponent.getRowsSubAttribute() == null) {
            errorNotification = new Notification(I18nProperties.getString(Strings.messageSpecifyRowAttribute),
                    Type.WARNING_MESSAGE);
        } else if (errorNotification == null && visualizationComponent.getColumnsAttribute() != null
                && visualizationComponent.getColumnsAttribute().getSubAttributes().length > 0
                && visualizationComponent.getColumnsSubAttribute() == null) {
            errorNotification = new Notification(
                    I18nProperties.getString(Strings.messageSpecifyColumnAttribute), Type.WARNING_MESSAGE);
        }

        if (errorNotification != null) {
            errorNotification.setDelayMsec(-1);
            errorNotification.show(Page.getCurrent());
        } else {
            resultsLayout.removeAllComponents();
            switch (visualizationComponent.getVisualizationType()) {
            case TABLE:
                generateTable();
                break;
            case MAP:
                generateMap();
                break;
            default:
                generateChart();
                break;
            }
        }
    });

    statisticsLayout.addComponent(generateButton);
}

From source file:de.unioninvestment.eai.portal.portlet.crud.scripting.domain.NotificationProvider.java

License:Apache License

/**
 * Zeigt entweder eine Warnung, einen Fehler oder eine Info im Window fr
 * die entsprechende Anzeige/*  w ww .j a v a2  s .c  o  m*/
 * 
 * @param description
 *            Der anzuzeigende Text der Notification
 */
public void doCall(String description) {
    if (type == Type.ERROR) {
        Notification.show(Type.ERROR.value, description, Notification.Type.ERROR_MESSAGE);
    } else if (type == Type.WARNING) {
        Notification.show(Type.WARNING.value, description, Notification.Type.WARNING_MESSAGE);
    } else {
        Notification notification = new Notification(Type.INFO.value, description,
                Notification.Type.HUMANIZED_MESSAGE);
        notification.setDelayMsec(1500);
        notification.show(Page.getCurrent());
    }
}

From source file:de.uni_tuebingen.qbic.qbicmainportlet.DatasetViewFilterGenerator.java

License:Open Source License

@Override
public void filterRemoved(Object propertyId) {
    Notification n = new Notification("Filter removed from: " + propertyId,
            Notification.Type.TRAY_NOTIFICATION);
    n.setDelayMsec(800);
    // n.show(Page.getCurrent());
}