Example usage for com.vaadin.ui Button addClickListener

List of usage examples for com.vaadin.ui Button addClickListener

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

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

License:Open Source License

@Override
protected void addFields() {
    if (person == null || disease == null) {
        return;/*from   w ww  .j a va  2  s.  c o m*/
    }

    // Add fields
    addFields(CaseDataDto.UUID, CaseDataDto.REPORT_DATE, CaseDataDto.REPORTING_USER,
            CaseDataDto.DISTRICT_LEVEL_DATE, CaseDataDto.REGION_LEVEL_DATE, CaseDataDto.NATIONAL_LEVEL_DATE,
            CaseDataDto.CLASSIFICATION_DATE, CaseDataDto.CLASSIFICATION_USER,
            CaseDataDto.CLASSIFICATION_COMMENT, CaseDataDto.NOTIFYING_CLINIC,
            CaseDataDto.NOTIFYING_CLINIC_DETAILS, CaseDataDto.CLINICIAN_NAME, CaseDataDto.CLINICIAN_PHONE,
            CaseDataDto.CLINICIAN_EMAIL);

    // Button to automatically assign a new epid number
    Button assignNewEpidNumberButton = new Button(
            I18nProperties.getCaption(Captions.actionAssignNewEpidNumber));
    CssStyles.style(assignNewEpidNumberButton, ValoTheme.BUTTON_PRIMARY, CssStyles.FORCE_CAPTION);
    getContent().addComponent(assignNewEpidNumberButton, ASSIGN_NEW_EPID_NUMBER_LOC);
    assignNewEpidNumberButton.setVisible(false);

    TextField epidField = addField(CaseDataDto.EPID_NUMBER, TextField.class);
    epidField.setInvalidCommitted(true);
    CssStyles.style(epidField, CssStyles.ERROR_COLOR_PRIMARY);

    assignNewEpidNumberButton.addClickListener(e -> {
        epidField.setValue(FacadeProvider.getCaseFacade().generateEpidNumber(getValue().toReference()));
    });

    addField(CaseDataDto.CASE_CLASSIFICATION, OptionGroup.class);
    addField(CaseDataDto.INVESTIGATION_STATUS, OptionGroup.class);
    addField(CaseDataDto.OUTCOME, OptionGroup.class);
    addField(CaseDataDto.SEQUELAE, OptionGroup.class);
    addFields(CaseDataDto.INVESTIGATED_DATE, CaseDataDto.OUTCOME_DATE, CaseDataDto.SEQUELAE_DETAILS);

    ComboBox diseaseField = addDiseaseField(CaseDataDto.DISEASE, false);
    addField(CaseDataDto.DISEASE_DETAILS, TextField.class);
    addField(CaseDataDto.PLAGUE_TYPE, OptionGroup.class);
    addField(CaseDataDto.DENGUE_FEVER_TYPE, OptionGroup.class);

    addField(CaseDataDto.CASE_ORIGIN, TextField.class);
    TextField healthFacilityDetails = addField(CaseDataDto.HEALTH_FACILITY_DETAILS, TextField.class);
    addField(CaseDataDto.REGION, ComboBox.class);
    addField(CaseDataDto.DISTRICT, ComboBox.class);
    addField(CaseDataDto.COMMUNITY, ComboBox.class);
    addField(CaseDataDto.HEALTH_FACILITY, ComboBox.class);
    ComboBox surveillanceOfficerField = addField(CaseDataDto.SURVEILLANCE_OFFICER, ComboBox.class);
    surveillanceOfficerField.setNullSelectionAllowed(true);
    addField(CaseDataDto.POINT_OF_ENTRY, ComboBox.class);
    addField(CaseDataDto.POINT_OF_ENTRY_DETAILS, TextField.class);

    addFields(CaseDataDto.PREGNANT, CaseDataDto.VACCINATION, CaseDataDto.VACCINATION_DOSES,
            CaseDataDto.VACCINATION_INFO_SOURCE, CaseDataDto.SMALLPOX_VACCINATION_SCAR,
            CaseDataDto.SMALLPOX_VACCINATION_RECEIVED, CaseDataDto.VACCINATION_DATE);

    // Set initial visibilities

    initializeVisibilitiesAndAllowedVisibilities(disease, viewMode);

    // Set requirements that don't need visibility changes and read only status

    setRequired(true, CaseDataDto.REPORT_DATE, CaseDataDto.CASE_CLASSIFICATION,
            CaseDataDto.INVESTIGATION_STATUS, CaseDataDto.OUTCOME, CaseDataDto.DISEASE);
    setSoftRequired(true, CaseDataDto.INVESTIGATED_DATE, CaseDataDto.OUTCOME_DATE, CaseDataDto.PLAGUE_TYPE,
            CaseDataDto.SURVEILLANCE_OFFICER);
    FieldHelper.setReadOnlyWhen(getFieldGroup(), CaseDataDto.INVESTIGATED_DATE,
            CaseDataDto.INVESTIGATION_STATUS, Arrays.asList(InvestigationStatus.PENDING), false);
    setReadOnly(true, CaseDataDto.UUID, CaseDataDto.REPORTING_USER, CaseDataDto.CLASSIFICATION_USER,
            CaseDataDto.CLASSIFICATION_DATE, CaseDataDto.REGION, CaseDataDto.DISTRICT, CaseDataDto.COMMUNITY,
            CaseDataDto.HEALTH_FACILITY, CaseDataDto.HEALTH_FACILITY_DETAILS, CaseDataDto.POINT_OF_ENTRY,
            CaseDataDto.POINT_OF_ENTRY_DETAILS, CaseDataDto.CASE_ORIGIN);
    setReadOnly(!UserProvider.getCurrent().hasUserRight(UserRight.CASE_CHANGE_DISEASE), CaseDataDto.DISEASE);
    setReadOnly(!UserProvider.getCurrent().hasUserRight(UserRight.CASE_INVESTIGATE),
            CaseDataDto.INVESTIGATION_STATUS, CaseDataDto.INVESTIGATED_DATE);
    setReadOnly(!UserProvider.getCurrent().hasUserRight(UserRight.CASE_CLASSIFY),
            CaseDataDto.CASE_CLASSIFICATION, CaseDataDto.OUTCOME, CaseDataDto.OUTCOME_DATE);

    // Set conditional visibilities - ALWAYS call isVisibleAllowed before
    // dynamically setting the visibility

    if (isVisibleAllowed(CaseDataDto.PREGNANT)) {
        setVisible(person.getSex() == Sex.FEMALE, CaseDataDto.PREGNANT);
    }
    if (isVisibleAllowed(CaseDataDto.VACCINATION_DOSES)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.VACCINATION_DOSES, CaseDataDto.VACCINATION,
                Arrays.asList(Vaccination.VACCINATED), true);
    }
    if (isVisibleAllowed(CaseDataDto.VACCINATION_INFO_SOURCE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.VACCINATION_INFO_SOURCE,
                CaseDataDto.VACCINATION, Arrays.asList(Vaccination.VACCINATED), true);
    }
    if (isVisibleAllowed(CaseDataDto.DISEASE_DETAILS)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.DISEASE_DETAILS),
                CaseDataDto.DISEASE, Arrays.asList(Disease.OTHER), true);
        FieldHelper.setRequiredWhen(getFieldGroup(), CaseDataDto.DISEASE,
                Arrays.asList(CaseDataDto.DISEASE_DETAILS), Arrays.asList(Disease.OTHER));
    }
    if (isVisibleAllowed(CaseDataDto.PLAGUE_TYPE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), Arrays.asList(CaseDataDto.PLAGUE_TYPE), CaseDataDto.DISEASE,
                Arrays.asList(Disease.PLAGUE), true);
    }
    if (isVisibleAllowed(CaseDataDto.SMALLPOX_VACCINATION_SCAR)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.SMALLPOX_VACCINATION_SCAR,
                CaseDataDto.SMALLPOX_VACCINATION_RECEIVED, Arrays.asList(YesNoUnknown.YES), true);
    }
    if (isVisibleAllowed(CaseDataDto.VACCINATION_DATE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.VACCINATION_DATE,
                CaseDataDto.SMALLPOX_VACCINATION_RECEIVED, Arrays.asList(YesNoUnknown.YES), true);
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.VACCINATION_DATE, CaseDataDto.VACCINATION,
                Arrays.asList(Vaccination.VACCINATED), true);
    }
    if (isVisibleAllowed(CaseDataDto.OUTCOME_DATE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.OUTCOME_DATE, CaseDataDto.OUTCOME,
                Arrays.asList(CaseOutcome.DECEASED, CaseOutcome.RECOVERED, CaseOutcome.UNKNOWN), true);
    }
    if (isVisibleAllowed(CaseDataDto.SEQUELAE)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.SEQUELAE, CaseDataDto.OUTCOME,
                Arrays.asList(CaseOutcome.RECOVERED, CaseOutcome.UNKNOWN), true);
    }
    if (isVisibleAllowed(CaseDataDto.SEQUELAE_DETAILS)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.SEQUELAE_DETAILS, CaseDataDto.SEQUELAE,
                Arrays.asList(YesNoUnknown.YES), true);
    }
    if (isVisibleAllowed(CaseDataDto.NOTIFYING_CLINIC_DETAILS)) {
        FieldHelper.setVisibleWhen(getFieldGroup(), CaseDataDto.NOTIFYING_CLINIC_DETAILS,
                CaseDataDto.NOTIFYING_CLINIC, Arrays.asList(HospitalWardType.OTHER), true);
    }
    setVisible(UserProvider.getCurrent().hasUserRight(UserRight.CASE_MANAGEMENT_ACCESS),
            CaseDataDto.CLINICIAN_NAME, CaseDataDto.CLINICIAN_PHONE, CaseDataDto.CLINICIAN_EMAIL);

    // Other initializations

    if (disease == Disease.MONKEYPOX) {
        Image smallpoxVaccinationScarImg = new Image(null,
                new ThemeResource("img/smallpox-vaccination-scar.jpg"));
        CssStyles.style(smallpoxVaccinationScarImg, CssStyles.VSPACE_3);
        getContent().addComponent(smallpoxVaccinationScarImg, SMALLPOX_VACCINATION_SCAR_IMG);

        // Set up initial image visibility
        getContent().getComponent(SMALLPOX_VACCINATION_SCAR_IMG).setVisible(getFieldGroup()
                .getField(CaseDataDto.SMALLPOX_VACCINATION_RECEIVED).getValue() == YesNoUnknown.YES);

        // Set up image visibility listener
        getFieldGroup().getField(CaseDataDto.SMALLPOX_VACCINATION_RECEIVED).addValueChangeListener(e -> {
            getContent().getComponent(SMALLPOX_VACCINATION_SCAR_IMG)
                    .setVisible(e.getProperty().getValue() == YesNoUnknown.YES);
        });
    }

    List<String> medicalInformationFields = Arrays.asList(CaseDataDto.PREGNANT, CaseDataDto.VACCINATION,
            CaseDataDto.SMALLPOX_VACCINATION_RECEIVED);

    for (String medicalInformationField : medicalInformationFields) {
        if (getFieldGroup().getField(medicalInformationField).isVisible()) {
            Label medicalInformationCaptionLabel = new Label(
                    I18nProperties.getString(Strings.headingMedicalInformation));
            medicalInformationCaptionLabel.addStyleName(CssStyles.H3);
            getContent().addComponent(medicalInformationCaptionLabel, MEDICAL_INFORMATION_LOC);
            break;
        }
    }

    Label paperFormDatesLabel = new Label(I18nProperties.getString(Strings.headingPaperFormDates));
    paperFormDatesLabel.addStyleName(CssStyles.H3);
    getContent().addComponent(paperFormDatesLabel, PAPER_FORM_DATES_LOC);

    // Automatic case classification rules button - invisible for other diseases
    if (disease != Disease.OTHER) {
        Button classificationRulesButton = new Button(I18nProperties.getCaption(Captions.info),
                VaadinIcons.INFO_CIRCLE);
        CssStyles.style(classificationRulesButton, ValoTheme.BUTTON_PRIMARY, CssStyles.FORCE_CAPTION);
        classificationRulesButton.addClickListener(e -> {
            ControllerProvider.getCaseController().openClassificationRulesPopup(getValue());
        });
        getContent().addComponent(classificationRulesButton, CLASSIFICATION_RULES_LOC);
    }

    addValueChangeListener(e -> {
        diseaseField.addValueChangeListener(new DiseaseChangeListener(diseaseField, getValue().getDisease()));

        // Replace classification user if case has been automatically classified
        if (getValue().getClassificationDate() != null && getValue().getClassificationUser() == null) {
            getField(CaseDataDto.CLASSIFICATION_USER).setVisible(false);
            Label classifiedBySystemLabel = new Label(I18nProperties.getCaption(Captions.system));
            classifiedBySystemLabel.setCaption(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.CLASSIFIED_BY));
            getContent().addComponent(classifiedBySystemLabel, CLASSIFIED_BY_SYSTEM_LOC);
        }

        setEpidNumberError(epidField, assignNewEpidNumberButton, getValue().getEpidNumber());

        epidField.addValueChangeListener(f -> {
            setEpidNumberError(epidField, assignNewEpidNumberButton, (String) f.getProperty().getValue());
        });

        // Set health facility details visibility and caption
        if (getValue().getHealthFacility() != null) {
            boolean otherHealthFacility = getValue().getHealthFacility().getUuid()
                    .equals(FacilityDto.OTHER_FACILITY_UUID);
            boolean noneHealthFacility = getValue().getHealthFacility().getUuid()
                    .equals(FacilityDto.NONE_FACILITY_UUID);
            boolean detailsVisible = otherHealthFacility || noneHealthFacility;

            if (isVisibleAllowed(healthFacilityDetails)) {
                healthFacilityDetails.setVisible(detailsVisible);
            }

            if (otherHealthFacility) {
                healthFacilityDetails.setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX,
                        CaseDataDto.HEALTH_FACILITY_DETAILS));
            }
            if (noneHealthFacility) {
                healthFacilityDetails.setCaption(
                        I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, NONE_HEALTH_FACILITY_DETAILS));
            }
        } else {
            setVisible(false, CaseDataDto.CLINICIAN_NAME, CaseDataDto.CLINICIAN_PHONE,
                    CaseDataDto.CLINICIAN_EMAIL);
        }

        // Set health facility/point of entry visibility based on case origin
        if (getValue().getCaseOrigin() == CaseOrigin.POINT_OF_ENTRY) {
            setVisible(true, CaseDataDto.POINT_OF_ENTRY);
            setVisible(getValue().getPointOfEntry().isOtherPointOfEntry(), CaseDataDto.POINT_OF_ENTRY_DETAILS);

            if (getValue().getHealthFacility() == null) {
                setVisible(false, CaseDataDto.COMMUNITY, CaseDataDto.HEALTH_FACILITY,
                        CaseDataDto.HEALTH_FACILITY_DETAILS);
            }
        } else {
            setVisible(false, CaseDataDto.POINT_OF_ENTRY, CaseDataDto.POINT_OF_ENTRY_DETAILS);
        }

        // Hide case origin from port health users
        if (UserRole.isPortHealthUser(UserProvider.getCurrent().getUserRoles())) {
            setVisible(false, CaseDataDto.CASE_ORIGIN);
        }
    });
}

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

