Example usage for com.vaadin.v7.ui Field getValue

List of usage examples for com.vaadin.v7.ui Field getValue

Introduction

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

Prototype

public T getValue();

Source Link

Document

Gets the value stored in the Property.

Usage

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

License:Open Source License

@SuppressWarnings("unchecked")
private void updateFollowUpStatusComponents() {

    getContent().removeComponent(CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
    getContent().removeComponent(LOST_FOLLOW_UP_BTN_LOC);

    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(ContactDto.FOLLOW_UP_STATUS);
    boolean followUpVisible = getValue() != null && statusField.isVisible();
    if (followUpVisible && UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EDIT)) {
        FollowUpStatus followUpStatus = statusField.getValue();
        if (followUpStatus == FollowUpStatus.FOLLOW_UP) {

            Button cancelButton = new Button(I18nProperties.getCaption(Captions.contactCancelFollowUp));
            cancelButton.setWidth(100, Unit.PERCENTAGE);
            cancelButton.addClickListener(new ClickListener() {
                @Override/*from   ww  w . j av a  2s. co  m*/
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.CANCELED);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(cancelButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);

            Button lostButton = new Button(I18nProperties.getCaption(Captions.contactLostToFollowUp));
            lostButton.setWidth(100, Unit.PERCENTAGE);
            lostButton.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.LOST);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(lostButton, LOST_FOLLOW_UP_BTN_LOC);

        } else if (followUpStatus == FollowUpStatus.CANCELED || followUpStatus == FollowUpStatus.LOST) {

            Button resumeButton = new Button(I18nProperties.getCaption(Captions.contactResumeFollowUp));
            resumeButton.addStyleName(CssStyles.FORCE_CAPTION);
            resumeButton.setWidth(100, Unit.PERCENTAGE);
            resumeButton.addClickListener(new ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    Field<FollowUpStatus> statusField = (Field<FollowUpStatus>) getField(
                            ContactDto.FOLLOW_UP_STATUS);
                    statusField.setReadOnly(false);
                    statusField.setValue(FollowUpStatus.FOLLOW_UP);
                    statusField.setReadOnly(true);
                    updateFollowUpStatusComponents();
                }
            });
            getContent().addComponent(resumeButton, CANCEL_OR_RESUME_FOLLOW_UP_BTN_LOC);
        }
    }
}

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;//  w  ww.  j a v  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

/**
 * Returns true if if the value of any field associated with the sourcePropertyIds
 * is set to one of the values contained in sourceValues.
 * /*w  ww . j av  a2  s.  c om*/
 * @param fieldGroup
 * @param sourcePropertyIds
 * @param sourceValues
 * @return
 */
@SuppressWarnings("rawtypes")
public boolean isAnySymptomSetToYes(FieldGroup fieldGroup, List<String> sourcePropertyIds,
        List<Object> sourceValues) {

    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        if (sourceValues.contains(sourceField.getValue())) {
            return true;
        }
    }

    return false;
}

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  2  s.  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
}

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

License:Open Source License

public DateComparisonValidator(Field<Date> dateField, Field<Date> referenceField, boolean earlierOrSame,
        boolean changeInvalidCommitted, String errorMessage) {
    this(dateField, () -> referenceField.getValue(), earlierOrSame, changeInvalidCommitted, errorMessage);
}

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

License:Open Source License

@SuppressWarnings("rawtypes")
public static void setReadOnlyWhen(final FieldGroup fieldGroup, List<Object> targetPropertyIds,
        Object sourcePropertyId, final List<Object> sourceValues, final boolean clearOnReadOnly) {

    Field sourceField = fieldGroup.getField(sourcePropertyId);
    if (sourceField instanceof AbstractField<?>) {
        ((AbstractField) sourceField).setImmediate(true);
    }//  w  ww  . j a v a2s  .c om

    // initialize
    {
        boolean readOnly = sourceValues.contains(sourceField.getValue());
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            if (readOnly && clearOnReadOnly && targetField.getValue() != null) {
                targetField.setReadOnly(false);
                targetField.clear();
            }
            targetField.setReadOnly(readOnly);
            if (readOnly) { // workaround to make sure the caption also knows the field is read-only
                targetField.addStyleName("v-readonly");
            } else {
                targetField.removeStyleName("v-readonly");
            }
        }
    }

    sourceField.addValueChangeListener(event -> {
        boolean readOnly = sourceValues.contains(event.getProperty().getValue());
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            if (readOnly && clearOnReadOnly && targetField.getValue() != null) {
                targetField.setReadOnly(false);
                targetField.clear();
            }
            targetField.setReadOnly(readOnly);
            if (readOnly) { // workaround to make sure the caption also knows the field is read-only
                targetField.addStyleName("v-readonly");
            } else {
                targetField.removeStyleName("v-readonly");
            }
        }
    });
}

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

License:Open Source License

