Search in sources :

Example 36 with TextArea

use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.

the class ResetableTextWatcher method edit.

/**
 * Entry point for using this class
 * @param impl The current running activity
 * @param component Any subclass of com.codename1.ui.TextArea
 * @param inputType One of the TextArea's input-type constants
 */
public static void edit(final AndroidImplementation impl, final Component component, final int inputType) {
    if (impl.getActivity() == null) {
        throw new IllegalArgumentException("activity is null");
    }
    if (component == null) {
        throw new IllegalArgumentException("component is null");
    }
    if (!(component instanceof TextArea)) {
        throw new IllegalArgumentException("component must be instance of TextArea");
    }
    final TextArea textArea = (TextArea) component;
    textArea.registerAsInputDevice();
    final String initialText = textArea.getText();
    textArea.putClientProperty("InPlaceEditView.initialText", initialText);
    // The very first time we try to edit a string, let's determine if the
    // system default is to do async editing.  If the system default
    // is not yet set, we set it here, and it will be used as the default from now on
    // We do this because the nativeInstance.isAsyncEditMode() value changes
    // to reflect the currently edited field so it isn't a good way to keep a
    // system default.
    String defaultAsyncEditingSetting = Display.getInstance().getProperty("android.VKBAlwaysOpen", null);
    if (defaultAsyncEditingSetting == null) {
        defaultAsyncEditingSetting = impl.isAsyncEditMode() ? "true" : "false";
        Display.getInstance().setProperty("android.VKBAlwaysOpen", defaultAsyncEditingSetting);
    }
    boolean asyncEdit = "true".equals(defaultAsyncEditingSetting) ? true : false;
    // Check if the form has any setting for asyncEditing that should override
    // the application defaults.
    final Form parentForm = component.getComponentForm();
    if (parentForm == null) {
        com.codename1.io.Log.p("Attempt to edit text area that is not on a form.  This is not supported");
        return;
    }
    if (parentForm.getClientProperty("asyncEditing") != null) {
        Object async = parentForm.getClientProperty("asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Form overriding asyncEdit due to asyncEditing client property: "+asyncEdit);
        }
    }
    if (parentForm.getClientProperty("android.asyncEditing") != null) {
        Object async = parentForm.getClientProperty("android.asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Form overriding asyncEdit due to ios.asyncEditing client property: "+asyncEdit);
        }
    }
    if (parentForm.isFormBottomPaddingEditingMode()) {
        asyncEdit = true;
    }
    // then this will override all other settings.
    if (component.getClientProperty("asyncEditing") != null) {
        Object async = component.getClientProperty("asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Overriding asyncEdit due to field asyncEditing client property: "+asyncEdit);
        }
    }
    if (component.getClientProperty("android.asyncEditing") != null) {
        Object async = component.getClientProperty("android.asyncEditing");
        if (async instanceof Boolean) {
            asyncEdit = ((Boolean) async).booleanValue();
        // Log.p("Overriding asyncEdit due to field ios.asyncEditing client property: "+asyncEdit);
        }
    }
    final boolean resizeEditMode = "resize".equalsIgnoreCase(String.valueOf(component.getClientProperty("android.editMode")));
    final boolean panEditMode = "pan".equalsIgnoreCase(String.valueOf(component.getClientProperty("android.editMode")));
    // if true, then in async mode we are currently editing and are switching to another field
    final boolean isEditedFieldSwitch;
    // If we are already editing, we need to finish that up before we proceed to edit the next field.
    synchronized (editingLock) {
        if (mIsEditing) {
            if (impl.isAsyncEditMode()) {
                // Using isEditedFieldSwitch was causing issues with cursors not showing up.
                // https://github.com/codenameone/CodenameOne/issues/2353
                // https://stackoverflow.com/questions/49004370/focus-behaviour-in-textarea-in-cn1
                // Disabling this feature by default now, but can be re-enabled by setting
                // Display.getInstance().setProperty("android.reuseTextEditorOnSwitch", "true");
                // This editedFieldSwitch feature was added a while back to improve experience on older
                // Android devices where the field switching was going too slow.
                // https://github.com/codenameone/CodenameOne/issues/2012
                // This issue was resolved in this commit (https://github.com/jaanushansen/CodenameOne/commit/f3e53a80704149e4d7cde276d01c1368bcdcfe2c)
                // which was submitted as part of a pull request.  This fix has been the source of several
                // regressions, mostly related to properties not being propagated properly when a text field is changed
                // However, this issue (with the cursor not showing up), doesn't appear to have a simple solution
                // so, I'm disabling this feature for now.
                isEditedFieldSwitch = "true".equals(Display.getInstance().getProperty("android.reuseTextEditorOnSwitch", "false"));
                final String[] out = new String[1];
                TextArea prevTextArea = null;
                if (sInstance != null && sInstance.mLastEditText != null) {
                    prevTextArea = sInstance.mLastEditText.getTextArea();
                }
                if (prevTextArea != null) {
                    final TextArea fPrevTextArea = prevTextArea;
                    final String retVal = sInstance.mLastEditText.getText().toString();
                    Display.getInstance().callSerially(new Runnable() {

                        public void run() {
                            Display.getInstance().onEditingComplete(fPrevTextArea, retVal);
                            textArea.requestFocus();
                        }
                    });
                }
                InPlaceEditView.setEditedTextField(textArea);
                nextTextArea = null;
            } else {
                isEditedFieldSwitch = false;
                final InPlaceEditView instance = sInstance;
                if (instance != null && instance.mEditText != null && instance.mEditText.mTextArea == textArea) {
                    instance.showTextEditorAgain();
                    return;
                }
                if (!isClosing && sInstance != null && sInstance.mEditText != null) {
                    isClosing = true;
                    impl.getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            instance.endEditing(REASON_UNDEFINED, true, 0);
                        }
                    });
                }
                afterClose = new Runnable() {

                    @Override
                    public void run() {
                        impl.callHideTextEditor();
                        Display.getInstance().editString(component, textArea.getMaxSize(), inputType, textArea.getText());
                    }
                };
                return;
            }
        } else {
            isEditedFieldSwitch = false;
        }
        mIsEditing = true;
        isClosing = false;
        afterClose = null;
    }
    impl.setAsyncEditMode(asyncEdit);
    // textArea.setPreferredSize(prefSize);
    if (!impl.isAsyncEditMode() && textArea instanceof TextField) {
        ((TextField) textArea).setEditable(false);
    }
    final boolean scrollableParent = isScrollableParent(textArea);
    // We wrap the text area so that we can safely pass data across to the
    // android UI thread.
    final TextAreaData textAreaData = new TextAreaData(textArea);
    impl.getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (!isEditedFieldSwitch) {
                releaseEdit();
                if (sInstance == null) {
                    sInstance = new InPlaceEditView(impl);
                    impl.relativeLayout.addView(sInstance);
                }
            // Let's try something new here
            // We'll ALWAYS try resize edit mode (since it just works better)
            // But we'll detect whether the field is still covered by the keyboard
            // and switch to pan mode if necessary.
            }
            if (panEditMode) {
                setEditMode(false);
            } else if (resizeEditMode) {
                setEditMode(true);
            } else if (parentForm.isFormBottomPaddingEditingMode()) {
                setEditMode(true);
            } else if (scrollableParent) {
                setEditMode(false);
            } else {
                trySetEditMode(true);
            }
            sInstance.startEditing(impl.getActivity(), textAreaData, initialText, inputType, isEditedFieldSwitch);
        }
    });
    final String[] out = new String[1];
    // In case the contents of the text area are changed while editing is in progress
    // we should propagate the changes to the native text field.
    final DataChangedListener textAreaDataChanged = new DataChangedListener() {

        @Override
        public void dataChanged(int type, int index) {
            if (suppressDataChangedEvent) {
                // https://github.com/codenameone/CodenameOne/issues/3343
                return;
            }
            TextArea currTextArea = getCurrentTextArea();
            if (currTextArea != textArea) {
                // This is not the active text area anymore
                textArea.removeDataChangedListener(this);
                return;
            }
            final String newText = textArea.getText();
            EditView currEditView = getCurrentEditView();
            if (currEditView == null || currEditView.mTextArea != textArea) {
                textArea.removeDataChangedListener(this);
                return;
            }
            String existingText = currEditView.getText().toString();
            // because Objects.equals was not available until API 19
            if (!com.codename1.compat.java.util.Objects.equals(newText, existingText)) {
                impl.getActivity().runOnUiThread(new Runnable() {

                    public void run() {
                        TextArea currTextArea = getCurrentTextArea();
                        EditView currEditView = getCurrentEditView();
                        if (currTextArea != textArea || currEditView == null || currEditView.mTextArea != textArea) {
                            return;
                        }
                        String existingText = currEditView.getText().toString();
                        // because Objects.equals was not available until API 19
                        if (!com.codename1.compat.java.util.Objects.equals(newText, existingText)) {
                            // We need to suppress the Android text change events
                            // to prevent weird things from happening.  E.g. https://github.com/codenameone/CodenameOne/issues/3349
                            suppressTextChangeEvent = true;
                            currEditView.setText(newText);
                            suppressTextChangeEvent = false;
                        }
                    }
                });
            }
        }
    };
    textArea.addDataChangedListener(textAreaDataChanged);
    // In order to reuse the code the runs after edit completion, we will wrap it in a runnable
    // For sync edit mode, we will just run onComplete.run() at the end of this method.  For
    // Async mode we add the Runnable to the textarea as a client property, then run it
    // when editing eventually completes.
    Runnable onComplete = new Runnable() {

        public void run() {
            textArea.removeDataChangedListener(textAreaDataChanged);
            if (!impl.isAsyncEditMode() && textArea instanceof TextField) {
                ((TextField) textArea).setEditable(true);
            }
            textArea.setPreferredSize(null);
            if (sInstance != null && sInstance.mLastEditText != null && sInstance.mLastEditText.mTextArea == textArea) {
                String retVal = sInstance.mLastEditText.getText().toString();
                if (!impl.isAsyncEditMode()) {
                    sInstance.mLastEditText = null;
                    impl.getActivity().runOnUiThread(new Runnable() {

                        public void run() {
                            releaseEdit();
                        }
                    });
                }
                out[0] = retVal;
            } else {
                out[0] = initialText;
            }
            Display.getInstance().onEditingComplete(component, out[0]);
            if (impl.isAsyncEditMode()) {
                impl.callHideTextEditor();
            } else {
                // lock.
                if (sInstance != null) {
                    Display.getInstance().invokeAndBlock(new Runnable() {

                        public void run() {
                            while (sInstance != null) {
                                com.codename1.io.Util.sleep(5);
                            }
                        }
                    });
                }
            }
            // Release the editing flag
            synchronized (editingLock) {
                mIsEditing = false;
            }
            // as a runnable ... this should take priority over the "nextTextArea" setting
            if (afterClose != null) {
                Display.getInstance().callSerially(afterClose);
            } else if (nextTextArea != null) {
                final TextArea next = nextTextArea;
                nextTextArea = null;
                next.requestFocus();
                Display.getInstance().callSerially(new Runnable() {

                    public void run() {
                        Display.getInstance().editString(next, next.getMaxSize(), next.getConstraint(), next.getText());
                    }
                });
            }
        }
    };
    textArea.requestFocus();
    textArea.repaint();
    if (impl.isAsyncEditMode()) {
        component.putClientProperty("android.onAsyncEditingComplete", onComplete);
        return;
    }
    // Make this call synchronous
    // We set this flag so that waitForEditCompletion can block on it.
    // The flag will be released inside the endEditing method which will
    // allow the method to proceed.
    waitingForSynchronousEditingCompletion = true;
    waitForEditCompletion();
    onComplete.run();
}
Also used : TextArea(com.codename1.ui.TextArea) Form(com.codename1.ui.Form) DataChangedListener(com.codename1.ui.events.DataChangedListener) TextField(com.codename1.ui.TextField)