License:Open Source License

public CasesView() {
    super(VIEW_NAME);
    originalViewTitle = getViewTitleLabel().getValue();

    criteria = ViewModelProviders.of(CasesView.class).get(CaseCriteria.class);
    if (criteria.getArchived() == null) {
        criteria.archived(false);//  www.  j  av  a 2  s .  c o m
    }

    grid = new CaseGrid();
    grid.setCriteria(criteria);
    gridLayout = new VerticalLayout();
    gridLayout.addComponent(createFilterBar());
    gridLayout.addComponent(createStatusFilterBar());
    gridLayout.addComponent(grid);
    gridLayout.setMargin(true);
    gridLayout.setSpacing(false);
    gridLayout.setSizeFull();
    gridLayout.setExpandRatio(grid, 1);
    gridLayout.setStyleName("crud-main-layout");

    grid.getDataProvider().addDataProviderListener(e -> updateStatusButtons());

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_IMPORT)) {
        Button importButton = new Button(I18nProperties.getCaption(Captions.actionImport));
        importButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        importButton.setIcon(VaadinIcons.UPLOAD);
        importButton.addClickListener(e -> {
            Window popupWindow = VaadinUiUtil.showPopupWindow(new CaseImportLayout());
            popupWindow.setCaption(I18nProperties.getString(Strings.headingImportCases));
            popupWindow.addCloseListener(c -> {
                grid.reload();
            });
        });
        addHeaderComponent(importButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_EXPORT)) {
        PopupButton exportButton = new PopupButton(I18nProperties.getCaption(Captions.export));
        exportButton.setId("export");
        exportButton.setIcon(VaadinIcons.DOWNLOAD);
        VerticalLayout exportLayout = new VerticalLayout();
        exportLayout.setSpacing(true);
        exportLayout.setMargin(true);
        exportLayout.addStyleName(CssStyles.LAYOUT_MINIMAL);
        exportLayout.setWidth(200, Unit.PIXELS);
        exportButton.setContent(exportLayout);
        addHeaderComponent(exportButton);

        Button basicExportButton = new Button(I18nProperties.getCaption(Captions.exportBasic));
        basicExportButton.setId("basicExport");
        basicExportButton.setDescription(I18nProperties.getString(Strings.infoBasicExport));
        basicExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        basicExportButton.setIcon(VaadinIcons.TABLE);
        basicExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(basicExportButton);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_cases",
                "sormas_cases_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(basicExportButton);

        Button extendedExportButton = new Button(I18nProperties.getCaption(Captions.exportDetailed));
        extendedExportButton.setId("extendedExport");
        extendedExportButton.setDescription(I18nProperties.getString(Strings.infoDetailedExport));
        extendedExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        extendedExportButton.setIcon(VaadinIcons.FILE_TEXT);
        extendedExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(extendedExportButton);

        StreamResource extendedExportStreamResource = DownloadUtil.createCsvExportStreamResource(
                CaseExportDto.class,
                (Integer start, Integer max) -> FacadeProvider.getCaseFacade()
                        .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max),
                (propertyId, type) -> {
                    String caption = I18nProperties.getPrefixCaption(CaseExportDto.I18N_PREFIX, propertyId,
                            I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId,
                                    I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId,
                                            I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, propertyId,
                                                    I18nProperties.getPrefixCaption(EpiDataDto.I18N_PREFIX,
                                                            propertyId,
                                                            I18nProperties.getPrefixCaption(
                                                                    HospitalizationDto.I18N_PREFIX,
                                                                    propertyId))))));
                    if (Date.class.isAssignableFrom(type)) {
                        caption += " (" + DateHelper.getLocalShortDatePattern() + ")";
                    }
                    return caption;
                }, "sormas_cases_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        new FileDownloader(extendedExportStreamResource).extend(extendedExportButton);

        Button sampleExportButton = new Button(I18nProperties.getCaption(Captions.exportSamples));
        sampleExportButton.setId("sampleExport");
        sampleExportButton.setDescription(I18nProperties.getString(Strings.infoSampleExport));
        sampleExportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        sampleExportButton.setIcon(VaadinIcons.FILE_TEXT);
        sampleExportButton.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(sampleExportButton);

        StreamResource sampleExportStreamResource = DownloadUtil.createCsvExportStreamResource(
                SampleExportDto.class,
                (Integer start, Integer max) -> FacadeProvider.getSampleFacade()
                        .getExportList(UserProvider.getCurrent().getUuid(), grid.getCriteria(), start, max),
                (propertyId, type) -> {
                    String caption = I18nProperties.getPrefixCaption(SampleExportDto.I18N_PREFIX, propertyId,
                            I18nProperties.getPrefixCaption(SampleDto.I18N_PREFIX, propertyId,
                                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, propertyId,
                                            I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, propertyId,
                                                    I18nProperties.getPrefixCaption(
                                                            AdditionalTestDto.I18N_PREFIX, propertyId)))));
                    if (Date.class.isAssignableFrom(type)) {
                        caption += " (" + DateHelper.getLocalShortDatePattern() + ")";
                    }
                    return caption;
                }, "sormas_samples_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        new FileDownloader(sampleExportStreamResource).extend(sampleExportButton);

        // Warning if no filters have been selected
        Label warningLabel = new Label(I18nProperties.getString(Strings.infoExportNoFilters), ContentMode.HTML);
        warningLabel.setWidth(100, Unit.PERCENTAGE);
        exportLayout.addComponent(warningLabel);
        warningLabel.setVisible(false);

        exportButton.addClickListener(e -> {
            warningLabel.setVisible(!criteria.hasAnyFilterActive());
        });
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_MERGE)) {
        Button mergeDuplicatesButton = new Button(I18nProperties.getCaption(Captions.caseMergeDuplicates));
        mergeDuplicatesButton.setId("mergeDuplicates");
        mergeDuplicatesButton.setIcon(VaadinIcons.COMPRESS_SQUARE);
        mergeDuplicatesButton
                .addClickListener(e -> ControllerProvider.getCaseController().navigateToMergeCasesView());
        addHeaderComponent(mergeDuplicatesButton);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CASE_CREATE)) {
        createButton = new Button(I18nProperties.getCaption(Captions.caseNewCase));
        createButton.setId("create");
        createButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        createButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        createButton.addClickListener(e -> ControllerProvider.getCaseController().create());
        addHeaderComponent(createButton);
    }

    addComponent(gridLayout);
}

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

