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

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

Introduction

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

Prototype

public void setItemCaptionMode(ItemCaptionMode mode) 

Source Link

Document

Sets the item caption mode.

Usage

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

License:Open Source License

@Override
protected void addFields() {
    if (!initialized) {
        // vars have to be set first
        return;/* www.  java  2  s .  co m*/
    }

    addField(PersonDto.FIRST_NAME, TextField.class);
    addField(PersonDto.LAST_NAME, TextField.class);
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.NICKNAME, TextField.class);
    addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
    addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
    ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
    birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
    TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
    ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
    addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);

    TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
    tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyNumbersAllowed,
            tfGestationAgeAtBirth.getCaption()));
    TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
    tfBirthWeight.setConversionError(
            I18nProperties.getValidationError(Validations.onlyNumbersAllowed, tfBirthWeight.getCaption()));

    AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
    deathPlaceType.setNullSelectionAllowed(true);
    TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
    DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
    TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
    ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
    addField(PersonDto.ADDRESS, LocationEditForm.class).setCaption(null);
    addField(PersonDto.PHONE, TextField.class);
    addField(PersonDto.PHONE_OWNER, TextField.class);

    addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.EDUCATION_TYPE,
            PersonDto.EDUCATION_DETAILS);

    ComboBox cbPlaceOfBirthRegion = addField(PersonDto.PLACE_OF_BIRTH_REGION, ComboBox.class);
    ComboBox cbPlaceOfBirthDistrict = addField(PersonDto.PLACE_OF_BIRTH_DISTRICT, ComboBox.class);
    ComboBox cbPlaceOfBirthCommunity = addField(PersonDto.PLACE_OF_BIRTH_COMMUNITY, ComboBox.class);
    ComboBox cbPlaceOfBirthFacility = addField(PersonDto.PLACE_OF_BIRTH_FACILITY, ComboBox.class);
    TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS,
            TextField.class);

    causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
    causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
    causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
    ComboBox facilityRegion = addField(PersonDto.OCCUPATION_REGION, ComboBox.class);
    facilityRegion.setImmediate(true);
    facilityRegion.setNullSelectionAllowed(true);
    ComboBox facilityDistrict = addField(PersonDto.OCCUPATION_DISTRICT, ComboBox.class);
    facilityDistrict.setImmediate(true);
    facilityDistrict.setNullSelectionAllowed(true);
    ComboBox facilityCommunity = addField(PersonDto.OCCUPATION_COMMUNITY, ComboBox.class);
    facilityCommunity.setImmediate(true);
    facilityCommunity.setNullSelectionAllowed(true);
    occupationFacility = addField(PersonDto.OCCUPATION_FACILITY, ComboBox.class);
    occupationFacility.setImmediate(true);
    occupationFacility.setNullSelectionAllowed(true);
    occupationFacilityDetails = addField(PersonDto.OCCUPATION_FACILITY_DETAILS, TextField.class);

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

    setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
    setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME);
    setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.OCCUPATION_FACILITY,
            PersonDto.OCCUPATION_FACILITY_DETAILS, PersonDto.OCCUPATION_REGION, PersonDto.OCCUPATION_DISTRICT,
            PersonDto.OCCUPATION_COMMUNITY, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE,
            PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION,
            PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS,
            PersonDto.CAUSE_OF_DEATH_DISEASE);

    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE,
            Arrays.asList(EducationType.OTHER), true);

    FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType,
            causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc,
            burialConductor);

    // Set initial visibilities

    initializeVisibilitiesAndAllowedVisibilities(disease, viewMode);

    if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
        occupationHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESS).isVisible())
        addressHeader.setVisible(false);

    // Add listeners

    FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE,
            PersonDto.APPROXIMATE_AGE_TYPE);
    addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
        @SuppressWarnings("unchecked")
        Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(
                PersonDto.APPROXIMATE_AGE_TYPE);
        if (e.getProperty().getValue() == null) {
            ageTypeField.clear();
        } else {
            if (ageTypeField.isEmpty()) {
                ageTypeField.setValue(ApproximateAgeType.YEARS);
            }
        }
    });

    addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });

    addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });

    addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });

    addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
    addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
        updateOccupationFieldCaptions();
        toogleOccupationMetaFields();
    });

    addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity,
            cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails);
    addListenersToInfrastructureFields(facilityRegion, facilityDistrict, facilityCommunity, occupationFacility,
            occupationFacilityDetails);
    cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllAsReference());
    facilityRegion.addItems(FacadeProvider.getRegionFacade().getAllAsReference());

    addFieldListeners(PersonDto.PRESENT_CONDITION, e -> toogleDeathAndBurialFields());

    causeOfDeathField.addValueChangeListener(e -> {
        toggleCauseOfDeathFields(
                presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
    });

    causeOfDeathDiseaseField.addValueChangeListener(e -> {
        toggleCauseOfDeathFields(
                presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
    });

    addValueChangeListener(e -> {
        fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc);
    });

    deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false,
            I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(),
                    birthDateYear.getCaption())));
    burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties
            .getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));

    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
    });
}

