Example usage for com.vaadin.v7.ui ComboBox setEnabled

List of usage examples for com.vaadin.v7.ui ComboBox setEnabled

Introduction

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

Prototype

public void setEnabled(boolean enabled);

Source Link

Document

Enables or disables the component.

Usage

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

License:Open Source License

@Override
protected void addFields() {
    if (!initialized) {
        return;//from w ww  .  j  av  a2s .  c o m
    }

    classificationCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkCaseClassification));
    getContent().addComponent(classificationCheckBox, CLASSIFICATION_CHECKBOX);
    investigationStatusCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkInvestigationStatus));
    getContent().addComponent(investigationStatusCheckBox, INVESTIGATION_STATUS_CHECKBOX);
    outcomeCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkCaseOutcome));
    getContent().addComponent(outcomeCheckBox, OUTCOME_CHECKBOX);
    OptionGroup caseClassification = addField(CaseDataDto.CASE_CLASSIFICATION, OptionGroup.class);
    caseClassification.setEnabled(false);
    OptionGroup investigationStatus = addField(CaseDataDto.INVESTIGATION_STATUS, OptionGroup.class);
    investigationStatus.setEnabled(false);
    OptionGroup outcome = addField(CaseDataDto.OUTCOME, OptionGroup.class);
    outcome.setEnabled(false);

    if (singleSelectedDistrict != null) {
        surveillanceOfficerCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkSurveillanceOfficer));
        getContent().addComponent(surveillanceOfficerCheckBox, SURVEILLANCE_OFFICER_CHECKBOX);
        ComboBox surveillanceOfficer = addField(CaseDataDto.SURVEILLANCE_OFFICER, ComboBox.class);
        surveillanceOfficer.setEnabled(false);
        FieldHelper.addSoftRequiredStyleWhen(getFieldGroup(), surveillanceOfficerCheckBox,
                Arrays.asList(CaseDataDto.SURVEILLANCE_OFFICER), Arrays.asList(true), null);
        List<UserReferenceDto> assignableSurveillanceOfficers = FacadeProvider.getUserFacade()
                .getUserRefsByDistrict(singleSelectedDistrict, false, UserRole.SURVEILLANCE_OFFICER);
        FieldHelper.updateItems(surveillanceOfficer, assignableSurveillanceOfficers);

        surveillanceOfficerCheckBox.addValueChangeListener(e -> {
            surveillanceOfficer.setEnabled((boolean) e.getProperty().getValue());
        });
    }

    FieldHelper.setRequiredWhen(getFieldGroup(), classificationCheckBox,
            Arrays.asList(CaseDataDto.CASE_CLASSIFICATION), Arrays.asList(true));
    FieldHelper.setRequiredWhen(getFieldGroup(), investigationStatusCheckBox,
            Arrays.asList(CaseDataDto.INVESTIGATION_STATUS), Arrays.asList(true));
    FieldHelper.setRequiredWhen(getFieldGroup(), outcomeCheckBox, Arrays.asList(CaseDataDto.OUTCOME),
            Arrays.asList(true));

    classificationCheckBox.addValueChangeListener(e -> {
        caseClassification.setEnabled((boolean) e.getProperty().getValue());
    });
    investigationStatusCheckBox.addValueChangeListener(e -> {
        investigationStatus.setEnabled((boolean) e.getProperty().getValue());
    });
    outcomeCheckBox.addValueChangeListener(e -> {
        outcome.setEnabled((boolean) e.getProperty().getValue());
    });
}

From source file:de.symeda.sormas.ui.configuration.infrastructure.CommunityEditForm.java

License:Open Source License