License:Open Source License

public VerticalLayout createFilterBar() {
    VerticalLayout filterLayout = new VerticalLayout();
    filterLayout.setSpacing(false);//www. j av  a2  s.co  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.configuration.DevModeView.java

License:Open Source License

public DevModeView() {
    super(VIEW_NAME);

    contentLayout = new VerticalLayout();
    contentLayout.setMargin(true);//  w ww.  ja v  a 2  s  .c  om
    contentLayout.setSpacing(true);
    contentLayout.setSizeFull();
    contentLayout.setStyleName("crud-main-layout");

    HorizontalLayout caseGeneratorLayout = new HorizontalLayout();

    TextField caseCountField = new TextField();
    caseCountField.setCaption(I18nProperties.getCaption(Captions.devModeCaseCount));
    caseGeneratorConfigBinder.forField(caseCountField)
            .withConverter(new StringToIntegerConverter("Must be a number"))
            .bind(CaseGenerationConfig::getCaseCount, CaseGenerationConfig::setCaseCount);
    caseGeneratorLayout.addComponent(caseCountField);

    DateField startDateField = new DateField();
    startDateField.setCaption(I18nProperties.getCaption(Captions.devModeStartDate));
    startDateField.setDateFormat(DateHelper.getLocalDatePattern());
    startDateField.setLenient(true);
    caseGeneratorConfigBinder.bind(startDateField, CaseGenerationConfig::getStartDate,
            CaseGenerationConfig::setStartDate);
    caseGeneratorLayout.addComponent(startDateField);

    DateField endDateField = new DateField();
    endDateField.setCaption(I18nProperties.getCaption(Captions.devModeEndDate));
    endDateField.setDateFormat(DateHelper.getLocalDatePattern());
    endDateField.setLenient(true);
    caseGeneratorConfigBinder.bind(endDateField, CaseGenerationConfig::getEndDate,
            CaseGenerationConfig::setEndDate);
    caseGeneratorLayout.addComponent(endDateField);

    ComboBox<Disease> diseaseField = new ComboBox<>(null,
            FacadeProvider.getDiseaseConfigurationFacade().getAllActivePrimaryDiseases());
    diseaseField.setCaption(I18nProperties.getCaption(Captions.devModeDisease));
    caseGeneratorConfigBinder.bind(diseaseField, CaseGenerationConfig::getDisease,
            CaseGenerationConfig::setDisease);
    caseGeneratorLayout.addComponent(diseaseField);

    List<RegionReferenceDto> regions = FacadeProvider.getRegionFacade().getAllAsReference();
    ComboBox<RegionReferenceDto> regionField = new ComboBox<RegionReferenceDto>(null, regions);
    regionField.setCaption(I18nProperties.getCaption(Captions.devModeRegion));
    caseGeneratorConfigBinder.bind(regionField, CaseGenerationConfig::getRegion,
            CaseGenerationConfig::setRegion);
    caseGeneratorLayout.addComponent(regionField);

    ComboBox<DistrictReferenceDto> districtField = new ComboBox<DistrictReferenceDto>();
    districtField.setCaption(I18nProperties.getCaption(Captions.devModeDistrict));
    caseGeneratorConfigBinder.bind(districtField, CaseGenerationConfig::getDistrict,
            CaseGenerationConfig::setDistrict);
    caseGeneratorLayout.addComponent(districtField);

    regionField.addValueChangeListener(event -> {
        RegionReferenceDto region = event.getValue();
        if (region != null) {
            districtField.setItems(FacadeProvider.getDistrictFacade().getAllByRegion(region.getUuid()));
        } else {
            districtField.setItems(new ArrayList<DistrictReferenceDto>());
        }
    });

    Button generateButton = new Button("generate cases");
    CssStyles.style(generateButton, CssStyles.FORCE_CAPTION);
    generateButton.addClickListener(e -> generateCases());
    caseGeneratorLayout.addComponent(generateButton);

    contentLayout.addComponent(caseGeneratorLayout);

    CaseGenerationConfig config = new CaseGenerationConfig();
    config.setRegion(regions.get(0));
    caseGeneratorConfigBinder.setBean(config);

    addComponent(contentLayout);
}

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

License:Open Source License

@Override
protected void addFields() {
    addField(ContactDto.CONTACT_CLASSIFICATION, OptionGroup.class);
    addField(ContactDto.CONTACT_STATUS, OptionGroup.class);
    addField(ContactDto.UUID, TextField.class);
    addField(ContactDto.REPORTING_USER, ComboBox.class);
    DateField lastContactDate = addField(ContactDto.LAST_CONTACT_DATE, DateField.class);
    addField(ContactDto.REPORT_DATE_TIME, DateField.class);
    OptionGroup contactProximity = addField(ContactDto.CONTACT_PROXIMITY, OptionGroup.class);
    contactProximity.removeStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
    ComboBox relationToCase = addField(ContactDto.RELATION_TO_CASE, ComboBox.class);
    addField(ContactDto.DESCRIPTION, TextArea.class).setRows(3);

    addField(ContactDto.FOLLOW_UP_STATUS, ComboBox.class);
    addField(ContactDto.FOLLOW_UP_COMMENT, TextArea.class).setRows(1);
    addDateField(ContactDto.FOLLOW_UP_UNTIL, DateField.class, -1);

    ComboBox contactOfficerField = addField(ContactDto.CONTACT_OFFICER, ComboBox.class);
    contactOfficerField.setNullSelectionAllowed(true);

    setReadOnly(true, ContactDto.UUID, ContactDto.REPORTING_USER, ContactDto.REPORT_DATE_TIME,
            ContactDto.CONTACT_STATUS, ContactDto.FOLLOW_UP_STATUS, ContactDto.FOLLOW_UP_UNTIL);

    FieldHelper.setRequiredWhen(getFieldGroup(), ContactDto.FOLLOW_UP_STATUS,
            Arrays.asList(ContactDto.FOLLOW_UP_COMMENT),
            Arrays.asList(FollowUpStatus.CANCELED, FollowUpStatus.LOST));

    addValueChangeListener(e -> {//from  www  . j av  a2s.co m
        if (getValue() != null) {
            CaseDataDto caseDto = FacadeProvider.getCaseFacade()
                    .getCaseDataByUuid(getValue().getCaze().getUuid());
            updateLastContactDateValidator();
            updateDiseaseConfiguration(caseDto.getDisease());

            updateFollowUpStatusComponents();

            contactOfficerField.addItems(FacadeProvider.getUserFacade()
                    .getUserRefsByDistrict(caseDto.getDistrict(), false, UserRole.CONTACT_OFFICER));

            getContent().removeComponent(TO_CASE_BTN_LOC);
            if (getValue().getResultingCase() != null) {
                // link to case
                Link linkToData = ControllerProvider.getCaseController().createLinkToData(
                        getValue().getResultingCase().getUuid(),
                        I18nProperties.getCaption(Captions.contactOpenContactCase));
                getContent().addComponent(linkToData, TO_CASE_BTN_LOC);
            } else if (getValue().getContactClassification() == ContactClassification.CONFIRMED) {
                // only when confirmed
                if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CONVERT)) {
                    Button toCaseButton = new Button(
                            I18nProperties.getCaption(Captions.contactCreateContactCase));
                    toCaseButton.addStyleName(ValoTheme.BUTTON_LINK);

                    toCaseButton.addClickListener(new ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            PersonReferenceDto personRef = getValue().getPerson();
                            CaseReferenceDto caseRef = getValue().getCaze();
                            CaseDataDto caze = FacadeProvider.getCaseFacade()
                                    .getCaseDataByUuid(caseRef.getUuid());
                            ControllerProvider.getCaseController().create(personRef, caze.getDisease(),
                                    getValue());
                        }
                    });

                    getContent().addComponent(toCaseButton, TO_CASE_BTN_LOC);
                }
            }
        }
    });

    setRequired(true, ContactDto.CONTACT_CLASSIFICATION, ContactDto.CONTACT_STATUS);
    FieldHelper.addSoftRequiredStyle(lastContactDate, contactProximity, relationToCase);
}

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