Example 37 with TextArea

use of com.vaadin.v7.ui.TextArea in project CodenameOne by codenameone.

the class ResetableTextWatcher method scrollActiveTextfieldToVisible.

static void scrollActiveTextfieldToVisible() {
    if (isEditing() && sInstance != null) {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                if (sInstance != null && sInstance.mEditText != null && sInstance.mEditText.mTextArea != null) {
                    TextArea ta = sInstance.mEditText.mTextArea;
                    if (isScrollableParent(ta)) {
                        ta.scrollRectToVisible(0, 0, ta.getWidth(), ta.getHeight(), ta);
                        ta.getComponentForm().getAnimationManager().flushAnimation(new Runnable() {

                            @Override
                            public void run() {
                                reLayoutEdit();
                            }
                        });
                    }
                }
            }
        };
    }
}
Also used : TextArea(com.codename1.ui.TextArea)

Example 38 with TextArea

use of com.vaadin.v7.ui.TextArea in project SORMAS-Project by hzi-braunschweig.

the class HealthConditionsForm method addFields.

@Override
protected void addFields() {
    Label healthConditionsHeadingLabel = new Label(I18nProperties.getString(Strings.headingHealthConditions));
    healthConditionsHeadingLabel.addStyleName(H3);
    getContent().addComponent(healthConditionsHeadingLabel, HEALTH_CONDITIONS_HEADINGS_LOC);
    addFields(TUBERCULOSIS, ASPLENIA, HEPATITIS, DIABETES, HIV, HIV_ART, CHRONIC_LIVER_DISEASE, MALIGNANCY_CHEMOTHERAPY, CHRONIC_HEART_FAILURE, CHRONIC_PULMONARY_DISEASE, CHRONIC_KIDNEY_DISEASE, CHRONIC_NEUROLOGIC_CONDITION, DOWN_SYNDROME, CONGENITAL_SYPHILIS, IMMUNODEFICIENCY_OTHER_THAN_HIV, CARDIOVASCULAR_DISEASE_INCLUDING_HYPERTENSION, OBESITY, CURRENT_SMOKER, FORMER_SMOKER, ASTHMA, SICKLE_CELL_DISEASE, IMMUNODEFICIENCY_INCLUDING_HIV);
    TextArea otherConditions = addField(OTHER_CONDITIONS, TextArea.class);
    otherConditions.setRows(6);
    otherConditions.setDescription(I18nProperties.getPrefixDescription(HealthConditionsDto.I18N_PREFIX, OTHER_CONDITIONS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    FieldHelper.setVisibleWhen(getFieldGroup(), HIV_ART, HIV, Arrays.asList(YesNoUnknown.YES), true);
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) Label(com.vaadin.ui.Label)

Example 39 with TextArea

use of com.vaadin.v7.ui.TextArea in project SORMAS-Project by hzi-braunschweig.

the class PersonEditForm method addFields.

@Override
protected void addFields() {
    personInformationHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonInformation));
    personInformationHeadingLabel.addStyleName(H3);
    getContent().addComponent(personInformationHeadingLabel, PERSON_INFORMATION_HEADING_LOC);
    addField(PersonDto.UUID).setReadOnly(true);
    firstNameField = addField(PersonDto.FIRST_NAME, TextField.class);
    lastNameField = addField(PersonDto.LAST_NAME, TextField.class);
    addFields(PersonDto.SALUTATION, PersonDto.OTHER_SALUTATION);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.OTHER_SALUTATION, PersonDto.SALUTATION, Salutation.OTHER, true);
    ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
    addField(PersonDto.BIRTH_NAME, TextField.class);
    addField(PersonDto.NICKNAME, TextField.class);
    addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
    addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
    addFields(PersonDto.NAMES_OF_GUARDIANS);
    ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
    birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateDay.setNullSelectionAllowed(true);
    birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
    birthDateDay.setCaption("");
    ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateMonth.setNullSelectionAllowed(true);
    birthDateMonth.addItems(DateHelper.getMonthsInYear());
    birthDateMonth.setPageLength(12);
    birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
    birthDateMonth.setCaption("");
    setItemCaptionsForMonths(birthDateMonth);
    ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, ComboBox.class);
    birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
    // @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
    birthDateYear.setNullSelectionAllowed(true);
    birthDateYear.addItems(DateHelper.getYearsToNow());
    birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
    birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
    birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
    birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
    birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
    DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
    TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
    approximateAgeField.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, approximateAgeField.getCaption()));
    ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
    addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);
    approximateAgeField.addValidator(new ApproximateAgeValidator(approximateAgeField, approximateAgeTypeField, I18nProperties.getValidationError(Validations.softApproximateAgeTooHigh)));
    TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
    tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfGestationAgeAtBirth.getCaption()));
    TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
    tfBirthWeight.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfBirthWeight.getCaption()));
    AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
    deathPlaceType.setNullSelectionAllowed(true);
    TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
    DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
    TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
    ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
    addressForm = addField(PersonDto.ADDRESS, LocationEditForm.class);
    addressForm.setCaption(null);
    addField(PersonDto.ADDRESSES, LocationsField.class).setCaption(null);
    PersonContactDetailsField personContactDetailsField = addField(PersonDto.PERSON_CONTACT_DETAILS, PersonContactDetailsField.class);
    personContactDetailsField.setThisPerson(getValue());
    personContactDetailsField.setCaption(null);
    personContactDetailsField.setPseudonymized(isPseudonymized);
    addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.ARMED_FORCES_RELATION_TYPE, PersonDto.EDUCATION_TYPE, PersonDto.EDUCATION_DETAILS);
    List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getAllActiveAsReference();
    addInfrastructureField(PersonDto.BIRTH_COUNTRY).addItems(countries);
    addInfrastructureField(PersonDto.CITIZENSHIP).addItems(countries);
    addFields(PersonDto.PASSPORT_NUMBER, PersonDto.NATIONAL_HEALTH_ID);
    Field externalId = addField(PersonDto.EXTERNAL_ID);
    if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
        externalId.setEnabled(false);
    }
    TextField externalTokenField = addField(PersonDto.EXTERNAL_TOKEN);
    Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messagePersonExternalTokenWarning));
    externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
    getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
    addField(PersonDto.INTERNAL_TOKEN);
    addField(PersonDto.HAS_COVID_APP).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    addField(PersonDto.COVID_CODE_DELIVERED).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
    if (personContext != PersonContext.CASE) {
        setVisible(false, PersonDto.HAS_COVID_APP, PersonDto.COVID_CODE_DELIVERED);
    }
    ComboBox cbPlaceOfBirthRegion = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_REGION);
    ComboBox cbPlaceOfBirthDistrict = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_DISTRICT);
    ComboBox cbPlaceOfBirthCommunity = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_COMMUNITY);
    ComboBox placeOfBirthFacilityType = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_TYPE);
    FieldHelper.removeItems(placeOfBirthFacilityType);
    placeOfBirthFacilityType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
    placeOfBirthFacilityType.addItems(FacilityType.getPlaceOfBirthTypes());
    cbPlaceOfBirthFacility = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_FACILITY);
    TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS, TextField.class);
    causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
    causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
    causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
    // Set requirements that don't need visibility changes and read only status
    setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
    setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
    setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE, PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION, PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS, PersonDto.CAUSE_OF_DEATH_DISEASE);
    FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE, Arrays.asList(EducationType.OTHER), true);
    FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType, causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc, burialConductor);
    // Set initial visibilities
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.ARMED_FORCES_RELATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
        occupationHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESS).isVisible())
        addressHeader.setVisible(false);
    if (!getField(PersonDto.ADDRESSES).isVisible())
        addressesHeader.setVisible(false);
    // Add listeners
    FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE, PersonDto.APPROXIMATE_AGE_TYPE);
    addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
        @SuppressWarnings("unchecked") Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(PersonDto.APPROXIMATE_AGE_TYPE);
        if (!ageTypeField.isReadOnly()) {
            if (e.getProperty().getValue() == null) {
                ageTypeField.clear();
            } else {
                if (ageTypeField.isEmpty()) {
                    ageTypeField.setValue(ApproximateAgeType.YEARS);
                }
            }
        }
    });
    addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
        updateApproximateAge();
        updateReadyOnlyApproximateAge();
    });
    addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
    addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
        updateOccupationFieldCaptions();
        toggleOccupationMetaFields();
    });
    addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity, placeOfBirthFacilityType, cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails, true);
    cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
    this.presentConditionChangeListener = new PresentConditionChangeListener();
    addFieldListeners(PersonDto.PRESENT_CONDITION, presentConditionChangeListener);
    causeOfDeathField.addValueChangeListener(e -> {
        boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
        toggleCauseOfDeathFields(causeOfDeathVisible);
    });
    causeOfDeathDiseaseField.addValueChangeListener(e -> {
        boolean causeOfDeathVisible = presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != PresentCondition.UNKNOWN && presentCondition.getValue() != null;
        toggleCauseOfDeathFields(causeOfDeathVisible);
    });
    addValueChangeListener(e -> fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc));
    deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(), birthDateYear.getCaption())));
    deathDate.addValidator(new DateComparisonValidator(deathDate, burialDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, deathDate.getCaption(), burialDate.getCaption())));
    deathDate.addValueChangeListener(value -> {
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    burialDate.addValidator(new DateComparisonValidator(burialDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), birthDateYear.getCaption())));
    burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));
    burialDate.addValueChangeListener(b -> {
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    // Update the list of days according to the selected month and year
    birthDateYear.addValueChangeListener(e -> {
        updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
        birthDateMonth.markAsDirty();
        birthDateDay.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    birthDateMonth.addValueChangeListener(e -> {
        updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
        birthDateYear.markAsDirty();
        birthDateDay.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    birthDateDay.addValueChangeListener(e -> {
        birthDateYear.markAsDirty();
        birthDateMonth.markAsDirty();
        deathDate.setValidationVisible(!deathDate.isValid());
        burialDate.setValidationVisible(!burialDate.isValid());
    });
    addValueChangeListener((e) -> {
        ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getPersonFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
        personContactDetailsField.setThisPerson((PersonDto) e.getProperty().getValue());
    });
    Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS));
    generalCommentLabel.addStyleName(H3);
    getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
    TextArea additionalDetails = addField(PersonDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>(false));
    additionalDetails.setRows(6);
    additionalDetails.setDescription(I18nProperties.getPrefixDescription(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
}
Also used : TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) Label(com.vaadin.ui.Label) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) DateComparisonValidator(de.symeda.sormas.ui.utils.DateComparisonValidator) Field(com.vaadin.v7.ui.Field) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) ApproximateAgeType(de.symeda.sormas.api.person.ApproximateAgeType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) TextField(com.vaadin.v7.ui.TextField) DateField(com.vaadin.v7.ui.DateField) LocationEditForm(de.symeda.sormas.ui.location.LocationEditForm) ApproximateAgeValidator(de.symeda.sormas.ui.utils.ApproximateAgeValidator)

Example 40 with TextArea

use of com.vaadin.v7.ui.TextArea in project SORMAS-Project by hzi-braunschweig.

the class AbstractSampleForm method addCommonFields.

protected void addCommonFields() {
    final NullableOptionGroup samplePurpose = addField(SampleDto.SAMPLE_PURPOSE, NullableOptionGroup.class);
    addField(SampleDto.UUID).setReadOnly(true);
    addField(SampleDto.REPORTING_USER).setReadOnly(true);
    samplePurpose.addValueChangeListener(e -> updateRequestedTestFields());
    addField(SampleDto.LAB_SAMPLE_ID, TextField.class);
    final DateTimeField sampleDateField = addField(SampleDto.SAMPLE_DATE_TIME, DateTimeField.class);
    sampleDateField.setInvalidCommitted(false);
    addField(SampleDto.SAMPLE_MATERIAL, ComboBox.class);
    addField(SampleDto.SAMPLE_MATERIAL_TEXT, TextField.class);
    addField(SampleDto.SAMPLE_SOURCE, ComboBox.class);
    addField(SampleDto.FIELD_SAMPLE_ID, TextField.class);
    addDateField(SampleDto.SHIPMENT_DATE, DateField.class, 7);
    addField(SampleDto.SHIPMENT_DETAILS, TextField.class);
    addField(SampleDto.RECEIVED_DATE, DateField.class);
    final ComboBox lab = addInfrastructureField(SampleDto.LAB);
    lab.addItems(FacadeProvider.getFacilityFacade().getAllActiveLaboratories(true));
    final TextField labDetails = addField(SampleDto.LAB_DETAILS, TextField.class);
    labDetails.setVisible(false);
    lab.addValueChangeListener(event -> updateLabDetailsVisibility(labDetails, event));
    addField(SampleDto.SPECIMEN_CONDITION, ComboBox.class);
    addField(SampleDto.NO_TEST_POSSIBLE_REASON, TextField.class);
    TextArea comment = addField(SampleDto.COMMENT, TextArea.class);
    comment.setRows(4);
    comment.setDescription(I18nProperties.getPrefixDescription(SampleDto.I18N_PREFIX, SampleDto.COMMENT, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
    addField(SampleDto.SHIPPED, CheckBox.class);
    addField(SampleDto.RECEIVED, CheckBox.class);
    ComboBox testResultField = addField(SampleDto.PATHOGEN_TEST_RESULT, ComboBox.class);
    testResultField.removeItem(PathogenTestResultType.NOT_DONE);
    addFields(SampleDto.SAMPLING_REASON, SampleDto.SAMPLING_REASON_DETAILS);
    FieldHelper.setVisibleWhen(getFieldGroup(), SampleDto.SAMPLING_REASON_DETAILS, SampleDto.SAMPLING_REASON, Collections.singletonList(SamplingReason.OTHER_REASON), true);
    addField(SampleDto.DELETION_REASON);
    addField(SampleDto.OTHER_DELETION_REASON, TextArea.class).setRows(3);
    setVisible(false, SampleDto.DELETION_REASON, SampleDto.OTHER_DELETION_REASON);
}
Also used : NullableOptionGroup(de.symeda.sormas.ui.utils.NullableOptionGroup) TextArea(com.vaadin.v7.ui.TextArea) ComboBox(com.vaadin.v7.ui.ComboBox) TextField(com.vaadin.v7.ui.TextField) DateTimeField(de.symeda.sormas.ui.utils.DateTimeField)

Aggregations

TextArea (com.codename1.ui.TextArea)60 Form (com.codename1.ui.Form)23 Component (com.codename1.ui.Component)21 Button (com.codename1.ui.Button)16 Label (com.codename1.ui.Label)16 TextArea (com.vaadin.v7.ui.TextArea)15 Container (com.codename1.ui.Container)13 BorderLayout (com.codename1.ui.layouts.BorderLayout)12 Label (com.vaadin.ui.Label)11 ComboBox (com.vaadin.v7.ui.ComboBox)10 TextField (com.codename1.ui.TextField)9 DateComparisonValidator (de.symeda.sormas.ui.utils.DateComparisonValidator)9 DateField (com.vaadin.v7.ui.DateField)8 TextField (com.vaadin.v7.ui.TextField)8 NullableOptionGroup (de.symeda.sormas.ui.utils.NullableOptionGroup)7 RadioButton (com.codename1.ui.RadioButton)6 Field (com.vaadin.v7.ui.Field)6 BoxLayout (com.codename1.ui.layouts.BoxLayout)5 Paint (android.graphics.Paint)4 CheckBox (com.codename1.ui.CheckBox)4