Example usage for com.vaadin.v7.ui OptionGroup addItems

List of usage examples for com.vaadin.v7.ui OptionGroup addItems

Introduction

In this page you can find the example usage for com.vaadin.v7.ui OptionGroup addItems.

Prototype

public void addItems(Object... itemId) throws UnsupportedOperationException 

Source Link

Document

Adds given items with given item ids to container.

Usage

From source file:de.symeda.sormas.ui.dashboard.contacts.ContactsEpiCurveComponent.java

License:Open Source License

@Override
protected PopupButton createEpiCurveModeSelector() {
    if (epiCurveContactsMode == null) {
        epiCurveContactsMode = ContactsEpiCurveMode.FOLLOW_UP_STATUS;
        epiCurveLabel.setValue(epiCurveContactsMode.toString() + " Chart");
    }//from w  ww  .  j a v  a  2 s .  c o m

    PopupButton dataDropdown = new PopupButton(I18nProperties.getCaption(Captions.dashboardData));
    CssStyles.style(dataDropdown, CssStyles.BUTTON_SUBTLE);

    VerticalLayout groupingLayout = new VerticalLayout();
    groupingLayout.setMargin(true);
    groupingLayout.setSizeUndefined();
    dataDropdown.setContent(groupingLayout);

    OptionGroup dataSelect = new OptionGroup();
    dataSelect.setWidth(100, Unit.PERCENTAGE);
    dataSelect.addItems((Object[]) ContactsEpiCurveMode.values());
    dataSelect.setValue(epiCurveContactsMode);
    dataSelect.select(epiCurveContactsMode);
    dataSelect.addValueChangeListener(e -> {
        epiCurveContactsMode = (ContactsEpiCurveMode) e.getProperty().getValue();
        epiCurveLabel.setValue(epiCurveContactsMode.toString() + " Chart");
        clearAndFillEpiCurveChart();
    });
    groupingLayout.addComponent(dataSelect);

    return dataDropdown;
}

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

License:Open Source License

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

    // Grouping/*from   w  w w .  j  a  va  2  s. c o  m*/
    PopupButton groupingDropdown = new PopupButton(I18nProperties.getCaption(Captions.dashboardGrouping));
    CssStyles.style(groupingDropdown, CssStyles.BUTTON_SUBTLE);
    {
        VerticalLayout groupingLayout = new VerticalLayout();
        groupingLayout.setMargin(true);
        groupingLayout.setSizeUndefined();
        groupingDropdown.setContent(groupingLayout);

        // Grouping option group
        OptionGroup groupingSelect = new OptionGroup();
        groupingSelect.setWidth(100, Unit.PERCENTAGE);
        groupingSelect.addItems((Object[]) EpiCurveGrouping.values());
        groupingSelect.setValue(epiCurveGrouping);
        groupingSelect.addValueChangeListener(e -> {
            epiCurveGrouping = (EpiCurveGrouping) e.getProperty().getValue();
            clearAndFillEpiCurveChart();
        });
        groupingLayout.addComponent(groupingSelect);

        // "Always show at least 7 entries" checkbox
        CheckBox minimumEntriesCheckbox = new CheckBox(
                I18nProperties.getCaption(Captions.dashboardShowMinimumEntries));
        CssStyles.style(minimumEntriesCheckbox, CssStyles.VSPACE_NONE);
        minimumEntriesCheckbox.setValue(showMinimumEntries);
        minimumEntriesCheckbox.addValueChangeListener(e -> {
            showMinimumEntries = (boolean) e.getProperty().getValue();
            clearAndFillEpiCurveChart();
        });
        groupingLayout.addComponent(minimumEntriesCheckbox);

        groupingDropdown.setContent(groupingLayout);
    }
    epiCurveFooterLayout.addComponent(groupingDropdown);
    epiCurveFooterLayout.setComponentAlignment(groupingDropdown, Alignment.MIDDLE_RIGHT);
    epiCurveFooterLayout.setExpandRatio(groupingDropdown, 1);

    // Epi curve mode
    AbstractComponent epiCurveModeSelector = createEpiCurveModeSelector();
    epiCurveFooterLayout.addComponent(epiCurveModeSelector);
    epiCurveFooterLayout.setComponentAlignment(epiCurveModeSelector, Alignment.MIDDLE_RIGHT);
    epiCurveFooterLayout.setExpandRatio(epiCurveModeSelector, 0);

    return epiCurveFooterLayout;
}

