Search in sources :

Example 51 with Field

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());
            }
        }
    });
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) ReferenceDto(de.symeda.sormas.api.ReferenceDto) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto) Label(com.vaadin.ui.Label) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField) TaskDto(de.symeda.sormas.api.task.TaskDto) HorizontalLayout(com.vaadin.ui.HorizontalLayout) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) MarginInfo(com.vaadin.shared.ui.MarginInfo) TaskType(de.symeda.sormas.api.task.TaskType) TaskStatusValidator(de.symeda.sormas.ui.utils.TaskStatusValidator) Collection(java.util.Collection)

Example 52 with Field

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

Example 53 with Field

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

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

Example 55 with Field

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);
                }
            }
        });
    }
}
Also used : SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) AbstractField(com.vaadin.v7.ui.AbstractField) Field(com.vaadin.v7.ui.Field) AbstractField(com.vaadin.v7.ui.AbstractField)

Aggregations

TextField (com.vaadin.v7.ui.TextField)36 Field (com.vaadin.v7.ui.Field)34 ComboBox (com.vaadin.v7.ui.ComboBox)32 AbstractField (com.vaadin.v7.ui.AbstractField)23 DateField (com.vaadin.v7.ui.DateField)20 Label (com.vaadin.ui.Label)19 Disease (de.symeda.sormas.api.Disease)15 FacadeProvider (de.symeda.sormas.api.FacadeProvider)15 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)15 FieldVisibilityCheckers (de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers)15 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)15 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)14 Strings (de.symeda.sormas.api.i18n.Strings)14 AbstractEditForm (de.symeda.sormas.ui.utils.AbstractEditForm)14 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)14 FieldHelper (de.symeda.sormas.ui.utils.FieldHelper)14 LayoutUtil.fluidRowLocs (de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs)14 Collections (java.util.Collections)14 Button (com.vaadin.ui.Button)13 CssStyles (de.symeda.sormas.ui.utils.CssStyles)13