@SuppressWarnings("rawtypes")
public static void setVisibleWhen(final FieldGroup fieldGroup, List<String> targetPropertyIds,
        Object sourcePropertyId, final List<Object> sourceValues, boolean visibleWhenNot,
        final boolean clearOnHidden, Class fieldClass, Disease disease) {

    Field sourceField = fieldGroup.getField(sourcePropertyId);
    if (sourceField instanceof AbstractField<?>) {
        ((AbstractField) sourceField).setImmediate(true);
    }/*from  ww  w .  ja va2  s  . c o  m*/

    // initialize
    {
        boolean visible = sourceValues.contains(sourceField.getValue());
        visible = visible != visibleWhenNot;
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            //            if(fieldClass == null || disease == null || Diseases.DiseasesConfiguration.isDefined(fieldClass, (String) targetPropertyId, disease)) {
            targetField.setVisible(visible);
            if (!visible && clearOnHidden && targetField.getValue() != null) {
                targetField.clear();
            }
            //            }
        }
    }

    sourceField.addValueChangeListener(event -> {
        boolean visible = sourceValues.contains(event.getProperty().getValue());
        visible = visible != visibleWhenNot;
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            //            if(fieldClass == null || disease == null || Diseases.DiseasesConfiguration.isDefined(fieldClass, (String) targetPropertyId, disease)) {
            targetField.setVisible(visible);
            if (!visible && clearOnHidden && targetField.getValue() != null) {
                targetField.clear();
            }
            //            }
        }
    });
}

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

License:Open Source License

/**
 * Sets the target fields to required when the sourceField has a value that's
 * contained in the sourceValues list; the disease is needed to make sure that
 * no fields are set to required that are not visible and therefore cannot be
 * edited by the user./*from w w  w.  j  a  v  a2s .c o m*/
 */
@SuppressWarnings("rawtypes")
public static void setRequiredWhen(FieldGroup fieldGroup, Field sourceField, List<String> targetPropertyIds,
        final List<Object> sourceValues, boolean requiredWhenNot, Disease disease) {

    if (sourceField instanceof AbstractField<?>) {
        ((AbstractField) sourceField).setImmediate(true);
    }

    // initialize
    {
        boolean required = sourceValues.contains(sourceField.getValue());
        required = required != requiredWhenNot;
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            if (!targetField.isVisible()) {
                targetField.setRequired(false);
                continue;
            }

            if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class,
                    (String) targetPropertyId, disease)) {
                targetField.setRequired(required);
            }
        }
    }

    sourceField.addValueChangeListener(event -> {
        boolean required = sourceValues.contains(event.getProperty().getValue());
        required = required != requiredWhenNot;
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            if (!targetField.isVisible()) {
                targetField.setRequired(false);
                continue;
            }

            if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class,
                    (String) targetPropertyId, disease)) {
                targetField.setRequired(required);
            }
        }
    });
}

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

License:Open Source License

/**
 * Sets the target fields to enabled when the source field has a value that's
 * contained in the sourceValues list.//from  w  ww  .j av a 2  s  . c  om
 */
@SuppressWarnings("rawtypes")
public static void setEnabledWhen(FieldGroup fieldGroup, Field sourceField, final List<Object> sourceValues,
        List<Object> targetPropertyIds, boolean clearOnDisabled) {

    if (sourceField instanceof AbstractField<?>) {
        ((AbstractField) sourceField).setImmediate(true);
    }

    // initialize
    {
        boolean enabled = sourceValues.contains(sourceField.getValue());
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            targetField.setEnabled(enabled);
            if (!enabled && clearOnDisabled) {
                targetField.clear();
            }
        }
    }

    sourceField.addValueChangeListener(event -> {
        boolean enabled = sourceValues.contains(event.getProperty().getValue());
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            targetField.setEnabled(enabled);
            if (!enabled && clearOnDisabled) {
                targetField.clear();
            }
        }
    });
}

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

License:Open Source License

@SuppressWarnings("rawtypes")
public static void addSoftRequiredStyleWhen(Field<?> sourceField, List<Field<?>> targetFields,
        final List<Object> sourceValues) {
    if (sourceField instanceof AbstractField<?>) {
        ((AbstractField) sourceField).setImmediate(true);
    }/*  w  w  w .  j  a  v  a 2s. c om*/

    // initialize
    {
        boolean softRequired = sourceValues.contains(sourceField.getValue());
        for (Field<?> targetField : targetFields) {
            if (softRequired) {
                addSoftRequiredStyle(targetField);
            } else {
                removeSoftRequiredStyle(targetField);
            }
        }
    }

    sourceField.addValueChangeListener(event -> {
        boolean softRequired = sourceValues.contains(event.getProperty().getValue());
        for (Field<?> targetField : targetFields) {
            if (softRequired) {
                addSoftRequiredStyle(targetField);
            } else {
                removeSoftRequiredStyle(targetField);
            }
        }
    });
}