From source file:de.symeda.sormas.ui.task.TaskEditForm.java

License:Open Source License

@Override
protected void addFields() {
    addField(TaskDto.CAZE, ComboBox.class);
    addField(TaskDto.EVENT, ComboBox.class);
    addField(TaskDto.CONTACT, ComboBox.class);
    DateTimeField startDate = addDateField(TaskDto.SUGGESTED_START, DateTimeField.class, -1);
    DateTimeField dueDate = addDateField(TaskDto.DUE_DATE, DateTimeField.class, -1);
    dueDate.setImmediate(true);/*from  ww w . j  ava 2s . c  om*/
    addField(TaskDto.PRIORITY, ComboBox.class);
    OptionGroup taskStatus = addField(TaskDto.TASK_STATUS, OptionGroup.class);
    OptionGroup taskContext = addField(TaskDto.TASK_CONTEXT, OptionGroup.class);
    taskContext.setImmediate(true);
    taskContext.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            updateByTaskContext();
        }
    });

    ComboBox taskTypeField = addField(TaskDto.TASK_TYPE, ComboBox.class);
    taskTypeField.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    taskTypeField.setImmediate(true);
    taskTypeField.addValueChangeListener(e -> {
        TaskType taskType = (TaskType) e.getProperty().getValue();
        if (taskType != null) {
            setRequired(taskType.isCreatorCommentRequired(), TaskDto.CREATOR_COMMENT);
        }
    });

    ComboBox assigneeUser = addField(TaskDto.ASSIGNEE_USER, ComboBox.class);
    assigneeUser.addValueChangeListener(e -> updateByCreatingAndAssignee());
    assigneeUser.setImmediate(true);

    TextArea creatorComment = addField(TaskDto.CREATOR_COMMENT, TextArea.class);
    creatorComment.setRows(2);
    creatorComment.setImmediate(true);
    addField(TaskDto.ASSIGNEE_REPLY, TextArea.class).setRows(2);

    setRequired(true, TaskDto.TASK_CONTEXT, TaskDto.TASK_TYPE, TaskDto.ASSIGNEE_USER, TaskDto.DUE_DATE);
    setReadOnly(true, TaskDto.TASK_CONTEXT, TaskDto.CAZE, TaskDto.CONTACT, TaskDto.EVENT);

    addValueChangeListener(e -> {
        TaskDto taskDto = getValue();

        if (taskDto.getTaskType() == TaskType.CASE_INVESTIGATION && taskDto.getCaze() != null) {
            taskStatus.addValidator(new TaskStatusValidator(taskDto.getCaze().getUuid(),
                    I18nProperties.getValidationError(Validations.investigationStatusUnclassifiedCase)));
        }

        DistrictReferenceDto district = null;
        RegionReferenceDto region = null;
        if (taskDto.getCaze() != null) {
            CaseDataDto caseDto = FacadeProvider.getCaseFacade().getCaseDataByUuid(taskDto.getCaze().getUuid());
            district = caseDto.getDistrict();
            region = caseDto.getRegion();
        } else if (taskDto.getContact() != null) {
            ContactDto contactDto = FacadeProvider.getContactFacade()
                    .getContactByUuid(taskDto.getContact().getUuid());
            CaseDataDto caseDto = FacadeProvider.getCaseFacade()
                    .getCaseDataByUuid(contactDto.getCaze().getUuid());
            district = caseDto.getDistrict();
            region = caseDto.getRegion();
        } else if (taskDto.getEvent() != null) {
            EventDto eventDto = FacadeProvider.getEventFacade().getEventByUuid(taskDto.getEvent().getUuid());
            district = eventDto.getEventLocation().getDistrict();
            region = eventDto.getEventLocation().getRegion();
        } else {
            UserDto userDto = UserProvider.getCurrent().getUser();
            district = userDto.getDistrict();
            region = userDto.getRegion();
        }

        List<UserReferenceDto> users = new ArrayList<>();
        if (district != null) {
            users = FacadeProvider.getUserFacade().getUserRefsByDistrict(district, true);
        } else if (region != null) {
            users = FacadeProvider.getUserFacade().getUsersByRegionAndRoles(region);
        } else {
            // fallback - just show all users
            users = FacadeProvider.getUserFacade().getAllAfterAsReference(null);
        }

        // Validation
        startDate.addValidator(new DateComparisonValidator(startDate, dueDate, true, false, I18nProperties
                .getValidationError(Validations.beforeDate, startDate.getCaption(), dueDate.getCaption())));
        dueDate.addValidator(new DateComparisonValidator(dueDate, startDate, false, false, I18nProperties
                .getValidationError(Validations.afterDate, dueDate.getCaption(), startDate.getCaption())));

        TaskController taskController = ControllerProvider.getTaskController();
        for (UserReferenceDto user : users) {
            assigneeUser.addItem(user);
            assigneeUser.setItemCaption(user, taskController.getUserCaptionWithPendingTaskCount(user));
        }
    });
}