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);
}
}
});
}
}
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();
}
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);
}
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();
}
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);
}
Aggregations