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

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

Introduction

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

Prototype

@Override
public Item addItem(Object itemId) throws UnsupportedOperationException 

Source Link

Document

Create a new item into container.

Usage

From source file:com.adonis.ui.vehicles.VehiclesCrudView.java

public void setVehiclesCrudProperties(VehicleService vehicleService, FotoAlbumService fotoAlbumService) {
    GridLayoutCrudFormFactory<Vehicle> formFactory = new GridLayoutCrudFormFactory<>(Vehicle.class, 1, 10);
    vehiclesCrud.setCrudFormFactory(formFactory);

    vehiclesCrud.setAddOperation(vehicle -> vehicleService.insert(vehicle));
    vehiclesCrud.setUpdateOperation(vehicle -> vehicleService.save(vehicle));
    vehiclesCrud.setDeleteOperation(vehicle -> vehicleService.delete(vehicle));
    vehiclesCrud.setFindAllOperation(() -> vehicleService.findAll());
    vehiclesCrud.getCrudFormFactory().setVisiblePropertyIds("fotoAlbum", "vehicleNmbr", "licenseNmbr", "make",
            "vehicleType", "model", "year", "status", "active", "location", "vinNumber", "price", "priceDay",
            "priceWeek", "priceMonth");
    vehiclesCrud.getCrudFormFactory().setDisabledPropertyIds(CrudOperation.UPDATE, "id", "created", "updated");
    vehiclesCrud.getCrudFormFactory().setDisabledPropertyIds(CrudOperation.ADD, "id", "created", "updated");
    vehiclesCrud.getGrid().setColumns("vehicleNmbr", "licenseNmbr", "make", "vehicleType", "model", "year",
            "status", "active", "location", "vinNumber", "price", "priceDay", "priceWeek", "priceMonth");
    vehiclesCrud.getCrudFormFactory().setFieldProvider("fotoAlbum", new FieldProvider() {
        @Override/*from w ww  .  ja  va 2 s .  c o m*/
        public Field buildField() {
            VehicleAlbumField albumField = ((Vehicle) vehiclesCrud.getGrid().getSelectedRow()) != null
                    ? new VehicleAlbumField(((Vehicle) vehiclesCrud.getGrid().getSelectedRow()).getFotoAlbum(),
                            ((Vehicle) vehiclesCrud.getGrid().getSelectedRow()), vehicleService,
                            fotoAlbumService)
                    : new VehicleAlbumField(vehicleService, fotoAlbumService);
            if (((Vehicle) vehiclesCrud.getGrid().getSelectedRow()) != null)
                albumField
                        .setInternalValue((((Vehicle) vehiclesCrud.getGrid().getSelectedRow()).getFotoAlbum()));
            return albumField;
        }
    });

    vehiclesCrud.getCrudFormFactory().setFieldType("vehicleType", ComboBox.class);
    vehiclesCrud.getCrudFormFactory().setFieldProvider("vehicleType",
            () -> new ComboBox("vehicleType", vehicleService.findAllTypesNames()));
    vehiclesCrud.getCrudFormFactory().setFieldCreationListener("vehicleType", field -> {
        com.vaadin.v7.ui.ComboBox comboBox = (com.vaadin.v7.ui.ComboBox) field;
        List<String> items = vehicleService.findAllTypesNames();
        items.forEach(item -> {
            comboBox.addItem(item);
        });
    });

    vehiclesCrud.getCrudFormFactory().setFieldType("model", ComboBox.class);
    vehiclesCrud.getCrudFormFactory().setFieldProvider("model",
            () -> new ComboBox("model", vehicleService.findAllModelNames()));
    vehiclesCrud.getCrudFormFactory().setFieldCreationListener("model", field -> {
        com.vaadin.v7.ui.ComboBox comboBox = (com.vaadin.v7.ui.ComboBox) field;
        List<String> items = vehicleService.findAllModelNames();
        items.forEach(item -> {
            comboBox.addItem(item);
        });
    });

}

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

License:Open Source License