License:Open Source License

@SuppressWarnings("unchecked")
private void updateFollowUpStatusComponents() {

    getContent().removeComponent(CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
    getContent().removeComponent(LOST_FOLLOW_UP_BTN_LOC);

    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(ContactDto.FOLLOW_UP_STATUS);
    boolean followUpVisible = getValue() != null && statusField.isVisible();
    if (followUpVisible && UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EDIT)) {
        FollowUpStatus followUpStatus = statusField.getValue();
        if (followUpStatus == FollowUpStatus.FOLLOW_UP) {

            Button cancelButton = new Button(I18nProperties.getCaption(Captions.contactCancelFollowUp));
            cancelButton.setWidth(100, Unit.PERCENTAGE);
            cancelButton.addClickListener(new ClickListener() {
                @Override/*from  w  w w . ja v  a 2 s .  c  o m*/
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.CANCELED);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(cancelButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);

            Button lostButton = new Button(I18nProperties.getCaption(Captions.contactLostToFollowUp));
            lostButton.setWidth(100, Unit.PERCENTAGE);
            lostButton.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.LOST);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(lostButton, LOST_FOLLOW_UP_BTN_LOC);

        } else if (followUpStatus == FollowUpStatus.CANCELED || followUpStatus == FollowUpStatus.LOST) {

            Button resumeButton = new Button(I18nProperties.getCaption(Captions.contactResumeFollowUp));
            resumeButton.addStyleName(CssStyles.FORCE_CAPTION);
            resumeButton.setWidth(100, Unit.PERCENTAGE);
            resumeButton.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.FOLLOW_UP);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(resumeButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
        }
    }
}

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  ww  w  .  ja v  a 2  s  .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.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. ja v a 2 s  . c  o  m
    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.dashboard.DashboardFilterLayout.java

