Search in sources :

Example 6 with FieldGroup

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);
}
Also used : Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) Spliterators(java.util.Spliterators) FacadeProvider(de.symeda.sormas.api.FacadeProvider) ComboBox(com.vaadin.ui.ComboBox) HasComponents(com.vaadin.ui.HasComponents) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DefaultFieldGroupFieldFactory(com.vaadin.v7.data.fieldgroup.DefaultFieldGroupFieldFactory) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) Diseases(de.symeda.sormas.api.utils.Diseases) Item(com.vaadin.v7.data.Item) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Collection(java.util.Collection) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Field(com.vaadin.v7.ui.Field) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) Stream(java.util.stream.Stream) Disease(de.symeda.sormas.api.Disease) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Collections(java.util.Collections) Spliterator(java.util.Spliterator) Component(com.vaadin.ui.Component) AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field)

Example 7 with FieldGroup

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");
            }
        }
    });
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) AbstractField(com.vaadin.v7.ui.AbstractField)

Example 8 with FieldGroup

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();
        }
    }
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field)

Example 9 with FieldGroup

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);
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field)

Example 10 with FieldGroup

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;
            }
        })));
    }
}
Also used : Panel(com.vaadin.ui.Panel) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Arrays(java.util.Arrays) ClickListener(com.vaadin.ui.Button.ClickListener) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) Notifier(com.vaadin.event.Action.Notifier) ArrayUtils(org.apache.commons.lang3.ArrayUtils) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) Buffered(com.vaadin.v7.data.Buffered) DeletionDetails(de.symeda.sormas.api.common.DeletionDetails) Notification(com.vaadin.ui.Notification) RichTextArea(com.vaadin.v7.ui.RichTextArea) Page(com.vaadin.server.Page) KeyCode(com.vaadin.event.ShortcutAction.KeyCode) AbstractLegacyComponent(com.vaadin.v7.ui.AbstractLegacyComponent) CannotProceedException(javax.naming.CannotProceedException) ValoTheme(com.vaadin.ui.themes.ValoTheme) LocationDto(de.symeda.sormas.api.location.LocationDto) ClickEvent(com.vaadin.ui.Button.ClickEvent) Collection(java.util.Collection) Field(com.vaadin.v7.ui.Field) EventDto(de.symeda.sormas.api.event.EventDto) InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) Collectors(java.util.stream.Collectors) Captions(de.symeda.sormas.api.i18n.Captions) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) List(java.util.List) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) Type(com.vaadin.ui.Notification.Type) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) HorizontalLayout(com.vaadin.ui.HorizontalLayout) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) TextArea(com.vaadin.v7.ui.TextArea) CommitException(com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException) Descriptions(de.symeda.sormas.api.i18n.Descriptions) Objects.nonNull(java.util.Objects.nonNull) Strings(de.symeda.sormas.api.i18n.Strings) Component(com.vaadin.ui.Component) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonEditForm(de.symeda.sormas.ui.person.PersonEditForm) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) EventDataForm(de.symeda.sormas.ui.events.EventDataForm) Buffered(com.vaadin.v7.data.Buffered)

Aggregations

FieldGroup (com.vaadin.v7.data.fieldgroup.FieldGroup)7 Field (com.vaadin.v7.ui.Field)7 AbstractField (com.vaadin.v7.ui.AbstractField)5 ArrayList (java.util.ArrayList)4 Button (com.vaadin.ui.Button)3 Component (com.vaadin.ui.Component)3 HorizontalLayout (com.vaadin.ui.HorizontalLayout)3 Panel (com.vaadin.ui.Panel)3 Buffered (com.vaadin.v7.data.Buffered)3 AbstractLegacyComponent (com.vaadin.v7.ui.AbstractLegacyComponent)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Notifier (com.vaadin.event.Action.Notifier)2 KeyCode (com.vaadin.event.ShortcutAction.KeyCode)2 Page (com.vaadin.server.Page)2 Alignment (com.vaadin.ui.Alignment)2 ClickEvent (com.vaadin.ui.Button.ClickEvent)2 ClickListener (com.vaadin.ui.Button.ClickListener)2 Notification (com.vaadin.ui.Notification)2 Type (com.vaadin.ui.Notification.Type)2