Example usage for com.vaadin.ui Notification Notification

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

Introduction

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

Prototype

public Notification(String caption, String description, Type type, boolean htmlContentAllowed) 

Source Link

Document

Creates a notification message of the specified type, with a bigger caption and smaller description.

Usage

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

License:Open Source License

public void dearchiveAllSelectedItems(Collection<CaseIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoCasesSelected),
                I18nProperties.getString(Strings.messageNoCasesSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {/*from   w  ww  . j  ava2 s.  co m*/
        VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingConfirmDearchiving),
                new Label(String.format(I18nProperties.getString(Strings.confirmationDearchiveCases),
                        selectedRows.size())),
                I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), null, e -> {
                    if (e.booleanValue() == true) {
                        for (CaseIndexDto selectedRow : selectedRows) {
                            FacadeProvider.getCaseFacade().archiveOrDearchiveCase(selectedRow.getUuid(), false);
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingCasesDearchived),
                                I18nProperties.getString(Strings.messageCasesDearchived),
                                Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent());
                    }
                });
    }
}

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

License:Open Source License

public CaseImportLayout() {
    super();/*from ww  w.j  a v  a2  s . co  m*/

    addDownloadResourcesComponent(1, new ClassResource("/SORMAS_Import_Guide.pdf"),
            new ClassResource("/doc/SORMAS_Data_Dictionary.xlsx"));
    addDownloadImportTemplateComponent(2,
            FacadeProvider.getImportFacade().getCaseImportTemplateFilePath().toString(),
            "sormas_import_case_template.csv");
    addImportCsvComponent(3, new ImportReceiver("_case_import_", new Consumer<File>() {
        @Override
        public void accept(File file) {
            resetDownloadErrorReportButton();

            try {
                CaseImporter importer = new CaseImporter(file, currentUser, currentUI);
                importer.startImport(new Consumer<StreamResource>() {
                    @Override
                    public void accept(StreamResource resource) {
                        extendDownloadErrorReportButton(resource);
                    }
                });
            } catch (IOException e) {
                new Notification(I18nProperties.getString(Strings.headingImportFailed),
                        I18nProperties.getString(Strings.messageImportFailed), Type.ERROR_MESSAGE, false)
                                .show(Page.getCurrent());
            }
        }
    }));
    addDownloadErrorReportComponent(4);
}

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. j  av a  2  s  .c  o m*/
    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.ContactController.java

License:Open Source License

public void showBulkContactDataEditComponent(Collection<ContactIndexDto> selectedContacts, String caseUuid) {
    if (selectedContacts.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoContactsSelected),
                I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
        return;//from   w  w  w  .  j  a va 2 s .c  o  m
    }

    // Check if cases with multiple districts have been selected
    String districtUuid = null;
    for (ContactIndexDto selectedContact : selectedContacts) {
        if (districtUuid == null) {
            districtUuid = selectedContact.getCaseDistrictUuid();
        } else if (!districtUuid.equals(selectedContact.getCaseDistrictUuid())) {
            districtUuid = null;
            break;
        }
    }

    DistrictReferenceDto district = FacadeProvider.getDistrictFacade().getDistrictReferenceByUuid(districtUuid);

    // Create a temporary contact in order to use the CommitDiscardWrapperComponent
    ContactDto tempContact = new ContactDto();

    BulkContactDataForm form = new BulkContactDataForm(district);
    form.setValue(tempContact);
    final CommitDiscardWrapperComponent<BulkContactDataForm> editView = new CommitDiscardWrapperComponent<BulkContactDataForm>(
            form, form.getFieldGroup());

    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView,
            I18nProperties.getString(Strings.headingEditContacts));

    editView.addCommitListener(new CommitListener() {
        @Override
        public void onCommit() {
            ContactDto updatedTempContact = form.getValue();
            for (ContactIndexDto indexDto : selectedContacts) {
                ContactDto contactDto = FacadeProvider.getContactFacade().getContactByUuid(indexDto.getUuid());
                if (form.getClassificationCheckBox().getValue() == true) {
                    contactDto.setContactClassification(updatedTempContact.getContactClassification());
                }
                // Setting the contact officer is only allowed if all selected contacts are in the same district
                if (district != null && form.getContactOfficerCheckBox().getValue() == true) {
                    contactDto.setContactOfficer(updatedTempContact.getContactOfficer());
                }

                FacadeProvider.getContactFacade().saveContact(contactDto);
            }
            popupWindow.close();
            if (caseUuid == null) {
                overview();
            } else {
                caseContactsOverview(caseUuid);
            }
            Notification.show(I18nProperties.getString(Strings.messageContactsEdited), Type.HUMANIZED_MESSAGE);
        }
    });

    editView.addDiscardListener(new DiscardListener() {
        @Override
        public void onDiscard() {
            popupWindow.close();
        }
    });
}

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

