use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class TaskEditForm method addFields.
@Override
protected void addFields() {
addField(TaskDto.CAZE, ComboBox.class);
addField(TaskDto.EVENT, ComboBox.class);
addField(TaskDto.CONTACT, ComboBox.class);
DateTimeField startDate = addDateField(TaskDto.SUGGESTED_START, DateTimeField.class, -1);
DateTimeField dueDate = addDateField(TaskDto.DUE_DATE, DateTimeField.class, -1);
dueDate.setImmediate(true);
addField(TaskDto.PRIORITY, ComboBox.class);
NullableOptionGroup taskStatus = addField(TaskDto.TASK_STATUS, NullableOptionGroup.class);
NullableOptionGroup taskContext = addField(TaskDto.TASK_CONTEXT, NullableOptionGroup.class);
taskContext.setImmediate(true);
taskContext.addValueChangeListener(event -> updateByTaskContext());
ComboBox taskTypeField = addField(TaskDto.TASK_TYPE, ComboBox.class);
taskTypeField.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
taskTypeField.setImmediate(true);
taskTypeField.addValueChangeListener(e -> {
TaskType taskType = (TaskType) e.getProperty().getValue();
if (taskType != null) {
setRequired(taskType.isCreatorCommentRequired(), TaskDto.CREATOR_COMMENT);
}
});
ComboBox assigneeUser = addField(TaskDto.ASSIGNEE_USER, ComboBox.class);
assigneeUser.addValueChangeListener(e -> {
updateObserversList();
updateByCreatingAndAssignee();
checkIfUserEmailOrPhoneIsProvided((UserReferenceDto) e.getProperty().getValue(), Strings.infoAssigneeMissingEmail, Strings.infoAssigneeMissingEmailOrPhoneNumber, ASSIGNEE_MISSING_INFO);
});
assigneeUser.setImmediate(true);
TextArea creatorComment = addField(TaskDto.CREATOR_COMMENT, TextArea.class);
creatorComment.setRows(2);
creatorComment.setImmediate(true);
addField(TaskDto.ASSIGNEE_REPLY, TextArea.class).setRows(4);
MultiSelect<UserReferenceDto> observerUsers = addField(TaskDto.OBSERVER_USERS, MultiSelect.class);
observerUsers.addValueChangeListener(e -> {
Collection<UserReferenceDto> userReferences = (Collection<UserReferenceDto>) e.getProperty().getValue();
for (UserReferenceDto userReference : userReferences) {
checkIfUserEmailOrPhoneIsProvided(userReference, Strings.infoObserverMissingEmail, Strings.infoObserverMissingEmailOrPhoneNumber, OBSERVER_MISSING_INFO);
}
});
observerUsers.setImmediate(true);
CssStyles.style(observerUsers, CssStyles.OPTIONGROUP_MAX_HEIGHT_150);
setRequired(true, TaskDto.TASK_CONTEXT, TaskDto.TASK_TYPE, TaskDto.ASSIGNEE_USER, TaskDto.DUE_DATE, TaskDto.TASK_STATUS);
setReadOnly(true, TaskDto.TASK_CONTEXT, TaskDto.CAZE, TaskDto.CONTACT, TaskDto.EVENT);
addValueChangeListener(e -> {
TaskDto taskDto = getValue();
if (taskDto.getTaskType() == TaskType.CASE_INVESTIGATION && taskDto.getCaze() != null) {
taskStatus.addValidator(new TaskStatusValidator(taskDto.getCaze().getUuid(), I18nProperties.getValidationError(Validations.investigationStatusUnclassifiedCase)));
if (!editedFromTaskGrid) {
final HorizontalLayout saveInfoLayout = new HorizontalLayout(new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + I18nProperties.getString(Strings.infoSaveOfTask), ContentMode.HTML));
saveInfoLayout.setSpacing(true);
saveInfoLayout.setMargin(new MarginInfo(true, false, true, false));
getContent().addComponent(saveInfoLayout, SAVE_INFO);
}
}
final UserDto userDto = UserProvider.getCurrent().getUser();
availableUsers = new ArrayList<>();
if (taskDto.getCaze() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingCaseInJurisdiction(taskDto.getCaze()));
} else if (taskDto.getContact() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingContactInJurisdiction(taskDto.getContact()));
} else if (taskDto.getEvent() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingEventInJurisdiction(taskDto.getEvent()));
} else if (taskDto.getTravelEntry() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingTravelEntryInJurisdiction(taskDto.getTravelEntry()));
} else {
availableUsers.addAll(FacadeProvider.getUserFacade().getAllUserRefs(false));
}
// For national users, there is no higher level
if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.ASSIGN_TASKS_TO_HIGHER_LEVEL) && UserRole.getJurisdictionLevel(userDto.getUserRoles()) != JurisdictionLevel.NATION) {
List<UserReferenceDto> superordinateUsers = FacadeProvider.getUserFacade().getUsersWithSuperiorJurisdiction(userDto);
if (superordinateUsers != null) {
availableUsers.addAll(superordinateUsers);
}
}
// Validation
startDate.addValidator(new DateComparisonValidator(startDate, dueDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, startDate.getCaption(), dueDate.getCaption())));
dueDate.addValidator(new DateComparisonValidator(dueDate, startDate, false, false, I18nProperties.getValidationError(Validations.afterDate, dueDate.getCaption(), startDate.getCaption())));
Map<String, Long> userTaskCounts = FacadeProvider.getTaskFacade().getPendingTaskCountPerUser(availableUsers.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
for (UserReferenceDto user : availableUsers) {
assigneeUser.addItem(user);
Long userTaskCount = userTaskCounts.get(user.getUuid());
assigneeUser.setItemCaption(user, user.getCaption() + " (" + (userTaskCount != null ? userTaskCount.toString() : "0") + ")");
if (!user.equals(assigneeUser.getValue())) {
// If a user has been assigned to the task, do not make it available for observers field
observerUsers.addItem(user);
observerUsers.setItemCaption(user, user.getCaption());
}
}
});
}
use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class AbstractEditForm method addDiseaseField.
/**
* Adds the field to the form by using addField(fieldId, fieldType), but additionally sets up a ValueChangeListener
* that makes sure the value that is about to be selected is added to the list of allowed values. This is intended
* to be used for Disease fields that might contain a disease that is no longer active in the system and thus will
* not be returned by DiseaseHelper.isActivePrimaryDisease(disease).
*
* @param showNonPrimaryDiseases
* Whether or not diseases that have been configured as non-primary should be included
* @param setServerDiseaseAsDefault
* If only a single diseases is active on the server, set it as the default value
*/
@SuppressWarnings("unchecked")
protected ComboBox addDiseaseField(String fieldId, boolean showNonPrimaryDiseases, boolean setServerDiseaseAsDefault) {
diseaseField = addField(fieldId, ComboBox.class);
this.setServerDiseaseAsDefault = setServerDiseaseAsDefault;
if (showNonPrimaryDiseases) {
addNonPrimaryDiseasesTo(diseaseField);
}
if (setServerDiseaseAsDefault) {
setDefaultDiseaseValue();
}
// Make sure that the ComboBox still contains a pre-selected inactive disease
diseaseField.addValueChangeListener(e -> {
Object value = e.getProperty().getValue();
if (value != null && !diseaseField.containsId(value)) {
Item newItem = diseaseField.addItem(value);
newItem.getItemProperty(SormasFieldGroupFieldFactory.CAPTION_PROPERTY_ID).setValue(value.toString());
}
});
return diseaseField;
}
use of com.vaadin.v7.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class AbstractForm method addField.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <F extends Field> F addField(CustomLayout layout, FieldConfiguration configuration) {
Field field = addField(layout, configuration.getPropertyId());
applyFieldConfiguration(configuration, field);
return (F) field;
}
use of com.vaadin.v7.ui.Field 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.ui.Field in project SORMAS-Project by hzi-braunschweig.
the class FieldHelper method setRequiredWhen.
@SuppressWarnings("rawtypes")
public static void setRequiredWhen(Field sourceField, List<? extends Field<?>> targetFields, List<?> sourceValues, boolean requiredWhenNot, Disease disease) {
if (sourceField != null) {
if (sourceField instanceof AbstractField<?>) {
((AbstractField) sourceField).setImmediate(true);
}
// initialize
{
boolean required = sourceValues.contains(getNullableSourceFieldValue(sourceField));
for (Field targetField : targetFields) {
if (!targetField.isVisible()) {
targetField.setRequired(false);
continue;
}
if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class, targetField.getId(), disease)) {
targetField.setRequired(required);
}
}
}
sourceField.addValueChangeListener(event -> {
boolean required = sourceValues.contains(getNullableSourceFieldValue(((Field) event.getProperty())));
required = required != requiredWhenNot;
for (Field targetField : targetFields) {
if (!targetField.isVisible()) {
targetField.setRequired(false);
continue;
}
if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class, targetField.getId(), disease)) {
targetField.setRequired(required);
}
}
});
}
}
Aggregations