From source file:de.symeda.sormas.ui.dashboard.map.DashboardMapComponent.java

License:Open Source License

private HorizontalLayout createFooter() {
    HorizontalLayout mapFooterLayout = new HorizontalLayout();
    mapFooterLayout.setWidth(100, Unit.PERCENTAGE);
    mapFooterLayout.setSpacing(true);//  www.j  a v  a 2 s  .  co m
    CssStyles.style(mapFooterLayout, CssStyles.VSPACE_4, CssStyles.VSPACE_TOP_3);

    // Map key dropdown button
    legendDropdown = new PopupButton(I18nProperties.getCaption(Captions.dashboardMapKey));
    CssStyles.style(legendDropdown, CssStyles.BUTTON_SUBTLE);
    legendDropdown.setContent(createLegend());
    mapFooterLayout.addComponent(legendDropdown);
    mapFooterLayout.setComponentAlignment(legendDropdown, Alignment.MIDDLE_RIGHT);
    mapFooterLayout.setExpandRatio(legendDropdown, 1);

    // Layers dropdown button
    PopupButton layersDropdown = new PopupButton(I18nProperties.getCaption(Captions.dashboardMapLayers));
    {
        CssStyles.style(layersDropdown, CssStyles.BUTTON_SUBTLE);

        VerticalLayout layersLayout = new VerticalLayout();
        layersLayout.setMargin(true);
        layersLayout.setSpacing(false);
        layersLayout.setSizeUndefined();
        layersDropdown.setContent(layersLayout);

        // Add check boxes and apply button
        {
            OptionGroup mapCaseDisplayModeSelect = new OptionGroup();
            mapCaseDisplayModeSelect.setWidth(100, Unit.PERCENTAGE);
            mapCaseDisplayModeSelect.addItems((Object[]) MapCaseDisplayMode.values());
            mapCaseDisplayModeSelect.setValue(mapCaseDisplayMode);
            mapCaseDisplayModeSelect.addValueChangeListener(event -> {
                mapCaseDisplayMode = (MapCaseDisplayMode) event.getProperty().getValue();
                refreshMap();
            });

            HorizontalLayout showCasesLayout = new HorizontalLayout();
            {
                showCasesLayout.setMargin(false);
                showCasesLayout.setSpacing(false);
                CheckBox showCasesCheckBox = new CheckBox();
                showCasesCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowCases));
                showCasesCheckBox.setValue(showCases);
                showCasesCheckBox.addValueChangeListener(e -> {
                    showCases = (boolean) e.getProperty().getValue();
                    mapCaseDisplayModeSelect.setEnabled(showCases);
                    mapCaseDisplayModeSelect.setValue(mapCaseDisplayMode);
                    refreshMap();
                });
                showCasesLayout.addComponent(showCasesCheckBox);

                Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
                infoLabel.setDescription(I18nProperties.getString(Strings.infoCaseMap));
                CssStyles.style(infoLabel, CssStyles.LABEL_MEDIUM, CssStyles.LABEL_SECONDARY,
                        CssStyles.HSPACE_LEFT_3);
                infoLabel.setHeightUndefined();
                showCasesLayout.addComponent(infoLabel);
                showCasesLayout.setComponentAlignment(infoLabel, Alignment.TOP_CENTER);
            }
            layersLayout.addComponent(showCasesLayout);

            layersLayout.addComponent(mapCaseDisplayModeSelect);
            mapCaseDisplayModeSelect.setEnabled(showCases);

            CheckBox showConfirmedContactsCheckBox = new CheckBox();
            CheckBox showUnconfirmedContactsCheckBox = new CheckBox();

            CheckBox showContactsCheckBox = new CheckBox();
            showContactsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowContacts));
            showContactsCheckBox.setValue(showContacts);
            showContactsCheckBox.addValueChangeListener(e -> {
                showContacts = (boolean) e.getProperty().getValue();
                showConfirmedContactsCheckBox.setEnabled(showContacts);
                showConfirmedContactsCheckBox.setValue(true);
                showUnconfirmedContactsCheckBox.setEnabled(showContacts);
                showUnconfirmedContactsCheckBox.setValue(true);
                refreshMap();
            });
            layersLayout.addComponent(showContactsCheckBox);

            showConfirmedContactsCheckBox
                    .setCaption(I18nProperties.getCaption(Captions.dashboardShowConfirmedContacts));
            showConfirmedContactsCheckBox.setValue(showConfirmedContacts);
            showConfirmedContactsCheckBox.addValueChangeListener(e -> {
                showConfirmedContacts = (boolean) e.getProperty().getValue();
                refreshMap();
            });
            layersLayout.addComponent(showConfirmedContactsCheckBox);

            CssStyles.style(showUnconfirmedContactsCheckBox, CssStyles.VSPACE_3);
            showUnconfirmedContactsCheckBox
                    .setCaption(I18nProperties.getCaption(Captions.dashboardShowUnconfirmedContacts));
            showUnconfirmedContactsCheckBox.setValue(showUnconfirmedContacts);
            showUnconfirmedContactsCheckBox.addValueChangeListener(e -> {
                showUnconfirmedContacts = (boolean) e.getProperty().getValue();
                refreshMap();
            });
            layersLayout.addComponent(showUnconfirmedContactsCheckBox);

            showConfirmedContactsCheckBox.setEnabled(showContacts);
            showUnconfirmedContactsCheckBox.setEnabled(showContacts);

            CheckBox showEventsCheckBox = new CheckBox();
            CssStyles.style(showEventsCheckBox, CssStyles.VSPACE_3);
            showEventsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowEvents));
            showEventsCheckBox.setValue(showEvents);
            showEventsCheckBox.addValueChangeListener(e -> {
                showEvents = (boolean) e.getProperty().getValue();
                refreshMap();
            });
            layersLayout.addComponent(showEventsCheckBox);

            if (UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_USER)
                    || UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_CLINICIAN)
                    || UserProvider.getCurrent().hasUserRole(UserRole.NATIONAL_OBSERVER)) {
                OptionGroup regionMapVisualizationSelect = new OptionGroup();
                regionMapVisualizationSelect.setWidth(100, Unit.PERCENTAGE);
                regionMapVisualizationSelect.addItems((Object[]) CaseMeasure.values());
                regionMapVisualizationSelect.setValue(caseMeasure);
                regionMapVisualizationSelect.addValueChangeListener(event -> {
                    caseMeasure = (CaseMeasure) event.getProperty().getValue();
                    refreshMap();
                });

                HorizontalLayout showRegionsLayout = new HorizontalLayout();
                {
                    showRegionsLayout.setMargin(false);
                    showRegionsLayout.setSpacing(false);
                    CheckBox showRegionsCheckBox = new CheckBox();
                    showRegionsCheckBox.setCaption(I18nProperties.getCaption(Captions.dashboardShowRegions));
                    showRegionsCheckBox.setValue(showRegions);
                    showRegionsCheckBox.addValueChangeListener(e -> {
                        showRegions = (boolean) e.getProperty().getValue();
                        regionMapVisualizationSelect.setEnabled(showRegions);
                        regionMapVisualizationSelect.setValue(caseMeasure);
                        refreshMap();
                    });
                    showRegionsLayout.addComponent(showRegionsCheckBox);

                    Label infoLabel = new Label(VaadinIcons.INFO_CIRCLE.getHtml(), ContentMode.HTML);
                    infoLabel.setDescription(I18nProperties.getString(Strings.infoCaseIncidence));
                    CssStyles.style(infoLabel, CssStyles.LABEL_MEDIUM, CssStyles.LABEL_SECONDARY,
                            CssStyles.HSPACE_LEFT_3);
                    infoLabel.setHeightUndefined();
                    showRegionsLayout.addComponent(infoLabel);
                    showRegionsLayout.setComponentAlignment(infoLabel, Alignment.TOP_CENTER);
                }
                layersLayout.addComponent(showRegionsLayout);
                layersLayout.addComponent(regionMapVisualizationSelect);
                regionMapVisualizationSelect.setEnabled(showRegions);
            }
        }
    }
    mapFooterLayout.addComponent(layersDropdown);
    mapFooterLayout.setComponentAlignment(layersDropdown, Alignment.MIDDLE_RIGHT);

    return mapFooterLayout;
}