@Override
protected void addFields() {
    addField(CommunityDto.NAME, TextField.class);
    ComboBox region = new ComboBox();
    region.setCaption(I18nProperties.getPrefixCaption(CommunityDto.I18N_PREFIX, REGION_LOC));
    region.setWidth(100, Unit.PERCENTAGE);
    getContent().addComponent(region, REGION_LOC);
    ComboBox district = addField(CommunityDto.DISTRICT, ComboBox.class);

    setRequired(true, CommunityDto.NAME, CommunityDto.DISTRICT);
    region.setRequired(true);//from  w w w .  j  av a  2s  .  c o  m

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

    district.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null && region.getValue() == null) {
            DistrictDto communityDistrict = FacadeProvider.getDistrictFacade()
                    .getDistrictByUuid(((DistrictReferenceDto) e.getProperty().getValue()).getUuid());
            region.setValue(communityDistrict.getRegion());
        }
    });

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

    // TODO: Workaround until cases and other data is properly transfered when infrastructure data changes
    if (!create) {
        region.setEnabled(false);
        district.setEnabled(false);
    }
}

From source file:de.symeda.sormas.ui.configuration.infrastructure.DistrictEditForm.java

License:Open Source License

@Override
protected void addFields() {
    addField(DistrictDto.NAME, TextField.class);
    addField(DistrictDto.EPID_CODE, TextField.class);
    ComboBox region = addField(DistrictDto.REGION, ComboBox.class);
    TextField population = addField(DistrictDto.POPULATION, TextField.class);
    population.setConverter(new StringToIntegerConverter());
    population.setConversionError(/*from w ww  .  ja  v  a  2s .com*/
            I18nProperties.getValidationError(Validations.onlyNumbersAllowed, population.getCaption()));
    TextField growthRate = addField(DistrictDto.GROWTH_RATE, TextField.class);
    growthRate.setConverter(new StringToFloatConverter());
    growthRate.setConversionError(
            I18nProperties.getValidationError(Validations.onlyDecimalNumbersAllowed, growthRate.getCaption()));

    setRequired(true, DistrictDto.NAME, DistrictDto.EPID_CODE, DistrictDto.REGION);

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

    // TODO: Workaround until cases and other data is properly transfered when infrastructure data changes
    if (!create) {
        region.setEnabled(false);
    }
}

From source file:de.symeda.sormas.ui.configuration.infrastructure.FacilityEditForm.java

License:Open Source License

@Override
protected void addFields() {
    TextField name = addField(FacilityDto.NAME, TextField.class);
    ComboBox region = addField(FacilityDto.REGION, ComboBox.class);
    ComboBox district = addField(FacilityDto.DISTRICT, ComboBox.class);
    ComboBox community = addField(FacilityDto.COMMUNITY, ComboBox.class);
    addField(FacilityDto.CITY, TextField.class);
    TextField latitude = addField(FacilityDto.LATITUDE, TextField.class);
    latitude.setConverter(new StringToAngularLocationConverter());
    latitude.setConversionError(/*from   ww w .  ja  va  2  s. co  m*/
            I18nProperties.getValidationError(Validations.onlyGeoCoordinatesAllowed, latitude.getCaption()));
    TextField longitude = addField(FacilityDto.LONGITUDE, TextField.class);
    longitude.setConverter(new StringToAngularLocationConverter());
    longitude.setConversionError(
            I18nProperties.getValidationError(Validations.onlyGeoCoordinatesAllowed, longitude.getCaption()));

    name.setRequired(true);
    if (!laboratory) {
        region.setRequired(true);
        district.setRequired(true);
        community.setRequired(true);
    }

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

    district.addValueChangeListener(e -> {
        FieldHelper.removeItems(community);
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community,
                districtDto != null
                        ? FacadeProvider.getCommunityFacade().getAllByDistrict(districtDto.getUuid())
                        : null);
    });

    community.addValueChangeListener(e -> {
        @SuppressWarnings("unused")
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
    });
    region.addItems(FacadeProvider.getRegionFacade().getAllAsReference());

    if (!create) {
        if (!laboratory) {
            // Disable editing of region, etc. so case references stay correct
            region.setEnabled(false);
            district.setEnabled(false);
            community.setEnabled(false);
        }
    }
}

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

License:Open Source License