@Override
protected void addFields() {
    if (disease == null || symptomsContext == null) {
        // workaround to stop initialization until disease is set 
        return;//from  w  w w.  j av a  2s  .c o  m
    }

    // Add fields

    DateField onsetDateField = addField(SymptomsDto.ONSET_DATE, DateField.class);
    ComboBox onsetSymptom = addField(SymptomsDto.ONSET_SYMPTOM, ComboBox.class);
    if (symptomsContext == SymptomsContext.CASE) {
        onsetDateField.addValidator(new DateComparisonValidator(onsetDateField,
                caze.getHospitalization().getAdmissionDate(), true, false,
                I18nProperties.getValidationError(Validations.beforeDateSoft, onsetDateField.getCaption(),
                        I18nProperties.getPrefixCaption(HospitalizationDto.I18N_PREFIX,
                                HospitalizationDto.ADMISSION_DATE))));
        onsetDateField.setInvalidCommitted(true);
    }

    ComboBox temperature = addField(SymptomsDto.TEMPERATURE, ComboBox.class);
    for (Float temperatureValue : SymptomsHelper.getTemperatureValues()) {
        temperature.addItem(temperatureValue);
        temperature.setItemCaption(temperatureValue, SymptomsHelper.getTemperatureString(temperatureValue));
    }
    if (symptomsContext == SymptomsContext.CASE) {
        temperature.setCaption(I18nProperties.getCaption(Captions.symptomsMaxTemperature));
    }
    addField(SymptomsDto.TEMPERATURE_SOURCE);

    ComboBox bloodPressureSystolic = addField(SymptomsDto.BLOOD_PRESSURE_SYSTOLIC, ComboBox.class);
    bloodPressureSystolic.addItems(SymptomsHelper.getBloodPressureValues());
    ComboBox bloodPressureDiastolic = addField(SymptomsDto.BLOOD_PRESSURE_DIASTOLIC, ComboBox.class);
    bloodPressureDiastolic.addItems(SymptomsHelper.getBloodPressureValues());
    ComboBox heartRate = addField(SymptomsDto.HEART_RATE, ComboBox.class);
    heartRate.addItems(SymptomsHelper.getHeartRateValues());
    ComboBox respiratoryRate = addField(SymptomsDto.RESPIRATORY_RATE, ComboBox.class);
    respiratoryRate.addItems(SymptomsHelper.getRespiratoryRateValues());
    ComboBox weight = addField(SymptomsDto.WEIGHT, ComboBox.class);
    for (Integer weightValue : SymptomsHelper.getWeightValues()) {
        weight.addItem(weightValue);
        weight.setItemCaption(weightValue, SymptomsHelper.getDecimalString(weightValue));
    }
    ComboBox height = addField(SymptomsDto.HEIGHT, ComboBox.class);
    height.addItems(SymptomsHelper.getHeightValues());
    ComboBox midUpperArmCircumference = addField(SymptomsDto.MID_UPPER_ARM_CIRCUMFERENCE, ComboBox.class);
    for (Integer circumferenceValue : SymptomsHelper.getMidUpperArmCircumferenceValues()) {
        midUpperArmCircumference.addItem(circumferenceValue);
        midUpperArmCircumference.setItemCaption(circumferenceValue,
                SymptomsHelper.getDecimalString(circumferenceValue));
    }
    ComboBox glasgowComaScale = addField(SymptomsDto.GLASGOW_COMA_SCALE, ComboBox.class);
    glasgowComaScale.addItems(SymptomsHelper.getGlasgowComaScaleValues());

    addFields(SymptomsDto.FEVER, SymptomsDto.VOMITING, SymptomsDto.DIARRHEA, SymptomsDto.BLOOD_IN_STOOL,
            SymptomsDto.NAUSEA, SymptomsDto.ABDOMINAL_PAIN, SymptomsDto.HEADACHE, SymptomsDto.MUSCLE_PAIN,
            SymptomsDto.FATIGUE_WEAKNESS, SymptomsDto.SKIN_RASH, SymptomsDto.NECK_STIFFNESS,
            SymptomsDto.SORE_THROAT, SymptomsDto.COUGH, SymptomsDto.RUNNY_NOSE,
            SymptomsDto.DIFFICULTY_BREATHING, SymptomsDto.CHEST_PAIN, SymptomsDto.CONJUNCTIVITIS,
            SymptomsDto.EYE_PAIN_LIGHT_SENSITIVE, SymptomsDto.KOPLIKS_SPOTS, SymptomsDto.THROBOCYTOPENIA,
            SymptomsDto.OTITIS_MEDIA, SymptomsDto.HEARINGLOSS, SymptomsDto.DEHYDRATION,
            SymptomsDto.ANOREXIA_APPETITE_LOSS, SymptomsDto.REFUSAL_FEEDOR_DRINK, SymptomsDto.JOINT_PAIN,
            SymptomsDto.HICCUPS, SymptomsDto.BACKACHE, SymptomsDto.EYES_BLEEDING, SymptomsDto.JAUNDICE,
            SymptomsDto.DARK_URINE, SymptomsDto.STOMACH_BLEEDING, SymptomsDto.RAPID_BREATHING,
            SymptomsDto.SWOLLEN_GLANDS, SymptomsDto.SYMPTOMS_COMMENTS, SymptomsDto.UNEXPLAINED_BLEEDING,
            SymptomsDto.GUMS_BLEEDING, SymptomsDto.INJECTION_SITE_BLEEDING, SymptomsDto.NOSE_BLEEDING,
            SymptomsDto.BLOODY_BLACK_STOOL, SymptomsDto.RED_BLOOD_VOMIT, SymptomsDto.DIGESTED_BLOOD_VOMIT,
            SymptomsDto.COUGHING_BLOOD, SymptomsDto.BLEEDING_VAGINA, SymptomsDto.SKIN_BRUISING,
            SymptomsDto.BLOOD_URINE, SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS,
            SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS_TEXT, SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS,
            SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT, SymptomsDto.LESIONS, SymptomsDto.LESIONS_THAT_ITCH,
            SymptomsDto.LESIONS_SAME_STATE, SymptomsDto.LESIONS_SAME_SIZE, SymptomsDto.LESIONS_DEEP_PROFOUND,
            SymptomsDto.LESIONS_FACE, SymptomsDto.LESIONS_LEGS, SymptomsDto.LESIONS_SOLES_FEET,
            SymptomsDto.LESIONS_PALMS_HANDS, SymptomsDto.LESIONS_THORAX, SymptomsDto.LESIONS_ARMS,
            SymptomsDto.LESIONS_GENITALS, SymptomsDto.LESIONS_ALL_OVER_BODY,
            SymptomsDto.LYMPHADENOPATHY_AXILLARY, SymptomsDto.LYMPHADENOPATHY_CERVICAL,
            SymptomsDto.LYMPHADENOPATHY_INGUINAL, SymptomsDto.CHILLS_SWEATS, SymptomsDto.BEDRIDDEN,
            SymptomsDto.ORAL_ULCERS, SymptomsDto.PAINFUL_LYMPHADENITIS, SymptomsDto.BLACKENING_DEATH_OF_TISSUE,
            SymptomsDto.BUBOES_GROIN_ARMPIT_NECK, SymptomsDto.BULGING_FONTANELLE,
            SymptomsDto.PHARYNGEAL_ERYTHEMA, SymptomsDto.PHARYNGEAL_EXUDATE, SymptomsDto.OEDEMA_FACE_NECK,
            SymptomsDto.OEDEMA_LOWER_EXTREMITY, SymptomsDto.LOSS_SKIN_TURGOR, SymptomsDto.PALPABLE_LIVER,
            SymptomsDto.PALPABLE_SPLEEN, SymptomsDto.MALAISE, SymptomsDto.SUNKEN_EYES_FONTANELLE,
            SymptomsDto.SIDE_PAIN, SymptomsDto.FLUID_IN_LUNG_CAVITY, SymptomsDto.TREMOR,
            SymptomsDto.BILATERAL_CATARACTS, SymptomsDto.UNILATERAL_CATARACTS, SymptomsDto.CONGENITAL_GLAUCOMA,
            SymptomsDto.CONGENITAL_HEART_DISEASE, SymptomsDto.PIGMENTARY_RETINOPATHY,
            SymptomsDto.RADIOLUCENT_BONE_DISEASE, SymptomsDto.SPLENOMEGALY, SymptomsDto.MICROCEPHALY,
            SymptomsDto.MENINGOENCEPHALITIS, SymptomsDto.PURPURIC_RASH, SymptomsDto.DEVELOPMENTAL_DELAY,
            SymptomsDto.CONGENITAL_HEART_DISEASE_TYPE, SymptomsDto.CONGENITAL_HEART_DISEASE_DETAILS,
            SymptomsDto.JAUNDICE_WITHIN_24_HOURS_OF_BIRTH, SymptomsDto.PATIENT_ILL_LOCATION);
    addField(SymptomsDto.LESIONS_ONSET_DATE, DateField.class);

    // complications
    addFields(SymptomsDto.ALTERED_CONSCIOUSNESS, SymptomsDto.CONFUSED_DISORIENTED,
            SymptomsDto.HEMORRHAGIC_SYNDROME, SymptomsDto.HYPERGLYCEMIA, SymptomsDto.HYPOGLYCEMIA,
            SymptomsDto.MENINGEAL_SIGNS, SymptomsDto.SEIZURES, SymptomsDto.SEPSIS, SymptomsDto.SHOCK);

    monkeypoxImageFieldIds = Arrays.asList(SymptomsDto.LESIONS_RESEMBLE_IMG1, SymptomsDto.LESIONS_RESEMBLE_IMG2,
            SymptomsDto.LESIONS_RESEMBLE_IMG3, SymptomsDto.LESIONS_RESEMBLE_IMG4);
    for (String propertyId : monkeypoxImageFieldIds) {
        @SuppressWarnings("rawtypes")
        Field monkeypoxImageField = addField(propertyId);
        CssStyles.style(monkeypoxImageField, CssStyles.VSPACE_NONE);
    }

    // Set initial visibilities

    initializeVisibilitiesAndAllowedVisibilities(disease, viewMode);

    if (symptomsContext != SymptomsContext.CLINICAL_VISIT) {
        setVisible(false, SymptomsDto.BLOOD_PRESSURE_SYSTOLIC, SymptomsDto.BLOOD_PRESSURE_DIASTOLIC,
                SymptomsDto.HEART_RATE, SymptomsDto.RESPIRATORY_RATE, SymptomsDto.WEIGHT, SymptomsDto.HEIGHT,
                SymptomsDto.MID_UPPER_ARM_CIRCUMFERENCE, SymptomsDto.GLASGOW_COMA_SCALE);
    } else {
        setVisible(false, SymptomsDto.ONSET_SYMPTOM, SymptomsDto.ONSET_DATE);
    }

    // Initialize lists

    conditionalBleedingSymptomFieldIds = Arrays.asList(SymptomsDto.GUMS_BLEEDING,
            SymptomsDto.INJECTION_SITE_BLEEDING, SymptomsDto.NOSE_BLEEDING, SymptomsDto.BLOODY_BLACK_STOOL,
            SymptomsDto.RED_BLOOD_VOMIT, SymptomsDto.DIGESTED_BLOOD_VOMIT, SymptomsDto.EYES_BLEEDING,
            SymptomsDto.COUGHING_BLOOD, SymptomsDto.BLEEDING_VAGINA, SymptomsDto.SKIN_BRUISING,
            SymptomsDto.STOMACH_BLEEDING, SymptomsDto.BLOOD_URINE, SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS);
    lesionsFieldIds = Arrays.asList(SymptomsDto.LESIONS_SAME_STATE, SymptomsDto.LESIONS_SAME_SIZE,
            SymptomsDto.LESIONS_DEEP_PROFOUND, SymptomsDto.LESIONS_THAT_ITCH);
    lesionsLocationFieldIds = Arrays.asList(SymptomsDto.LESIONS_FACE, SymptomsDto.LESIONS_LEGS,
            SymptomsDto.LESIONS_SOLES_FEET, SymptomsDto.LESIONS_PALMS_HANDS, SymptomsDto.LESIONS_THORAX,
            SymptomsDto.LESIONS_ARMS, SymptomsDto.LESIONS_GENITALS, SymptomsDto.LESIONS_ALL_OVER_BODY);
    unconditionalSymptomFieldIds = Arrays.asList(SymptomsDto.FEVER, SymptomsDto.VOMITING, SymptomsDto.DIARRHEA,
            SymptomsDto.BLOOD_IN_STOOL, SymptomsDto.NAUSEA, SymptomsDto.ABDOMINAL_PAIN, SymptomsDto.HEADACHE,
            SymptomsDto.MUSCLE_PAIN, SymptomsDto.FATIGUE_WEAKNESS, SymptomsDto.SKIN_RASH,
            SymptomsDto.NECK_STIFFNESS, SymptomsDto.SORE_THROAT, SymptomsDto.COUGH, SymptomsDto.RUNNY_NOSE,
            SymptomsDto.DIFFICULTY_BREATHING, SymptomsDto.CHEST_PAIN, SymptomsDto.CONJUNCTIVITIS,
            SymptomsDto.EYE_PAIN_LIGHT_SENSITIVE, SymptomsDto.KOPLIKS_SPOTS, SymptomsDto.THROBOCYTOPENIA,
            SymptomsDto.OTITIS_MEDIA, SymptomsDto.HEARINGLOSS, SymptomsDto.DEHYDRATION,
            SymptomsDto.ANOREXIA_APPETITE_LOSS, SymptomsDto.REFUSAL_FEEDOR_DRINK, SymptomsDto.JOINT_PAIN,
            SymptomsDto.HICCUPS, SymptomsDto.BACKACHE, SymptomsDto.JAUNDICE, SymptomsDto.DARK_URINE,
            SymptomsDto.RAPID_BREATHING, SymptomsDto.SWOLLEN_GLANDS, SymptomsDto.UNEXPLAINED_BLEEDING,
            SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS, SymptomsDto.LESIONS,
            SymptomsDto.LYMPHADENOPATHY_AXILLARY, SymptomsDto.LYMPHADENOPATHY_CERVICAL,
            SymptomsDto.LYMPHADENOPATHY_INGUINAL, SymptomsDto.CHILLS_SWEATS, SymptomsDto.BEDRIDDEN,
            SymptomsDto.ORAL_ULCERS, SymptomsDto.PAINFUL_LYMPHADENITIS, SymptomsDto.BLACKENING_DEATH_OF_TISSUE,
            SymptomsDto.BUBOES_GROIN_ARMPIT_NECK, SymptomsDto.BULGING_FONTANELLE,
            SymptomsDto.PHARYNGEAL_ERYTHEMA, SymptomsDto.PHARYNGEAL_EXUDATE, SymptomsDto.OEDEMA_FACE_NECK,
            SymptomsDto.OEDEMA_LOWER_EXTREMITY, SymptomsDto.LOSS_SKIN_TURGOR, SymptomsDto.PALPABLE_LIVER,
            SymptomsDto.PALPABLE_SPLEEN, SymptomsDto.MALAISE, SymptomsDto.SUNKEN_EYES_FONTANELLE,
            SymptomsDto.SIDE_PAIN, SymptomsDto.FLUID_IN_LUNG_CAVITY, SymptomsDto.TREMOR,
            SymptomsDto.BILATERAL_CATARACTS, SymptomsDto.UNILATERAL_CATARACTS, SymptomsDto.CONGENITAL_GLAUCOMA,
            SymptomsDto.CONGENITAL_HEART_DISEASE, SymptomsDto.RADIOLUCENT_BONE_DISEASE,
            SymptomsDto.SPLENOMEGALY, SymptomsDto.MICROCEPHALY, SymptomsDto.MENINGOENCEPHALITIS,
            SymptomsDto.DEVELOPMENTAL_DELAY, SymptomsDto.PURPURIC_RASH, SymptomsDto.PIGMENTARY_RETINOPATHY,
            // complications
            SymptomsDto.ALTERED_CONSCIOUSNESS, SymptomsDto.CONFUSED_DISORIENTED,
            SymptomsDto.HEMORRHAGIC_SYNDROME, SymptomsDto.HYPERGLYCEMIA, SymptomsDto.HYPOGLYCEMIA,
            SymptomsDto.MENINGEAL_SIGNS, SymptomsDto.SEIZURES, SymptomsDto.SEPSIS, SymptomsDto.SHOCK);

    // Set visibilities

    FieldHelper.setVisibleWhen(getFieldGroup(), conditionalBleedingSymptomFieldIds,
            SymptomsDto.UNEXPLAINED_BLEEDING, Arrays.asList(SymptomState.YES), true, SymptomsDto.class,
            disease);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS_TEXT,
            SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS, Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT,
            SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS, Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), lesionsFieldIds, SymptomsDto.LESIONS,
            Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), lesionsLocationFieldIds, SymptomsDto.LESIONS,
            Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.LESIONS_ONSET_DATE, SymptomsDto.LESIONS,
            Arrays.asList(SymptomState.YES), true);

    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.CONGENITAL_HEART_DISEASE_TYPE,
            SymptomsDto.CONGENITAL_HEART_DISEASE, Arrays.asList(SymptomState.YES), true);
    FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.CONGENITAL_HEART_DISEASE_DETAILS,
            SymptomsDto.CONGENITAL_HEART_DISEASE_TYPE, Arrays.asList(CongenitalHeartDiseaseType.OTHER), true);
    if (isVisibleAllowed(getFieldGroup().getField(SymptomsDto.JAUNDICE_WITHIN_24_HOURS_OF_BIRTH))) {
        FieldHelper.setVisibleWhen(getFieldGroup(), SymptomsDto.JAUNDICE_WITHIN_24_HOURS_OF_BIRTH,
                SymptomsDto.JAUNDICE, Arrays.asList(SymptomState.YES), true);
    }

    FieldHelper.addSoftRequiredStyle(getField(SymptomsDto.LESIONS_ONSET_DATE));

    boolean isInfant = person != null && person.getApproximateAge() != null
            && ((person.getApproximateAge() <= 12
                    && person.getApproximateAgeType() == ApproximateAgeType.MONTHS)
                    || person.getApproximateAge() <= 1);
    if (!isInfant) {
        getFieldGroup().getField(SymptomsDto.BULGING_FONTANELLE).setVisible(false);
    }

    // Handle visibility of lesions locations caption
    Label lesionsLocationsCaption = new Label(I18nProperties.getCaption(Captions.symptomsLesionsLocations));
    CssStyles.style(lesionsLocationsCaption, CssStyles.VSPACE_3);
    getContent().addComponent(lesionsLocationsCaption, LESIONS_LOCATIONS_LOC);
    getContent().getComponent(LESIONS_LOCATIONS_LOC)
            .setVisible(getFieldGroup().getField(SymptomsDto.LESIONS).getValue() == SymptomState.YES);
    getFieldGroup().getField(SymptomsDto.LESIONS).addValueChangeListener(e -> {
        getContent().getComponent(LESIONS_LOCATIONS_LOC)
                .setVisible(e.getProperty().getValue() == SymptomState.YES);
    });

    // Symptoms hint text
    Label symptomsHint = new Label(
            I18nProperties.getString(symptomsContext == SymptomsContext.CASE ? Strings.messageSymptomsHint
                    : Strings.messageSymptomsVisitHint),
            ContentMode.HTML);
    getContent().addComponent(symptomsHint, SYMPTOMS_HINT_LOC);

    if (disease == Disease.MONKEYPOX) {
        setUpMonkeypoxVisibilities();
    }

    if (symptomsContext != SymptomsContext.CASE) {
        getFieldGroup().getField(SymptomsDto.PATIENT_ILL_LOCATION).setVisible(false);
    }

    FieldHelper.setRequiredWhen(getFieldGroup(),
            getFieldGroup().getField(SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS),
            Arrays.asList(SymptomsDto.OTHER_HEMORRHAGIC_SYMPTOMS_TEXT), Arrays.asList(SymptomState.YES),
            disease);
    FieldHelper.setRequiredWhen(getFieldGroup(),
            getFieldGroup().getField(SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS),
            Arrays.asList(SymptomsDto.OTHER_NON_HEMORRHAGIC_SYMPTOMS_TEXT), Arrays.asList(SymptomState.YES),
            disease);
    FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(SymptomsDto.LESIONS), lesionsFieldIds,
            Arrays.asList(SymptomState.YES), disease);
    FieldHelper.setRequiredWhen(getFieldGroup(), getFieldGroup().getField(SymptomsDto.LESIONS),
            monkeypoxImageFieldIds, Arrays.asList(SymptomState.YES), disease);

    addListenerForOnsetFields(onsetSymptom, onsetDateField);

    Button clearAllButton = new Button(I18nProperties.getCaption(Captions.actionClearAll));
    clearAllButton.addStyleName(ValoTheme.BUTTON_LINK);

    clearAllButton.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            for (Object symptomId : unconditionalSymptomFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : conditionalBleedingSymptomFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : lesionsFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : lesionsLocationFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
            for (Object symptomId : monkeypoxImageFieldIds) {
                getFieldGroup().getField(symptomId).setValue(null);
            }
        }
    });

    Button setEmptyToNoButton = new Button(I18nProperties.getCaption(Captions.symptomsSetClearedToNo));
    setEmptyToNoButton.addStyleName(ValoTheme.BUTTON_LINK);

    setEmptyToNoButton.addClickListener(new ClickListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void buttonClick(ClickEvent event) {
            for (Object symptomId : unconditionalSymptomFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
            for (Object symptomId : conditionalBleedingSymptomFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
            for (Object symptomId : lesionsFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
            for (Object symptomId : monkeypoxImageFieldIds) {
                Field<SymptomState> symptom = (Field<SymptomState>) getFieldGroup().getField(symptomId);
                if (symptom.isVisible() && symptom.getValue() == null) {
                    symptom.setValue(SymptomState.NO);
                }
            }
        }
    });

    // Complications heading - not displayed for Rubella (dirty, should be made generic)
    Label complicationsHeading = new Label(I18nProperties.getString(Strings.headingComplications));
    CssStyles.style(complicationsHeading, CssStyles.H3);
    if (disease != Disease.CONGENITAL_RUBELLA) {
        getContent().addComponent(complicationsHeading, COMPLICATIONS_HEADING);
    }

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.addComponent(clearAllButton);
    buttonsLayout.addComponent(setEmptyToNoButton);
    buttonsLayout.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
    getContent().addComponent(buttonsLayout, BUTTONS_LOC);
}

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)));
            }/*from  w  w  w.j a v a  2s .  c o 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
}

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);//  ww w  .  j a v  a  2s  .com
    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));
        }
    });
}

From source file:de.symeda.sormas.ui.utils.AbstractEditForm.java

License:Open Source License

/**
 * Adds the field to the form by using addField(fieldId, fieldType), but additionally sets up a ValueChangeListener
 * that makes sure the value that is about to be selected is added to the list of allowed values. This is intended
 * to be used for Disease fields that might contain a disease that is no longer active in the system and thus will
 * not be returned by DiseaseHelper.isActivePrimaryDisease(disease).
 *//*  w  w  w . jav  a 2s.  c  om*/
@SuppressWarnings("rawtypes")
protected ComboBox addDiseaseField(String fieldId, boolean showNonPrimaryDiseases) {
    ComboBox field = addField(fieldId, ComboBox.class);
    if (showNonPrimaryDiseases) {
        addNonPrimaryDiseasesTo(field);
    }
    // Make sure that the ComboBox still contains a pre-selected inactive disease
    field.addValueChangeListener(e -> {
        Object value = e.getProperty().getValue();
        if (value != null && !field.containsId(value)) {
            Item newItem = field.addItem(value);
            newItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID)
                    .setValue(value.toString());
        }
    });
    return field;
}

From source file:de.symeda.sormas.ui.utils.AbstractEditForm.java

License:Open Source License

protected void addNonPrimaryDiseasesTo(ComboBox diseaseField) {
    List<Disease> diseases = FacadeProvider.getDiseaseConfigurationFacade().getAllActiveDiseases();
    for (Disease disease : diseases) {
        if (diseaseField.getItem(disease) != null) {
            continue;
        }//from   w  w  w .  j a va2s.co m

        Item newItem = diseaseField.addItem(disease);
        newItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID).setValue(disease.toString());
    }
}