From source file:de.symeda.sormas.ui.dashboard.surveillance.SurveillanceEpiCurveComponent.java

License:Open Source License

@Override
protected OptionGroup createEpiCurveModeSelector() {
    if (epiCurveSurveillanceMode == null) {
        epiCurveSurveillanceMode = SurveillanceEpiCurveMode.CASE_STATUS;
    }//w w w  . jav  a  2s  .c o  m

    OptionGroup epiCurveModeOptionGroup = new OptionGroup();
    epiCurveModeOptionGroup.setMultiSelect(false);
    CssStyles.style(epiCurveModeOptionGroup, ValoTheme.OPTIONGROUP_HORIZONTAL,
            CssStyles.OPTIONGROUP_HORIZONTAL_SUBTLE);
    epiCurveModeOptionGroup.addItems((Object[]) SurveillanceEpiCurveMode.values());
    epiCurveModeOptionGroup.setValue(epiCurveSurveillanceMode);
    epiCurveModeOptionGroup.select(epiCurveSurveillanceMode);
    epiCurveModeOptionGroup.addValueChangeListener(e -> {
        epiCurveSurveillanceMode = (SurveillanceEpiCurveMode) e.getProperty().getValue();
        clearAndFillEpiCurveChart();
    });
    return epiCurveModeOptionGroup;
}

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