@Override
protected void addFields() {
    if (!initialized) {
        return;//from  ww  w.  ja v a2  s. co m
    }

    classificationCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkContactClassification));
    getContent().addComponent(classificationCheckBox, CLASSIFICATION_CHECKBOX);
    OptionGroup contactClassification = addField(ContactDto.CONTACT_CLASSIFICATION, OptionGroup.class);
    contactClassification.setEnabled(false);

    if (singleSelectedDistrict != null) {
        contactOfficerCheckBox = new CheckBox(I18nProperties.getCaption(Captions.bulkContactOfficer));
        getContent().addComponent(contactOfficerCheckBox, CONTACT_OFFICER_CHECKBOX);
        ComboBox contactOfficer = addField(ContactDto.CONTACT_OFFICER, ComboBox.class);
        contactOfficer.setEnabled(false);
        FieldHelper.addSoftRequiredStyleWhen(getFieldGroup(), contactOfficerCheckBox,
                Arrays.asList(ContactDto.CONTACT_OFFICER), Arrays.asList(true), null);
        List<UserReferenceDto> assignableContactOfficers = FacadeProvider.getUserFacade()
                .getUserRefsByDistrict(singleSelectedDistrict, false, UserRole.CONTACT_OFFICER);
        FieldHelper.updateItems(contactOfficer, assignableContactOfficers);

        contactOfficerCheckBox.addValueChangeListener(e -> {
            contactOfficer.setEnabled((boolean) e.getProperty().getValue());
        });
    }

    FieldHelper.setRequiredWhen(getFieldGroup(), classificationCheckBox,
            Arrays.asList(ContactDto.CONTACT_CLASSIFICATION), Arrays.asList(true));

    classificationCheckBox.addValueChangeListener(e -> {
        contactClassification.setEnabled((boolean) e.getProperty().getValue());
    });
}

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

License:Open Source License