License:Open Source License

public void deleteAllSelectedItems(Collection<ContactIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoContactsSelected),
                I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {//from   www .j a  v a2 s .  c  o m
        VaadinUiUtil.showDeleteConfirmationWindow(String
                .format(I18nProperties.getString(Strings.confirmationDeleteContacts), selectedRows.size()),
                new Runnable() {
                    public void run() {
                        for (ContactIndexDto selectedRow : selectedRows) {
                            FacadeProvider.getContactFacade().deleteContact(
                                    new ContactReferenceDto((selectedRow).getUuid()),
                                    UserProvider.getCurrent().getUuid());
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingContactsDeleted),
                                I18nProperties.getString(Strings.messageContactsDeleted),
                                Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent());
                    }
                });
    }
}

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

License:Open Source License

public void cancelFollowUpOfAllSelectedItems(Collection<ContactIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoContactsSelected),
                I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {// ww  w  .  j  a v a  2s.c  om
        VaadinUiUtil.showDeleteConfirmationWindow(String
                .format(I18nProperties.getString(Strings.confirmationCancelFollowUp), selectedRows.size()),
                new Runnable() {
                    public void run() {
                        for (ContactIndexDto contact : selectedRows) {
                            if (contact.getFollowUpStatus() != FollowUpStatus.NO_FOLLOW_UP) {
                                ContactDto contactDto = FacadeProvider.getContactFacade()
                                        .getContactByUuid(contact.getUuid());
                                contactDto.setFollowUpStatus(FollowUpStatus.CANCELED);
                                contactDto.setFollowUpComment(
                                        String.format(I18nProperties.getString(Strings.infoCanceledBy),
                                                UserProvider.getCurrent().getUserName()));
                                FacadeProvider.getContactFacade().saveContact(contactDto);
                            }
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingFollowUpCanceled),
                                I18nProperties.getString(Strings.messageFollowUpCanceled),
                                Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent());
                    }
                });
    }
}

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

License:Open Source License

public void setAllSelectedItemsToLostToFollowUp(Collection<ContactIndexDto> selectedRows, Runnable callback) {
    if (selectedRows.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoContactsSelected),
                I18nProperties.getString(Strings.messageNoContactsSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
    } else {// w w w.  jav  a2s  .  c om
        VaadinUiUtil.showDeleteConfirmationWindow(String
                .format(I18nProperties.getString(Strings.confirmationLostToFollowUp), selectedRows.size()),
                new Runnable() {
                    public void run() {
                        for (ContactIndexDto contact : selectedRows) {
                            if (contact.getFollowUpStatus() != FollowUpStatus.NO_FOLLOW_UP) {
                                ContactDto contactDto = FacadeProvider.getContactFacade()
                                        .getContactByUuid(contact.getUuid());
                                contactDto.setFollowUpStatus(FollowUpStatus.LOST);
                                contactDto.setFollowUpComment(
                                        String.format(I18nProperties.getString(Strings.infoLostToFollowUpBy),
                                                UserProvider.getCurrent().getUserName()));
                                FacadeProvider.getContactFacade().saveContact(contactDto);
                            }
                        }
                        callback.run();
                        new Notification(I18nProperties.getString(Strings.headingFollowUpStatusChanged),
                                I18nProperties.getString(Strings.messageFollowUpStatusChanged),
                                Type.HUMANIZED_MESSAGE, false).show(Page.getCurrent());
                    }
                });
    }
}

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

License:Open Source License