License:Open Source License

private void initializeRequestedTests() {
    // Yes/No fields for requesting pathogen/additional tests
    OptionGroup pathogenTestingRequestedField = addField(SampleDto.PATHOGEN_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(pathogenTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    pathogenTestingRequestedField.setWidthUndefined();
    OptionGroup additionalTestingRequestedField = addField(SampleDto.ADDITIONAL_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(additionalTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    additionalTestingRequestedField.setWidthUndefined();

    // CheckBox groups to select the requested pathogen/additional tests
    OptionGroup requestedPathogenTestsField = addField(SampleDto.REQUESTED_PATHOGEN_TESTS, OptionGroup.class);
    CssStyles.style(requestedPathogenTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedPathogenTestsField.setMultiSelect(true);
    requestedPathogenTestsField.addItems((Object[]) PathogenTestType.values());
    requestedPathogenTestsField.removeItem(PathogenTestType.OTHER);
    requestedPathogenTestsField.setCaption(null);
    OptionGroup requestedAdditionalTestsField = addField(SampleDto.REQUESTED_ADDITIONAL_TESTS,
            OptionGroup.class);
    CssStyles.style(requestedAdditionalTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedAdditionalTestsField.setMultiSelect(true);
    requestedAdditionalTestsField.addItems((Object[]) AdditionalTestType.values());
    requestedAdditionalTestsField.setCaption(null);

    // Text fields to type in other tests
    TextField requestedOtherPathogenTests = addField(SampleDto.REQUESTED_OTHER_PATHOGEN_TESTS, TextField.class);
    TextField requestedOtherAdditionalTests = addField(SampleDto.REQUESTED_OTHER_ADDITIONAL_TESTS,
            TextField.class);

    // Information texts
    Label requestedPathogenInfoLabel = new Label(I18nProperties.getString(Strings.infoSamplePathogenTesting));
    getContent().addComponent(requestedPathogenInfoLabel, PATHOGEN_TESTING_INFO_LOC);
    Label requestedAdditionalInfoLabel = new Label(
            I18nProperties.getString(Strings.infoSampleAdditionalTesting));
    getContent().addComponent(requestedAdditionalInfoLabel, ADDITIONAL_TESTING_INFO_LOC);

    // Set initial visibility
    requestedPathogenTestsField.setVisible(false);
    requestedPathogenInfoLabel.setVisible(false);
    requestedAdditionalTestsField.setVisible(false);
    requestedAdditionalInfoLabel.setVisible(false);
    requestedOtherPathogenTests.setVisible(false);
    requestedOtherAdditionalTests.setVisible(false);

    // CheckBoxes should be hidden when no tests are requested
    pathogenTestingRequestedField.addValueChangeListener(f -> {
        requestedPathogenInfoLabel.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
        requestedPathogenTestsField.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
        requestedOtherPathogenTests.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
    });/*from   w  w w .ja  v  a 2 s  . com*/

    if (!UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)) {
        // Hide additional testing fields when user is not allowed to see them
        additionalTestingRequestedField.setVisible(false);
    } else {
        additionalTestingRequestedField.addValueChangeListener(f -> {
            requestedAdditionalInfoLabel.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
            requestedAdditionalTestsField.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
            requestedOtherAdditionalTests.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
        });
    }
}

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

License:Open Source License

private void initializeRequestedTests() {
    // Yes/No fields for requesting pathogen/additional tests
    OptionGroup pathogenTestingRequestedField = addField(SampleDto.PATHOGEN_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(pathogenTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    pathogenTestingRequestedField.setWidthUndefined();
    OptionGroup additionalTestingRequestedField = addField(SampleDto.ADDITIONAL_TESTING_REQUESTED,
            OptionGroup.class);
    CssStyles.style(additionalTestingRequestedField, CssStyles.OPTIONGROUP_CAPTION_AREA_INLINE);
    additionalTestingRequestedField.setWidthUndefined();

    // CheckBox groups to select the requested pathogen/additional tests
    OptionGroup requestedPathogenTestsField = addField(SampleDto.REQUESTED_PATHOGEN_TESTS, OptionGroup.class);
    CssStyles.style(requestedPathogenTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedPathogenTestsField.setMultiSelect(true);
    requestedPathogenTestsField.addItems((Object[]) PathogenTestType.values());
    requestedPathogenTestsField.removeItem(PathogenTestType.OTHER);
    requestedPathogenTestsField.setCaption(null);
    OptionGroup requestedAdditionalTestsField = addField(SampleDto.REQUESTED_ADDITIONAL_TESTS,
            OptionGroup.class);
    CssStyles.style(requestedAdditionalTestsField, CssStyles.OPTIONGROUP_CHECKBOXES_HORIZONTAL);
    requestedAdditionalTestsField.setMultiSelect(true);
    requestedAdditionalTestsField.addItems((Object[]) AdditionalTestType.values());
    requestedAdditionalTestsField.setCaption(null);

    // Text fields to type in other tests
    TextField requestedOtherPathogenTests = addField(SampleDto.REQUESTED_OTHER_PATHOGEN_TESTS, TextField.class);
    TextField requestedOtherAdditionalTests = addField(SampleDto.REQUESTED_OTHER_ADDITIONAL_TESTS,
            TextField.class);

    // The code below relies on getValue() to return the sample of the form and therefore has to be delayed until the sample is set
    addValueChangeListener(e -> {/*  w ww . j  a  va  2  s.  com*/
        if (!requestedTestsInitialized) {
            if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_EDIT_NOT_OWNED)
                    || UserProvider.getCurrent().getUuid().equals(getValue().getReportingUser().getUuid())) {
                // Information texts for users that can edit the requested tests
                Label requestedPathogenInfoLabel = new Label(
                        I18nProperties.getString(Strings.infoSamplePathogenTesting));
                getContent().addComponent(requestedPathogenInfoLabel, PATHOGEN_TESTING_INFO_LOC);
                Label requestedAdditionalInfoLabel = new Label(
                        I18nProperties.getString(Strings.infoSampleAdditionalTesting));
                getContent().addComponent(requestedAdditionalInfoLabel, ADDITIONAL_TESTING_INFO_LOC);

                // Set initial visibility
                requestedPathogenTestsField
                        .setVisible(Boolean.TRUE.equals(getValue().getPathogenTestingRequested()));
                requestedPathogenInfoLabel
                        .setVisible(Boolean.TRUE.equals(getValue().getPathogenTestingRequested()));
                requestedOtherPathogenTests
                        .setVisible(Boolean.TRUE.equals(getValue().getPathogenTestingRequested()));

                // CheckBoxes should be hidden when no tests are requested
                pathogenTestingRequestedField.addValueChangeListener(f -> {
                    requestedPathogenInfoLabel.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                    requestedPathogenTestsField.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                    requestedOtherPathogenTests.setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                });

                if (!UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)) {
                    // Hide additional testing fields when user is not allowed to see them
                    additionalTestingRequestedField.setVisible(false);
                    requestedAdditionalTestsField.setVisible(false);
                    requestedAdditionalInfoLabel.setVisible(false);
                    requestedOtherAdditionalTests.setVisible(false);
                } else {
                    requestedAdditionalTestsField
                            .setVisible(Boolean.TRUE.equals(getValue().getAdditionalTestingRequested()));
                    requestedAdditionalInfoLabel
                            .setVisible(Boolean.TRUE.equals(getValue().getAdditionalTestingRequested()));
                    requestedOtherAdditionalTests
                            .setVisible(Boolean.TRUE.equals(getValue().getAdditionalTestingRequested()));

                    additionalTestingRequestedField.addValueChangeListener(f -> {
                        requestedAdditionalInfoLabel
                                .setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                        requestedAdditionalTestsField
                                .setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                        requestedOtherAdditionalTests
                                .setVisible(f.getProperty().getValue().equals(Boolean.TRUE));
                    });
                }
            } else {
                // If the user can't edit the sample, they see a read-only list of requested tests
                setVisible(false, SampleDto.PATHOGEN_TESTING_REQUESTED, SampleDto.ADDITIONAL_TESTING_REQUESTED,
                        SampleDto.REQUESTED_PATHOGEN_TESTS, SampleDto.REQUESTED_ADDITIONAL_TESTS);

                // Display a label for every requested pathogen test or hide the whole section if no tests have been requested
                if (Boolean.TRUE.equals(getValue().getPathogenTestingRequested())
                        && !getValue().getRequestedPathogenTests().isEmpty()) {
                    Label pathogenTestsHeading = new Label(
                            I18nProperties.getString(Strings.headingRequestedPathogenTests));
                    CssStyles.style(pathogenTestsHeading, CssStyles.LABEL_BOLD, CssStyles.LABEL_SECONDARY,
                            CssStyles.VSPACE_4);
                    getContent().addComponent(pathogenTestsHeading, PATHOGEN_TESTING_READ_HEADLINE_LOC);

                    CssLayout requestedPathogenTestsLayout = new CssLayout();
                    CssStyles.style(requestedPathogenTestsLayout, CssStyles.VSPACE_3);
                    for (PathogenTestType testType : getValue().getRequestedPathogenTests()) {
                        Label testLabel = new Label(testType.toString());
                        testLabel.setWidthUndefined();
                        CssStyles.style(testLabel, CssStyles.LABEL_ROUNDED_CORNERS,
                                CssStyles.LABEL_BACKGROUND_FOCUS_LIGHT, CssStyles.VSPACE_4,
                                CssStyles.HSPACE_RIGHT_4);
                        requestedPathogenTestsLayout.addComponent(testLabel);
                    }
                    getContent().addComponent(requestedPathogenTestsLayout, REQUESTED_PATHOGEN_TESTS_READ_LOC);
                }

                // If the user can view additional tests, display a label for every requested additional test
                // or hide the whole section if no tests have been requested
                if (UserProvider.getCurrent().hasUserRight(UserRight.ADDITIONAL_TEST_VIEW)
                        && Boolean.TRUE.equals(getValue().getAdditionalTestingRequested())
                        && !getValue().getRequestedAdditionalTests().isEmpty()) {
                    Label additionalTestsHeading = new Label(
                            I18nProperties.getString(Strings.headingRequestedAdditionalTests));
                    CssStyles.style(additionalTestsHeading, CssStyles.LABEL_BOLD, CssStyles.LABEL_SECONDARY,
                            CssStyles.VSPACE_4);
                    getContent().addComponent(additionalTestsHeading, ADDITIONAL_TESTING_READ_HEADLINE_LOC);

                    CssLayout requestedAdditionalTestsLayout = new CssLayout();
                    CssStyles.style(requestedAdditionalTestsLayout, CssStyles.VSPACE_3);
                    for (AdditionalTestType testType : getValue().getRequestedAdditionalTests()) {
                        Label testLabel = new Label(testType.toString());
                        testLabel.setWidthUndefined();
                        CssStyles.style(testLabel, CssStyles.LABEL_ROUNDED_CORNERS,
                                CssStyles.LABEL_BACKGROUND_FOCUS_LIGHT, CssStyles.VSPACE_4,
                                CssStyles.HSPACE_RIGHT_4);
                        requestedAdditionalTestsLayout.addComponent(testLabel);
                    }
                    getContent().addComponent(requestedAdditionalTestsLayout,
                            REQUESTED_ADDITIONAL_TESTS_READ_LOC);
                }

            }
        }

        requestedTestsInitialized = true;
    });
}

From source file:de.symeda.sormas.ui.user.UserEditForm.java

License:Open Source License

@Override
protected void addFields() {

    addField(UserDto.FIRST_NAME, TextField.class);
    addField(UserDto.LAST_NAME, TextField.class);
    addField(UserDto.USER_EMAIL, TextField.class);
    TextField phone = addField(UserDto.PHONE, TextField.class);
    phone.addValidator(/*from  w  w  w .  ja  v a  2 s  . c  om*/
            new PhoneNumberValidator(I18nProperties.getValidationError(Validations.phoneNumberValidation)));
    addDiseaseField(UserDto.LIMITED_DISEASE, false);

    Label userEmailDesc = new Label(I18nProperties.getString(Strings.infoUserEmail));
    getContent().addComponent(userEmailDesc, USER_EMAIL_DESC_LOC);
    Label userPhoneDesc = new Label(I18nProperties.getString(Strings.infoUserPhoneNumber));
    getContent().addComponent(userPhoneDesc, USER_PHONE_DESC_LOC);

    addField(UserDto.ADDRESS, LocationEditForm.class).setCaption(null);

    addField(UserDto.ACTIVE, CheckBox.class);
    addField(UserDto.USER_NAME, TextField.class);
    addField(UserDto.USER_ROLES, OptionGroup.class).addValidator(new UserRolesValidator());
    OptionGroup userRoles = (OptionGroup) getFieldGroup().getField(UserDto.USER_ROLES);
    userRoles.setMultiSelect(true);
    userRoles.addItems(UserRole.getAssignableRoles(UserProvider.getCurrent().getUserRoles()));

    ComboBox region = addField(UserDto.REGION, ComboBox.class);
    ComboBox community = addField(UserDto.COMMUNITY, ComboBox.class);

    ComboBox district = addField(UserDto.DISTRICT, ComboBox.class);
    region.addValueChangeListener(e -> {
        FieldHelper.removeItems(community);
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district,
                regionDto != null ? FacadeProvider.getDistrictFacade().getAllByRegion(regionDto.getUuid())
                        : null);
    });

    // for informant
    ComboBox associatedOfficer = addField(UserDto.ASSOCIATED_OFFICER, ComboBox.class);

    ComboBox healthFacility = addField(UserDto.HEALTH_FACILITY, ComboBox.class);
    ComboBox cbPointOfEntry = addField(UserDto.POINT_OF_ENTRY, ComboBox.class);
    district.addValueChangeListener(e -> {
        FieldHelper.removeItems(healthFacility);
        FieldHelper.removeItems(associatedOfficer);
        FieldHelper.removeItems(cbPointOfEntry);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community,
                districtDto != null
                        ? FacadeProvider.getCommunityFacade().getAllByDistrict(districtDto.getUuid())
                        : null);
        FieldHelper.updateItems(healthFacility,
                districtDto != null
                        ? FacadeProvider.getFacilityFacade().getHealthFacilitiesByDistrict(districtDto, false)
                        : null);
        FieldHelper.updateItems(associatedOfficer,
                districtDto != null
                        ? FacadeProvider.getUserFacade().getUserRefsByDistrict(districtDto, false,
                                UserRole.SURVEILLANCE_OFFICER)
                        : null);
        FieldHelper.updateItems(cbPointOfEntry,
                districtDto != null
                        ? FacadeProvider.getPointOfEntryFacade().getAllByDistrict(districtDto.getUuid(), false)
                        : null);
    });

    ComboBox laboratory = addField(UserDto.LABORATORY, ComboBox.class);
    laboratory.addItems(FacadeProvider.getFacilityFacade().getAllLaboratories(false));

    region.addItems(FacadeProvider.getRegionFacade().getAllAsReference());

    setRequired(true, UserDto.FIRST_NAME, UserDto.LAST_NAME, UserDto.USER_NAME, UserDto.USER_ROLES);
    addValidators(UserDto.USER_NAME, new UserNameValidator());

    addFieldListeners(UserDto.FIRST_NAME, e -> suggestUserName());
    addFieldListeners(UserDto.LAST_NAME, e -> suggestUserName());
    addFieldListeners(UserDto.USER_ROLES, e -> updateFieldsByUserRole());
    updateFieldsByUserRole();
}