Search in sources :

Example 1 with FieldGroup

use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.

the class SymptomsForm method addSoftRequiredStyleWhenSymptomaticAndCooperative.

/**
 * 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.
 */
@SuppressWarnings("rawtypes")
private void addSoftRequiredStyleWhenSymptomaticAndCooperative(FieldGroup fieldGroup, Object targetPropertyId, List<String> sourcePropertyIds, List<Object> sourceValues, NullableOptionGroup 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.getNullableValue() == 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);
                }
            }
        });
    }
}
Also used : AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) AbstractField(com.vaadin.v7.ui.AbstractField)

Example 2 with FieldGroup

use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method discard.

@Override
public void discard() {
    if (fieldGroups != null) {
        for (FieldGroup fieldGroup : fieldGroups) {
            fieldGroup.discard();
        }
    } else if (wrappedComponent instanceof Buffered) {
        ((Buffered) wrappedComponent).discard();
    } else {
    // NOOP
    }
    dirty = false;
    onDiscard();
    onDone();
}
Also used : FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) Buffered(com.vaadin.v7.data.Buffered)

Example 3 with FieldGroup

use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method setWrappedComponent.

protected void setWrappedComponent(C component, FieldGroup... fieldGroups) {
    this.wrappedComponent = component;
    this.fieldGroups = new ArrayList(Arrays.asList(fieldGroups));
    if (contentPanel != null) {
        contentPanel.setContent(wrappedComponent);
        return;
    }
    setSpacing(false);
    setMargin(true);
    setSizeUndefined();
    contentPanel = new Panel(component);
    updateInternalWidth();
    updateInternalHeight();
    addComponent(contentPanel);
    setExpandRatio(contentPanel, 1);
    buttonsPanel = new HorizontalLayout();
    buttonsPanel.setMargin(false);
    buttonsPanel.setSpacing(true);
    buttonsPanel.setWidth(100, Unit.PERCENTAGE);
    Button discardButton = getDiscardButton();
    buttonsPanel.addComponent(discardButton);
    buttonsPanel.setComponentAlignment(discardButton, Alignment.BOTTOM_RIGHT);
    buttonsPanel.setExpandRatio(discardButton, 1);
    Button commitButton = getCommitButton();
    buttonsPanel.addComponent(commitButton);
    buttonsPanel.setComponentAlignment(commitButton, Alignment.BOTTOM_RIGHT);
    buttonsPanel.setExpandRatio(commitButton, 0);
    addComponent(buttonsPanel);
    setComponentAlignment(buttonsPanel, Alignment.BOTTOM_RIGHT);
    setShortcutsEnabled(shortcutsEnabled);
    if (fieldGroups != null && fieldGroups.length > 0) {
        // convention: set wrapper to read-only when all wrapped field groups are read-only
        boolean allReadOnly = true;
        for (FieldGroup fieldGroup : fieldGroups) {
            if (!fieldGroup.isReadOnly()) {
                allReadOnly = false;
                break;
            }
        }
        if (allReadOnly) {
            setReadOnly(true);
        }
    } else if (wrappedComponent != null) {
        if (wrappedComponent instanceof AbstractLegacyComponent && ((AbstractLegacyComponent) wrappedComponent).isReadOnly()) {
            setReadOnly(true);
        }
    }
    dirty = false;
    addDirtyHandler(fieldGroups);
}
Also used : Panel(com.vaadin.ui.Panel) Button(com.vaadin.ui.Button) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) ArrayList(java.util.ArrayList) AbstractLegacyComponent(com.vaadin.v7.ui.AbstractLegacyComponent) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Example 4 with FieldGroup

use of com.vaadin.v7.data.fieldgroup.FieldGroup in project SORMAS-Project by hzi-braunschweig.

the class CommitDiscardWrapperComponent method doCommit.

private void doCommit() throws InvalidValueException, SourceException, CommitRuntimeException {
    if (fieldGroups != null) {
        if (fieldGroups.size() > 1) {
            List<InvalidValueException> invalidValueExceptions = fieldGroups.stream().filter(fieldGroup -> !fieldGroup.isValid()).map(fieldGroup -> {
                try {
                    // all invalid fieldGroups are committed to fetch the CommitExceptions
                    fieldGroup.commit();
                } catch (CommitException e) {
                    return e;
                }
                // when the fieldGroup did not throw a CommitException, it is invalid and committed
                throw new IllegalStateException();
            }).map(e -> {
                // keep invalid value exceptions, throw the rest
                Throwable c = e.getCause();
                if (c instanceof InvalidValueException) {
                    return (InvalidValueException) c;
                } else if (c instanceof SourceException) {
                    throw (SourceException) c;
                } else {
                    throw new CommitRuntimeException(e);
                }
            }).collect(Collectors.toList());
            if (invalidValueExceptions.isEmpty()) {
            // NOOP
            } else if (invalidValueExceptions.size() == 1) {
                throw invalidValueExceptions.get(0);
            } else {
                throw new InvalidValueException(null, invalidValueExceptions.stream().map(InvalidValueException::getCauses).flatMap(Arrays::stream).toArray(InvalidValueException[]::new));
            }
        }
        try {
            for (FieldGroup fieldGroup : fieldGroups) {
                fieldGroup.commit();
            }
        } catch (CommitException e) {
            Throwable c = e.getCause();
            if (c instanceof InvalidValueException) {
                throw (InvalidValueException) c;
            } else if (c instanceof SourceException) {
                throw (SourceException) c;
            } else {
                throw new CommitRuntimeException(e);
            }
        }
    } else if (wrappedComponent instanceof Buffered) {
        ((Buffered) wrappedComponent).commit();
    } else {
    // NOOP
    }
    dirty = false;
    onCommit();
    commited = true;
    onDone();
}
Also used : InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) 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) AccessibleTextField(de.symeda.sormas.ui.location.AccessibleTextField) PersonDto(de.symeda.sormas.api.person.PersonDto) ArrayList(java.util.ArrayList) Buffered(com.vaadin.v7.data.Buffered) 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) CommitException(com.vaadin.v7.data.fieldgroup.FieldGroup.CommitException) FieldGroup(com.vaadin.v7.data.fieldgroup.FieldGroup) Buffered(com.vaadin.v7.data.Buffered)

Example 5 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) UserRole(de.symeda.sormas.api.user.UserRole) 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) 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)

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 List (java.util.List)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