Example usage for com.vaadin.v7.data.fieldgroup FieldGroup getField

List of usage examples for com.vaadin.v7.data.fieldgroup FieldGroup getField

Introduction

In this page you can find the example usage for com.vaadin.v7.data.fieldgroup FieldGroup getField.

Prototype

public Field<?> getField(Object propertyId) 

Source Link

Document

Returns the field that is bound to the given property id.

Usage

From source file:de.symeda.sormas.ui.events.EventDataForm.java

License:Open Source License

@SuppressWarnings("rawtypes")
public void setTypeOfPlaceTextRequirement() {
    FieldGroup fieldGroup = getFieldGroup();
    ComboBox typeOfPlaceField = (ComboBox) fieldGroup.getField(EventDto.TYPE_OF_PLACE);
    TextField typeOfPlaceTextField = (TextField) fieldGroup.getField(EventDto.TYPE_OF_PLACE_TEXT);
    ((AbstractField) typeOfPlaceField).setImmediate(true);

    // initialize
    {//from ww w .j a v a  2  s  .com
        typeOfPlaceTextField.setRequired(typeOfPlaceField.getValue() == TypeOfPlace.OTHER);
    }

    typeOfPlaceField.addValueChangeListener(event -> {
        typeOfPlaceTextField.setRequired(typeOfPlaceField.getValue() == TypeOfPlace.OTHER);
    });
}

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

License:Open Source License

/**
 * Sets the fields defined by the ids contained in sourceValues to required when the person is symptomatic
 * and - if a visit is processed - cooperative. When this method is called from within a case, it needs to 
 * be called with visitStatusField set to null in order to ignore the visit status requirement.
 *///from  w w  w .ja va2  s . c  om
@SuppressWarnings("rawtypes")
private void addSoftRequiredStyleWhenSymptomaticAndCooperative(FieldGroup fieldGroup, Object targetPropertyId,
        List<String> sourcePropertyIds, List<Object> sourceValues, OptionGroup visitStatusField) {

    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        if (sourceField instanceof AbstractField<?>) {
            ((AbstractField) sourceField).setImmediate(true);
        }
    }

    // Initialize
    final Field targetField = fieldGroup.getField(targetPropertyId);
    if (!targetField.isVisible()) {
        return;
    }

    if (visitStatusField != null) {
        if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)
                && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
            FieldHelper.addSoftRequiredStyle(targetField);
        } else {
            FieldHelper.removeSoftRequiredStyle(targetField);
        }
    } else {
        if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)) {
            FieldHelper.addSoftRequiredStyle(targetField);
        } else {
            FieldHelper.removeSoftRequiredStyle(targetField);
        }
    }

    // Add listeners
    for (Object sourcePropertyId : sourcePropertyIds) {
        Field sourceField = fieldGroup.getField(sourcePropertyId);
        sourceField.addValueChangeListener(event -> {
            if (visitStatusField != null) {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)
                        && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            } else {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            }
        });
    }

    if (visitStatusField != null) {
        visitStatusField.addValueChangeListener(new ValueChangeListener() {
            @Override
            public void valueChange(com.vaadin.v7.data.Property.ValueChangeEvent event) {
                if (isAnySymptomSetToYes(fieldGroup, sourcePropertyIds, sourceValues)
                        && visitStatusField.getValue() == VisitStatus.COOPERATIVE) {
                    FieldHelper.addSoftRequiredStyle(targetField);
                } else {
                    FieldHelper.removeSoftRequiredStyle(targetField);
                }
            }
        });
    }
}

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

    // 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  w  w w.j av a 2s .com*/

    // 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

public static void setRequiredWhen(FieldGroup fieldGroup, Object sourcePropertyId,
        List<String> targetPropertyIds, final List<Object> sourceValues) {

    setRequiredWhen(fieldGroup, fieldGroup.getField(sourcePropertyId), targetPropertyIds, sourceValues);
}

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

License:Open Source License

public static void setRequiredWhenNotNull(FieldGroup fieldGroup, Object sourcePropertyId,
        String targetPropertyId) {
    setRequiredWhen(fieldGroup, fieldGroup.getField(sourcePropertyId), Arrays.asList(targetPropertyId),
            Arrays.asList((Object) null), true, null);
}

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  va  2s  . 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.// w  w  w. java 2s.c o m
 */
@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(FieldGroup fieldGroup, Field sourceField,
        List<String> targetPropertyIds, final List<Object> sourceValues, Disease disease) {

    if (sourceField instanceof AbstractField<?>) {
        ((AbstractField) sourceField).setImmediate(true);
    }//  w ww  .ja  va  2  s. c o  m

    // initialize
    {
        boolean required = sourceValues.contains(sourceField.getValue());
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class,
                    (String) targetPropertyId, disease)) {
                if (required) {
                    addSoftRequiredStyle(targetField);
                } else {
                    removeSoftRequiredStyle(targetField);
                }
            }
        }
    }

    sourceField.addValueChangeListener(event -> {
        boolean required = sourceValues.contains(event.getProperty().getValue());
        for (Object targetPropertyId : targetPropertyIds) {
            Field targetField = fieldGroup.getField(targetPropertyId);
            if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class,
                    (String) targetPropertyId, disease)) {
                if (required) {
                    addSoftRequiredStyle(targetField);
                } else {
                    removeSoftRequiredStyle(targetField);
                }
            }
        }
    });
}