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

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

Introduction

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

Prototype

public OptionGroup(String caption) 

Source Link

Usage

From source file:de.symeda.sormas.ui.importer.ImportPersonSelectField.java

License:Open Source License

@Override
protected Component initContent() {
    if (importedCase == null || importedPerson == null) {
        return null;
    }//  w  w  w  .  j ava 2s.c o m

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeUndefined();
    layout.setWidth(100, Unit.PERCENTAGE);

    // Info label

    Label infoLabel = new Label(I18nProperties.getString(Strings.infoImportSimilarity));
    CssStyles.style(infoLabel, CssStyles.VSPACE_3);
    layout.addComponent(infoLabel);

    // Imported case info
    VerticalLayout outerCaseInfoLayout = new VerticalLayout();
    outerCaseInfoLayout.setWidth(100, Unit.PERCENTAGE);
    CssStyles.style(outerCaseInfoLayout, CssStyles.BACKGROUND_ROUNDED_CORNERS,
            CssStyles.BACKGROUND_SUB_CRITERIA, CssStyles.VSPACE_3, "v-scrollable");

    Label importedCaseLabel = new Label(I18nProperties.getString(Strings.headingImportedCaseInfo));
    CssStyles.style(importedCaseLabel, CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
    outerCaseInfoLayout.addComponent(importedCaseLabel);

    HorizontalLayout caseInfoLayout = new HorizontalLayout();
    caseInfoLayout.setSpacing(true);
    caseInfoLayout.setSizeUndefined();
    {
        Label diseaseField = new Label();
        diseaseField.setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISEASE));
        diseaseField
                .setValue(DiseaseHelper.toString(importedCase.getDisease(), importedCase.getDiseaseDetails()));
        diseaseField.setWidthUndefined();
        caseInfoLayout.addComponent(diseaseField);

        Label caseDateField = new Label();
        if (importedCase.getSymptoms().getOnsetDate() != null) {
            caseDateField.setCaption(
                    I18nProperties.getPrefixCaption(SymptomsDto.I18N_PREFIX, SymptomsDto.ONSET_DATE));
            caseDateField.setValue(DateHelper.formatLocalShortDate(importedCase.getSymptoms().getOnsetDate()));
        } else {
            caseDateField.setCaption(
                    I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REPORT_DATE));
            caseDateField.setValue(DateHelper.formatLocalShortDate(importedCase.getReportDate()));
        }
        caseDateField.setWidthUndefined();
        caseInfoLayout.addComponent(caseDateField);

        Label regionField = new Label();
        regionField.setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.REGION));
        regionField.setValue(importedCase.getRegion().toString());
        regionField.setWidthUndefined();
        caseInfoLayout.addComponent(regionField);

        Label districtField = new Label();
        districtField
                .setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.DISTRICT));
        districtField.setValue(importedCase.getDistrict().toString());
        districtField.setWidthUndefined();
        caseInfoLayout.addComponent(districtField);

        Label communityField = new Label();
        communityField
                .setCaption(I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.COMMUNITY));
        communityField
                .setValue(importedCase.getCommunity() != null ? importedCase.getCommunity().toString() : "");
        communityField.setWidthUndefined();
        caseInfoLayout.addComponent(communityField);

        Label facilityField = new Label();
        facilityField.setCaption(
                I18nProperties.getPrefixCaption(CaseDataDto.I18N_PREFIX, CaseDataDto.HEALTH_FACILITY));
        facilityField.setValue(FacilityHelper.buildFacilityString(null,
                importedCase.getHealthFacility() != null ? importedCase.getHealthFacility().toString() : "",
                importedCase.getHealthFacilityDetails()));
        facilityField.setWidthUndefined();
        caseInfoLayout.addComponent(facilityField);
    }

    outerCaseInfoLayout.addComponent(caseInfoLayout);
    layout.addComponent(outerCaseInfoLayout);

    // Imported person info
    VerticalLayout outerPersonInfoLayout = new VerticalLayout();
    outerPersonInfoLayout.setWidth(100, Unit.PERCENTAGE);
    CssStyles.style(outerPersonInfoLayout, CssStyles.BACKGROUND_ROUNDED_CORNERS,
            CssStyles.BACKGROUND_SUB_CRITERIA, CssStyles.VSPACE_3, "v-scrollable");

    Label importedPersonLabel = new Label(I18nProperties.getString(Strings.headingImportedPersonInfo));
    CssStyles.style(importedPersonLabel, CssStyles.LABEL_BOLD, CssStyles.VSPACE_4);
    outerPersonInfoLayout.addComponent(importedPersonLabel);

    HorizontalLayout personInfoLayout = new HorizontalLayout();
    personInfoLayout.setSpacing(true);
    personInfoLayout.setSizeUndefined();
    {
        Label firstNameField = new Label();
        firstNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.FIRST_NAME));
        firstNameField.setValue(importedPerson.getFirstName());
        firstNameField.setWidthUndefined();
        personInfoLayout.addComponent(firstNameField);

        Label lastNameField = new Label();
        lastNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.LAST_NAME));
        lastNameField.setValue(importedPerson.getLastName());
        lastNameField.setWidthUndefined();
        personInfoLayout.addComponent(lastNameField);

        Label nicknameField = new Label();
        nicknameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.NICKNAME));
        nicknameField.setValue(importedPerson.getNickname());
        nicknameField.setWidthUndefined();
        personInfoLayout.addComponent(nicknameField);

        Label ageField = new Label();
        ageField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.APPROXIMATE_AGE));
        ageField.setValue(ApproximateAgeHelper.formatApproximateAge(importedPerson.getApproximateAge(),
                importedPerson.getApproximateAgeType()));
        ageField.setWidthUndefined();
        personInfoLayout.addComponent(ageField);

        Label sexField = new Label();
        sexField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.SEX));
        sexField.setValue(importedPerson.getSex() != null ? importedPerson.getSex().toString() : "");
        sexField.setWidthUndefined();
        personInfoLayout.addComponent(sexField);

        Label presentConditionField = new Label();
        presentConditionField.setCaption(
                I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.PRESENT_CONDITION));
        presentConditionField.setValue(
                importedPerson.getPresentCondition() != null ? importedPerson.getPresentCondition().toString()
                        : null);
        presentConditionField.setWidthUndefined();
        personInfoLayout.addComponent(presentConditionField);

        Label regionField = new Label();
        regionField.setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.REGION));
        regionField.setValue(importedPerson.getAddress().getRegion() != null
                ? importedPerson.getAddress().getRegion().toString()
                : "");
        regionField.setWidthUndefined();
        personInfoLayout.addComponent(regionField);

        Label districtField = new Label();
        districtField
                .setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.DISTRICT));
        districtField.setValue(importedPerson.getAddress().getDistrict() != null
                ? importedPerson.getAddress().getDistrict().toString()
                : "");
        districtField.setWidthUndefined();
        personInfoLayout.addComponent(districtField);

        Label communityField = new Label();
        communityField
                .setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.COMMUNITY));
        communityField.setValue(importedPerson.getAddress().getCommunity() != null
                ? importedPerson.getAddress().getCommunity().toString()
                : "");
        communityField.setWidthUndefined();
        personInfoLayout.addComponent(communityField);

        Label cityField = new Label();
        cityField.setCaption(I18nProperties.getPrefixCaption(LocationDto.I18N_PREFIX, LocationDto.CITY));
        cityField.setValue(importedPerson.getAddress().getCity());
        cityField.setWidthUndefined();
        personInfoLayout.addComponent(cityField);
    }

    outerPersonInfoLayout.addComponent(personInfoLayout);
    layout.addComponent(outerPersonInfoLayout);

    // Person selection/creation
    selectPerson = new OptionGroup(null);
    selectPerson.addItem(SELECT_PERSON);
    selectPerson.setItemCaption(SELECT_PERSON, I18nProperties.getCaption(Captions.personSelect));
    CssStyles.style(selectPerson, CssStyles.VSPACE_NONE);
    selectPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            createNewPerson.setValue(null);
            personGrid.setEnabled(true);
            mergeCheckBox.setEnabled(true);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(personGrid.getSelectedRow() != null);
            }
        }
    });
    layout.addComponent(selectPerson);

    mergeCheckBox = new CheckBox();
    mergeCheckBox.setCaption(I18nProperties.getCaption(Captions.caseImportMergeCase));
    CssStyles.style(mergeCheckBox, CssStyles.VSPACE_3);
    layout.addComponent(mergeCheckBox);

    initPersonGrid();
    // Deselect "create new" when person is selected
    personGrid.addSelectionListener(e -> {
        if (e.getSelected().size() > 0) {
            createNewPerson.setValue(null);
        }
    });
    CssStyles.style(personGrid, CssStyles.VSPACE_3);
    layout.addComponent(personGrid);

    personGrid.addSelectionListener(e -> {
        if (selectionChangeCallback != null) {
            selectionChangeCallback.accept(!e.getSelected().isEmpty());
        }
    });

    createNewPerson = new OptionGroup(null);
    createNewPerson.addItem(CREATE_PERSON);
    createNewPerson.setItemCaption(CREATE_PERSON, I18nProperties.getCaption(Captions.personCreateNew));
    // Deselect grid when "create new" is selected
    createNewPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            selectPerson.setValue(null);
            personGrid.select(null);
            personGrid.setEnabled(false);
            mergeCheckBox.setEnabled(false);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(true);
            }
        }
    });
    layout.addComponent(createNewPerson);

    // Set field values based on internal value
    setInternalValue(super.getInternalValue());

    return layout;
}

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