@Override
protected void addFields() {
    addField(SampleDto.LAB_SAMPLE_ID, TextField.class);
    DateTimeField sampleDateField = addField(SampleDto.SAMPLE_DATE_TIME, DateTimeField.class);
    sampleDateField.setInvalidCommitted(false);
    addField(SampleDto.SAMPLE_MATERIAL, ComboBox.class);
    addField(SampleDto.SAMPLE_MATERIAL_TEXT, TextField.class);
    ComboBox sampleSource = addField(SampleDto.SAMPLE_SOURCE, ComboBox.class);
    DateField shipmentDate = addDateField(SampleDto.SHIPMENT_DATE, DateField.class, 7);
    addField(SampleDto.SHIPMENT_DETAILS, TextField.class);
    DateField receivedDate = addField(SampleDto.RECEIVED_DATE, DateField.class);
    ComboBox lab = addField(SampleDto.LAB, ComboBox.class);
    lab.addItems(FacadeProvider.getFacilityFacade().getAllLaboratories(true));
    TextField labDetails = addField(SampleDto.LAB_DETAILS, TextField.class);
    labDetails.setVisible(false);//from   w w  w  .j a v  a 2s.  c o  m
    addField(SampleDto.SPECIMEN_CONDITION, ComboBox.class);
    addField(SampleDto.NO_TEST_POSSIBLE_REASON, TextField.class);
    addField(SampleDto.COMMENT, TextArea.class).setRows(2);
    CheckBox shipped = addField(SampleDto.SHIPPED, CheckBox.class);
    CheckBox received = addField(SampleDto.RECEIVED, CheckBox.class);
    ComboBox pathogenTestResultField = addField(SampleDto.PATHOGEN_TEST_RESULT, ComboBox.class);

    initializeRequestedTests();

    // Validators
    sampleDateField.addValidator(new DateComparisonValidator(sampleDateField, shipmentDate, true, false,
            I18nProperties.getValidationError(Validations.beforeDate, sampleDateField.getCaption(),
                    shipmentDate.getCaption())));
    sampleDateField.addValidator(new DateComparisonValidator(sampleDateField, receivedDate, true, false,
            I18nProperties.getValidationError(Validations.beforeDate, sampleDateField.getCaption(),
                    receivedDate.getCaption())));
    shipmentDate.addValidator(new DateComparisonValidator(shipmentDate, sampleDateField, false, false,
            I18nProperties.getValidationError(Validations.afterDate, shipmentDate.getCaption(),
                    sampleDateField.getCaption())));
    shipmentDate.addValidator(new DateComparisonValidator(shipmentDate, receivedDate, true, false,
            I18nProperties.getValidationError(Validations.beforeDate, shipmentDate.getCaption(),
                    receivedDate.getCaption())));
    receivedDate.addValidator(new DateComparisonValidator(receivedDate, sampleDateField, false, false,
            I18nProperties.getValidationError(Validations.afterDate, receivedDate.getCaption(),
                    sampleDateField.getCaption())));
    receivedDate.addValidator(new DateComparisonValidator(receivedDate, shipmentDate, false, false,
            I18nProperties.getValidationError(Validations.afterDate, receivedDate.getCaption(),
                    shipmentDate.getCaption())));

    FieldHelper.setVisibleWhen(getFieldGroup(), SampleDto.SAMPLE_MATERIAL_TEXT, SampleDto.SAMPLE_MATERIAL,
            Arrays.asList(SampleMaterial.OTHER), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), SampleDto.NO_TEST_POSSIBLE_REASON, SampleDto.SPECIMEN_CONDITION,
            Arrays.asList(SpecimenCondition.NOT_ADEQUATE), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), SampleDto.SAMPLE_MATERIAL,
            Arrays.asList(SampleDto.SAMPLE_MATERIAL_TEXT), Arrays.asList(SampleMaterial.OTHER));
    FieldHelper.setRequiredWhen(getFieldGroup(), SampleDto.SPECIMEN_CONDITION,
            Arrays.asList(SampleDto.NO_TEST_POSSIBLE_REASON), Arrays.asList(SpecimenCondition.NOT_ADEQUATE));

    addValueChangeListener(e -> {
        CaseDataDto caze = FacadeProvider.getCaseFacade()
                .getCaseDataByUuid(getValue().getAssociatedCase().getUuid());

        FieldHelper.setRequiredWhen(getFieldGroup(), received,
                Arrays.asList(SampleDto.RECEIVED_DATE, SampleDto.SPECIMEN_CONDITION), Arrays.asList(true));
        FieldHelper.setEnabledWhen(getFieldGroup(), received, Arrays.asList(true),
                Arrays.asList(SampleDto.RECEIVED_DATE, SampleDto.LAB_SAMPLE_ID, SampleDto.SPECIMEN_CONDITION,
                        SampleDto.NO_TEST_POSSIBLE_REASON),
                true);

        if (caze.getDisease() != Disease.NEW_INFLUENCA) {
            sampleSource.setVisible(false);
        }

        if (UserProvider.getCurrent().hasUserRight(UserRight.SAMPLE_EDIT_NOT_OWNED)
                || UserProvider.getCurrent().getUuid().equals(getValue().getReportingUser().getUuid())) {
            FieldHelper.setEnabledWhen(getFieldGroup(), shipped, Arrays.asList(true),
                    Arrays.asList(SampleDto.SHIPMENT_DATE, SampleDto.SHIPMENT_DETAILS), true);
            FieldHelper.setRequiredWhen(getFieldGroup(), shipped, Arrays.asList(SampleDto.SHIPMENT_DATE),
                    Arrays.asList(true));
            setRequired(true, SampleDto.SAMPLE_DATE_TIME, SampleDto.SAMPLE_MATERIAL, SampleDto.LAB);
        } else {
            getField(SampleDto.SAMPLE_DATE_TIME).setEnabled(false);
            getField(SampleDto.SAMPLE_MATERIAL).setEnabled(false);
            getField(SampleDto.SAMPLE_MATERIAL_TEXT).setEnabled(false);
            getField(SampleDto.LAB).setEnabled(false);
            getField(SampleDto.SHIPPED).setEnabled(false);
            getField(SampleDto.SHIPMENT_DATE).setEnabled(false);
            getField(SampleDto.SHIPMENT_DETAILS).setEnabled(false);
            getField(SampleDto.SAMPLE_SOURCE).setEnabled(false);
        }

        shipped.addValueChangeListener(event -> {
            if ((boolean) event.getProperty().getValue() == true) {
                if (shipmentDate.getValue() == null) {
                    shipmentDate.setValue(new Date());
                }
            }
        });

        received.addValueChangeListener(event -> {
            if ((boolean) event.getProperty().getValue() == true) {
                if (receivedDate.getValue() == null) {
                    receivedDate.setValue(new Date());
                }
            }
        });

        // Initialize referral and report information
        VerticalLayout reportInfoLayout = new VerticalLayout();

        String reportInfoText = I18nProperties.getString(Strings.reportedOn) + " "
                + DateHelper.formatLocalDateTime(getValue().getReportDateTime()) + " "
                + I18nProperties.getString(Strings.by) + " " + getValue().getReportingUser().toString();
        Label reportInfoLabel = new Label(reportInfoText);
        reportInfoLabel.setEnabled(false);
        reportInfoLayout.addComponent(reportInfoLabel);

        SampleReferenceDto referredFromRef = FacadeProvider.getSampleFacade()
                .getReferredFrom(getValue().getUuid());
        if (referredFromRef != null) {
            SampleDto referredFrom = FacadeProvider.getSampleFacade()
                    .getSampleByUuid(referredFromRef.getUuid());
            Button referredButton = new Button(I18nProperties.getCaption(Captions.sampleReferredFrom) + " "
                    + referredFrom.getLab().toString());
            referredButton.addStyleName(ValoTheme.BUTTON_LINK);
            referredButton.addStyleName(CssStyles.VSPACE_NONE);
            referredButton.addClickListener(
                    s -> ControllerProvider.getSampleController().navigateToData(referredFrom.getUuid()));
            reportInfoLayout.addComponent(referredButton);
        }

        getContent().addComponent(reportInfoLayout, REPORT_INFORMATION_LOC);

        if (FacadeProvider.getPathogenTestFacade().hasPathogenTest(getValue().toReference())) {
            pathogenTestResultField.setRequired(true);
        } else {
            pathogenTestResultField.setEnabled(false);
        }
    });

    lab.addValueChangeListener(event -> {
        if (event.getProperty().getValue() != null && ((FacilityReferenceDto) event.getProperty().getValue())
                .getUuid().equals(FacilityDto.OTHER_LABORATORY_UUID)) {
            labDetails.setVisible(true);
            labDetails.setRequired(true);
        } else {
            labDetails.setVisible(false);
            labDetails.setRequired(false);
            labDetails.clear();
        }
    });
}

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

