use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.
the class FieldHelper method setVisibleWhenSourceNotNull.
@SuppressWarnings("rawtypes")
public static void setVisibleWhenSourceNotNull(final FieldGroup fieldGroup, List<String> targetPropertyIds, String sourcePropertyId, boolean clearOnHidden) {
final List<? extends Field<?>> targetFields = targetPropertyIds.stream().map(id -> fieldGroup.getField(id)).collect(Collectors.toList());
Field sourceField = fieldGroup.getField(sourcePropertyId);
setVisibleWhenSourceNotNull(sourceField, targetFields, clearOnHidden);
}
use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.
the class FieldHelper method setReadOnlyWhen.
@SuppressWarnings("rawtypes")
public static void setReadOnlyWhen(final FieldGroup fieldGroup, List<?> targetPropertyIds, Object sourcePropertyId, final List<?> sourceValues, final boolean clearOnReadOnly, boolean readOnlyWhenNull) {
Field sourceField = fieldGroup.getField(sourcePropertyId);
if (sourceField instanceof AbstractField<?>) {
((AbstractField) sourceField).setImmediate(true);
}
// initialize
{
boolean readOnly;
if (getNullableSourceFieldValue(sourceField) == null) {
readOnly = readOnlyWhenNull;
} else {
readOnly = sourceValues.contains(getNullableSourceFieldValue(sourceField));
}
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;
if (getNullableSourceFieldValue(sourceField) == null) {
readOnly = readOnlyWhenNull;
} else {
readOnly = sourceValues.contains(getNullableSourceFieldValue(((Field) event.getProperty())));
}
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");
}
}
});
}
use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.
the class FieldHelper method onValueChangedSetVisible.
private static void onValueChangedSetVisible(final FieldGroup fieldGroup, List<String> targetPropertyIds, Map<?, ? extends List<?>> sourcePropertyIdsAndValues, final boolean clearOnHidden) {
// a workaround variable to be modified in the forEach lambda
boolean[] visibleArray = { true };
sourcePropertyIdsAndValues.forEach((sourcePropertyId, sourceValues) -> {
if (!sourceValues.contains(fieldGroup.getField(sourcePropertyId).getValue()))
visibleArray[0] = false;
});
boolean visible = visibleArray[0];
for (Object targetPropertyId : targetPropertyIds) {
@SuppressWarnings("rawtypes") Field targetField = fieldGroup.getField(targetPropertyId);
targetField.setVisible(visible);
if (!visible && clearOnHidden && targetField.getValue() != null) {
targetField.clear();
}
}
}
use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.
the class FieldHelper method setVisibleWhen.
@SuppressWarnings("rawtypes")
public static void setVisibleWhen(final FieldGroup fieldGroup, List<String> targetPropertyIds, Object sourcePropertyId, final List<?> sourceValues, final boolean clearOnHidden) {
Field sourceField = fieldGroup.getField(sourcePropertyId);
setVisibleWhen(fieldGroup, targetPropertyIds, sourceField, sourceValues, clearOnHidden);
}
use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.
the class CommitDiscardWrapperComponent method addDirtyHandler.
@SuppressWarnings("deprecation")
protected void addDirtyHandler(FieldGroup[] fieldGroups) {
if (fieldGroups != null) {
Stream.of(fieldGroups).forEach(fg -> fg.getFields().forEach(f -> f.addValueChangeListener(ev -> {
final Object source = ((Field.ValueChangeEvent) ev).getSource();
// moving it to a separate method breaks the logic at least on my dev system
if (source instanceof PersonEditForm) {
final PersonEditForm personEditForm = (PersonEditForm) source;
final LocationEditForm locationEditForm = personEditForm.getField(PersonDto.ADDRESS);
if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
dirty = true;
} else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
dirty = true;
} else if (personEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
dirty = true;
}
} else if (source instanceof EventDataForm) {
final EventDataForm eventDataForm = (EventDataForm) source;
final LocationEditForm locationEditForm = eventDataForm.getField(EventDto.EVENT_LOCATION);
if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
dirty = true;
} else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
dirty = true;
} else if (eventDataForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
dirty = true;
}
} else if (source instanceof LocationEditForm) {
final LocationEditForm locationEditForm = (LocationEditForm) source;
if (atLeastOneFieldModified(locationEditForm.getField(LocationDto.LATITUDE), locationEditForm.getField(LocationDto.LONGITUDE), locationEditForm.getField(LocationDto.LAT_LON_ACCURACY))) {
dirty = true;
} else if (locationEditForm.getFieldGroup().getFields().stream().filter(lf -> !(lf instanceof AccessibleTextField)).anyMatch(Buffered::isModified)) {
dirty = true;
}
} else if (source instanceof AccessibleTextField) {
final AccessibleTextField accessibleTextField = (AccessibleTextField) source;
if (accessibleTextField.isModified()) {
dirty = true;
}
} else {
dirty = true;
}
})));
}
}
Aggregations