License:Open Source License

private void initializeDateFilterButton(Button button) {
    if (button != customButton) {
        button.addClickListener(e -> {
            changeDateFilterButtonsStyles(button);
        });//from w  w w . j  a v a 2 s.c  o  m
    }
    CssStyles.style(button, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER,
            CssStyles.BUTTON_FILTER_LIGHT);//, CssStyles.FORCE_CAPTION);
    dateFilterButtons.add(button);
}

From source file:de.symeda.sormas.ui.dashboard.diagram.AbstractEpiCurveComponent.java

License:Open Source License

private HorizontalLayout createHeader() {
    HorizontalLayout epiCurveHeaderLayout = new HorizontalLayout();
    epiCurveHeaderLayout.setWidth(100, Unit.PERCENTAGE);
    epiCurveHeaderLayout.setSpacing(true);
    CssStyles.style(epiCurveHeaderLayout, CssStyles.VSPACE_4);

    epiCurveLabel = new Label(I18nProperties.getString(Strings.headingEpiCurve));
    epiCurveLabel.setSizeUndefined();/*from   www.ja v a2s . c  o m*/
    CssStyles.style(epiCurveLabel, CssStyles.H2, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_NONE);

    epiCurveHeaderLayout.addComponent(epiCurveLabel);
    epiCurveHeaderLayout.setComponentAlignment(epiCurveLabel, Alignment.BOTTOM_LEFT);
    epiCurveHeaderLayout.setExpandRatio(epiCurveLabel, 1);

    // "Expand" and "Collapse" buttons
    Button expandEpiCurveButton = new Button("", VaadinIcons.EXPAND);
    CssStyles.style(expandEpiCurveButton, CssStyles.BUTTON_SUBTLE);
    expandEpiCurveButton.addStyleName(CssStyles.VSPACE_NONE);
    Button collapseEpiCurveButton = new Button("", VaadinIcons.COMPRESS);
    CssStyles.style(collapseEpiCurveButton, CssStyles.BUTTON_SUBTLE);
    collapseEpiCurveButton.addStyleName(CssStyles.VSPACE_NONE);

    expandEpiCurveButton.addClickListener(e -> {
        externalExpandListener.accept(true);
        epiCurveHeaderLayout.removeComponent(expandEpiCurveButton);
        epiCurveHeaderLayout.addComponent(collapseEpiCurveButton);
        epiCurveHeaderLayout.setComponentAlignment(collapseEpiCurveButton, Alignment.MIDDLE_RIGHT);
    });
    collapseEpiCurveButton.addClickListener(e -> {
        externalExpandListener.accept(false);
        epiCurveHeaderLayout.removeComponent(collapseEpiCurveButton);
        epiCurveHeaderLayout.addComponent(expandEpiCurveButton);
        epiCurveHeaderLayout.setComponentAlignment(expandEpiCurveButton, Alignment.MIDDLE_RIGHT);
    });
    epiCurveHeaderLayout.addComponent(expandEpiCurveButton);
    epiCurveHeaderLayout.setComponentAlignment(expandEpiCurveButton, Alignment.MIDDLE_RIGHT);

    return epiCurveHeaderLayout;
}