License:Open Source License

public void makePathogenTestResultRequired() {
    ComboBox pathogenTestResultField = (ComboBox) getFieldGroup().getField(SampleDto.PATHOGEN_TEST_RESULT);
    pathogenTestResultField.setEnabled(true);
    pathogenTestResultField.setRequired(true);

    if (pathogenTestResultField.getValue() == null) {
        pathogenTestResultField.setValue(PathogenTestResultType.PENDING);
    }//from www  . ja v  a  2s  .  c  o  m
}

From source file:de.symeda.sormas.ui.symptoms.SymptomsForm.java

License:Open Source License

@SuppressWarnings("rawtypes")
private void addListenerForOnsetFields(ComboBox onsetSymptom, DateField onsetDateField) {
    List<String> allPropertyIds = Stream
            .concat(unconditionalSymptomFieldIds.stream(), conditionalBleedingSymptomFieldIds.stream())
            .collect(Collectors.toList());
    allPropertyIds.add(SymptomsDto.LESIONS_THAT_ITCH);

    for (Object sourcePropertyId : allPropertyIds) {
        Field sourceField = getFieldGroup().getField(sourcePropertyId);
        sourceField.addValueChangeListener(event -> {
            if (sourceField.getValue() == SymptomState.YES) {
                onsetSymptom.addItem(sourceField.getCaption());
                onsetDateField.setEnabled(true);
            } else {
                onsetSymptom.removeItem(sourceField.getCaption());
                onsetDateField.setEnabled(
                        isAnySymptomSetToYes(getFieldGroup(), allPropertyIds, Arrays.asList(SymptomState.YES)));
            }// www  .j a  v  a 2s .co m
            onsetSymptom.setEnabled(!onsetSymptom.getItemIds().isEmpty());
        });
    }
    onsetSymptom.setEnabled(false); // will be updated by listener if needed
    onsetDateField.setEnabled(false); // will be updated by listener if needed
}