License:Open Source License

@Override
protected Component initContent() {
    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);/*from ww  w . j  av  a2 s . c  om*/
    layout.setSizeUndefined();
    layout.setWidth(100, Unit.PERCENTAGE);

    HorizontalLayout nameLayout = new HorizontalLayout();
    nameLayout.setSpacing(true);
    nameLayout.setWidth(100, Unit.PERCENTAGE);

    firstNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.FIRST_NAME));
    firstNameField.setWidth(100, Unit.PERCENTAGE);
    firstNameField.setRequired(true);
    nameLayout.addComponent(firstNameField);

    lastNameField.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.LAST_NAME));
    lastNameField.setWidth(100, Unit.PERCENTAGE);
    lastNameField.setRequired(true);
    nameLayout.addComponent(lastNameField);

    CssStyles.style(searchMatchesButton, CssStyles.FORCE_CAPTION, ValoTheme.BUTTON_PRIMARY);
    searchMatchesButton.addClickListener(e -> {
        personGrid.reload(firstNameField.getValue(), lastNameField.getValue());
        selectBestMatch();
    });
    nameLayout.addComponent(searchMatchesButton);

    layout.addComponent(nameLayout);

    selectPerson = new OptionGroup(null);
    selectPerson.addItem(SELECT_PERSON);
    selectPerson.setItemCaption(SELECT_PERSON, I18nProperties.getCaption(Captions.personSelect));
    CssStyles.style(selectPerson, CssStyles.VSPACE_NONE);
    selectPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            createNewPerson.setValue(null);
            personGrid.setEnabled(true);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(personGrid.getSelectedRow() != null);
            }
        }
    });
    layout.addComponent(selectPerson);

    initPersonGrid();
    // unselect "create new" when person is selected
    personGrid.addSelectionListener(e -> {
        if (e.getSelected().size() > 0) {
            createNewPerson.setValue(null);
        }
    });
    layout.addComponent(personGrid);

    personGrid.addSelectionListener(e -> {
        if (selectionChangeCallback != null) {
            selectionChangeCallback.accept(!e.getSelected().isEmpty());
        }
    });

    createNewPerson = new OptionGroup(null);
    createNewPerson.addItem(CREATE_PERSON);
    createNewPerson.setItemCaption(CREATE_PERSON, I18nProperties.getCaption(Captions.personCreateNew));
    // unselect grid when "create new" is selected
    createNewPerson.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null) {
            selectPerson.setValue(null);
            personGrid.select(null);
            personGrid.setEnabled(false);
            if (selectionChangeCallback != null) {
                selectionChangeCallback.accept(true);
            }
        }
    });
    layout.addComponent(createNewPerson);

    // set field values based on internal value
    setInternalValue(super.getInternalValue());

    return layout;
}