public VerticalLayout createFilterBar() {
    VerticalLayout filterLayout = new VerticalLayout();
    filterLayout.setSpacing(false);/*from w ww.  ja  va  2  s  .c  o  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.dashboard.DashboardFilterLayout.java

License:Open Source License

private void createDateFilters() {
    HorizontalLayout dateFilterLayout = new HorizontalLayout();
    dateFilterLayout.addStyleName(CssStyles.LAYOUT_MINIMAL);
    dateFilterLayout.setSpacing(true);//from   w w w  .j  a v a2 s .c  om
    addComponent(dateFilterLayout);
    Date now = new Date();

    // Date filters
    Button todayButton = new Button(I18nProperties.getCaption(Captions.dashboardToday));
    initializeDateFilterButton(todayButton);
    todayButton.addClickListener(e -> {
        setDateFilter(DateHelper.getStartOfDay(now), DateHelper.getEndOfDay(now));
        dashboardView.refreshDashboard();
    });

    Button yesterdayButton = new Button(I18nProperties.getCaption(Captions.dashboardYesterday));
    initializeDateFilterButton(yesterdayButton);
    yesterdayButton.addClickListener(e -> {
        setDateFilter(DateHelper.getStartOfDay(DateHelper.subtractDays(now, 1)),
                DateHelper.getEndOfDay(DateHelper.subtractDays(now, 1)));
        dashboardView.refreshDashboard();
    });

    Button thisWeekButton = new Button(I18nProperties.getCaption(Captions.dashboardThisWeek));
    initializeDateFilterButton(thisWeekButton);
    thisWeekButton.addClickListener(e -> {
        setDateFilter(DateHelper.getStartOfWeek(now), DateHelper.getEndOfWeek(now));
        dashboardView.refreshDashboard();
    });
    CssStyles.style(thisWeekButton, CssStyles.BUTTON_FILTER_DARK);
    CssStyles.removeStyles(thisWeekButton, CssStyles.BUTTON_FILTER_LIGHT);

    Button lastWeekButton = new Button(I18nProperties.getCaption(Captions.dashboardLastWeek));
    initializeDateFilterButton(lastWeekButton);
    lastWeekButton.addClickListener(e -> {
        setDateFilter(DateHelper.getStartOfWeek(DateHelper.subtractWeeks(now, 1)),
                DateHelper.getEndOfWeek(DateHelper.subtractWeeks(now, 1)));
        dashboardView.refreshDashboard();
    });

    Button thisYearButton = new Button(I18nProperties.getCaption(Captions.dashboardThisYear));
    initializeDateFilterButton(thisYearButton);
    thisYearButton.addClickListener(e -> {
        setDateFilter(DateHelper.getStartOfYear(now), DateHelper.getEndOfYear(now));
        dashboardView.refreshDashboard();
    });

    Button lastYearButton = new Button(I18nProperties.getCaption(Captions.dashboardLastYear));
    initializeDateFilterButton(lastYearButton);
    lastYearButton.addClickListener(e -> {
        setDateFilter(DateHelper.getStartOfYear(DateHelper.subtractYears(now, 1)),
                DateHelper.getEndOfYear(DateHelper.subtractYears(now, 1)));
        dashboardView.refreshDashboard();
    });

    customButton = new PopupButton(I18nProperties.getCaption(Captions.dashboardCustom));
    initializeDateFilterButton(customButton);

    // Custom filter
    HorizontalLayout customDateFilterLayout = new HorizontalLayout();
    customDateFilterLayout.setSpacing(true);
    customDateFilterLayout.setMargin(true);

    // 'Apply custom filter' button
    Button applyButton = new Button(I18nProperties.getCaption(Captions.dashboardApplyCustomFilter));
    CssStyles.style(applyButton, CssStyles.FORCE_CAPTION, ValoTheme.BUTTON_PRIMARY);

    // Date & Epi Week filter
    EpiWeekAndDateFilterComponent<NewCaseDateType> weekAndDateFilter = new EpiWeekAndDateFilterComponent<>(
            applyButton, true, true, I18nProperties.getString(Strings.infoCaseDate));
    customDateFilterLayout.addComponent(weekAndDateFilter);
    dashboardDataProvider
            .setDateFilterOption((DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter().getValue());
    dashboardDataProvider.setFromDate(
            DateHelper.getEpiWeekStart((EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue()));
    dashboardDataProvider
            .setToDate(DateHelper.getEpiWeekEnd((EpiWeek) weekAndDateFilter.getWeekToFilter().getValue()));

    customDateFilterLayout.addComponent(applyButton);

    // Apply button listener
    applyButton.addClickListener(e -> {
        DateFilterOption dateFilterOption = (DateFilterOption) weekAndDateFilter.getDateFilterOptionFilter()
                .getValue();
        Date fromDate = null;
        Date toDate = null;
        EpiWeek fromWeek = null;
        EpiWeek toWeek = null;
        dashboardDataProvider.setDateFilterOption(dateFilterOption);
        if (dateFilterOption == DateFilterOption.DATE) {
            fromDate = weekAndDateFilter.getDateFromFilter().getValue();
            dashboardDataProvider.setFromDate(fromDate);
            toDate = weekAndDateFilter.getDateToFilter().getValue();
            dashboardDataProvider.setToDate(toDate);
        } else {
            fromWeek = (EpiWeek) weekAndDateFilter.getWeekFromFilter().getValue();
            dashboardDataProvider.setFromDate(DateHelper.getEpiWeekStart(fromWeek));
            toWeek = (EpiWeek) weekAndDateFilter.getWeekToFilter().getValue();
            dashboardDataProvider.setToDate(DateHelper.getEpiWeekEnd(toWeek));
        }

        if ((fromDate != null && toDate != null) || (fromWeek != null && toWeek != null)) {
            changeDateFilterButtonsStyles(customButton);
            dashboardView.refreshDashboard();
            if (dateFilterOption == DateFilterOption.DATE) {
                customButton.setCaption(DateHelper.formatLocalShortDate(fromDate) + " - "
                        + DateHelper.formatLocalShortDate(toDate));
            } else {
                customButton.setCaption(fromWeek.toShortString() + " - " + toWeek.toShortString());
            }
        } else {
            if (dateFilterOption == DateFilterOption.DATE) {
                new Notification(I18nProperties.getString(Strings.headingMissingDateFilter),
                        I18nProperties.getString(Strings.messageMissingDateFilter), Type.ERROR_MESSAGE, false)
                                .show(Page.getCurrent());
            } else {
                new Notification(I18nProperties.getString(Strings.headingMissingEpiWeekFilter),
                        I18nProperties.getString(Strings.messageMissingEpiWeekFilter), Type.ERROR_MESSAGE,
                        false).show(Page.getCurrent());
            }
        }
    });

    customButton.setContent(customDateFilterLayout);

    dateFilterLayout.addComponents(todayButton, yesterdayButton, thisWeekButton, lastWeekButton, thisYearButton,
            lastYearButton, customButton);

    infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
    infoLabel.setSizeUndefined();
    CssStyles.style(infoLabel, CssStyles.LABEL_XLARGE, CssStyles.LABEL_SECONDARY);
    addComponent(infoLabel);
    setComponentAlignment(infoLabel, Alignment.TOP_RIGHT);
}

From source file:de.symeda.sormas.ui.events.EventController.java

License:Open Source License

public void showBulkEventDataEditComponent(Collection<EventIndexDto> selectedEvents) {
    if (selectedEvents.size() == 0) {
        new Notification(I18nProperties.getString(Strings.headingNoEventsSelected),
                I18nProperties.getString(Strings.messageNoEventsSelected), Type.WARNING_MESSAGE, false)
                        .show(Page.getCurrent());
        return;//  www.jav  a 2  s.c om
    }

    // Create a temporary event in order to use the CommitDiscardWrapperComponent
    EventDto tempEvent = new EventDto();

    BulkEventDataForm form = new BulkEventDataForm();
    form.setValue(tempEvent);
    final CommitDiscardWrapperComponent<BulkEventDataForm> editView = new CommitDiscardWrapperComponent<BulkEventDataForm>(
            form, form.getFieldGroup());

    Window popupWindow = VaadinUiUtil.showModalPopupWindow(editView,
            I18nProperties.getString(Strings.headingEditEvents));

    editView.addCommitListener(new CommitListener() {
        @Override
        public void onCommit() {
            EventDto updatedTempEvent = form.getValue();
            for (EventIndexDto indexDto : selectedEvents) {
                EventDto eventDto = FacadeProvider.getEventFacade().getEventByUuid(indexDto.getUuid());
                if (form.getEventStatusCheckBox().getValue() == true) {
                    eventDto.setEventStatus(updatedTempEvent.getEventStatus());
                }

                FacadeProvider.getEventFacade().saveEvent(eventDto);
            }
            popupWindow.close();
            navigateToIndex();
            Notification.show(I18nProperties.getString(Strings.messageEventsEdited), Type.HUMANIZED_MESSAGE);
        }
    });

    editView.addDiscardListener(new DiscardListener() {
        @Override
        public void onDiscard() {
            popupWindow.close();
        }
    });
}