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

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

Introduction

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

Prototype

public void setVisible(boolean visible);

Source Link

Document

Sets the visibility of the component.

Usage

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

License:Open Source License

@Override
protected void addFields() {
    //      addField(SampleDto.SAMPLE_CODE, TextField.class);
    addField(SampleDto.LAB_SAMPLE_ID, TextField.class);
    DateTimeField sampleDateField = addField(SampleDto.SAMPLE_DATE_TIME, DateTimeField.class);
    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);// www  . ja v  a  2s  .com
    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);

    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));

    setRequired(true, SampleDto.SAMPLE_DATE_TIME, SampleDto.SAMPLE_MATERIAL, SampleDto.LAB);

    addValueChangeListener(e -> {
        CaseDataDto caze = FacadeProvider.getCaseFacade()
                .getCaseDataByUuid(getValue().getAssociatedCase().getUuid());
        if (caze.getDisease() != Disease.NEW_INFLUENCA) {
            sampleSource.setVisible(false);
        }

        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));
        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);
    });

    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());
            }
        }
    });

    lab.addValueChangeListener(e -> {
        if (e.getProperty().getValue() != null && ((FacilityReferenceDto) e.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

@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);// w  w w.j av a 2  s. 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.user.UserEditForm.java

License:Open Source License

@SuppressWarnings("unchecked")
private void updateFieldsByUserRole() {
    OptionGroup userRolesField = (OptionGroup) getFieldGroup().getField(UserDto.USER_ROLES);
    Set<UserRole> userRoles = (Set<UserRole>) userRolesField.getValue();
    boolean isInformant = UserRole.isInformant(userRoles);
    boolean isOfficer = UserRole.isOfficer(userRoles);
    boolean isSupervisor = UserRole.isSupervisor(userRoles);
    boolean isLabUser = UserRole.isLabUser(userRoles);
    boolean isPortHealthUser = UserRole.isPortHealthUser(userRoles);
    boolean isStateObserver = userRoles.contains(UserRole.STATE_OBSERVER);
    boolean isDistrictObserver = userRoles.contains(UserRole.DISTRICT_OBSERVER);

    // associated officer
    ComboBox associatedOfficer = (ComboBox) getFieldGroup().getField(UserDto.ASSOCIATED_OFFICER);
    associatedOfficer.setVisible(isInformant);
    setRequired(isInformant && !isPortHealthUser, UserDto.ASSOCIATED_OFFICER);
    if (!isInformant) {
        associatedOfficer.clear();//from w ww  .  j  a v  a 2 s .  co  m
    }

    // community
    ComboBox community = (ComboBox) getFieldGroup().getField(UserDto.COMMUNITY);
    community.setVisible(userRoles.contains(UserRole.COMMUNITY_INFORMANT));
    setRequired(userRoles.contains(UserRole.COMMUNITY_INFORMANT), UserDto.COMMUNITY);
    if (!userRoles.contains(UserRole.COMMUNITY_INFORMANT)) {
        community.clear();
    }

    // health facility
    ComboBox healthFacility = (ComboBox) getFieldGroup().getField(UserDto.HEALTH_FACILITY);
    healthFacility.setVisible(isOfficer || userRoles.contains(UserRole.HOSPITAL_INFORMANT));
    setRequired(userRoles.contains(UserRole.HOSPITAL_INFORMANT), UserDto.HEALTH_FACILITY);
    if (!healthFacility.isVisible()) {
        healthFacility.clear();
    }

    // laboratory
    ComboBox laboratory = (ComboBox) getFieldGroup().getField(UserDto.LABORATORY);
    laboratory.setVisible(isLabUser);
    setRequired(isLabUser, UserDto.LABORATORY);
    if (!isLabUser) {
        laboratory.clear();
    }

    // point of entry
    ComboBox pointOfEntry = (ComboBox) getFieldGroup().getField(UserDto.POINT_OF_ENTRY);
    boolean usePointOfEntry = isPortHealthUser && isInformant;
    pointOfEntry.setVisible(usePointOfEntry);
    setRequired(usePointOfEntry, UserDto.POINT_OF_ENTRY);
    if (!usePointOfEntry) {
        pointOfEntry.clear();
    }

    ComboBox region = (ComboBox) getFieldGroup().getField(UserDto.REGION);
    boolean useRegion = isSupervisor || isInformant || isOfficer || isStateObserver || isDistrictObserver;
    region.setVisible(useRegion);
    setRequired(useRegion, UserDto.REGION);
    if (!useRegion) {
        region.clear();
    }

    ComboBox district = (ComboBox) getFieldGroup().getField(UserDto.DISTRICT);
    boolean useDistrict = isInformant || isOfficer || isDistrictObserver;
    district.setVisible(useDistrict);
    setRequired(useDistrict, UserDto.DISTRICT);
    if (!useDistrict) {
        district.clear();
    }
}