Search in sources :

Example 1 with ValidatorWithReasonCallback

use of org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback in project kie-wb-common by kiegroup.

the class DataObjectBrowser method onCreateNewProperty.

private void onCreateNewProperty(final DataObject dataObject, final String propertyName, final String propertyLabel, final String propertyType, final Boolean isMultiple, final boolean closePopup) {
    if (dataObject != null) {
        validatorService.isValidIdentifier(propertyName, new ValidatorCallback() {

            @Override
            public void onFailure() {
                newFieldPopup.setErrorMessage(Constants.INSTANCE.validation_error_invalid_object_attribute_identifier(propertyName));
            }

            @Override
            public void onSuccess() {
                validatorService.isUniqueAttributeName(propertyName, dataObject, new ValidatorWithReasonCallback() {

                    @Override
                    public void onFailure() {
                        showFailure(ValidatorService.MANAGED_PROPERTY_EXISTS);
                    }

                    @Override
                    public void onFailure(String reason) {
                        showFailure(reason);
                    }

                    private void showFailure(String reason) {
                        if (ValidatorService.UN_MANAGED_PROPERTY_EXISTS.equals(reason)) {
                            ObjectProperty unmanagedProperty = getDataObject().getUnManagedProperty(propertyName);
                            newFieldPopup.setErrorMessage(Constants.INSTANCE.validation_error_object_un_managed_attribute_already_exists(unmanagedProperty.getName(), unmanagedProperty.getClassName()));
                        } else {
                            newFieldPopup.setErrorMessage(Constants.INSTANCE.validation_error_object_attribute_already_exists(propertyName));
                        }
                    }

                    @Override
                    public void onSuccess() {
                        if (propertyType != null && !"".equals(propertyType) && !UIUtil.NOT_SELECTED.equals(propertyType)) {
                            // extra check
                            boolean multiple = isMultiple && !getContext().getHelper().isPrimitiveType(propertyType);
                            addNewProperty(getDataObject(), propertyName, propertyLabel, propertyType, multiple);
                            if (closePopup) {
                                newFieldPopup.hide();
                            } else {
                                newFieldPopup.resetInput();
                            }
                        } else {
                            newFieldPopup.setErrorMessage(Constants.INSTANCE.validation_error_missing_object_attribute_type());
                        }
                    }
                });
            }
        });
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ValidatorCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorCallback) ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback)

Example 2 with ValidatorWithReasonCallback

use of org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback in project kie-wb-common by kiegroup.

the class NewResourceViewImpl method onOKButtonClick.

void onOKButtonClick() {
    clearErrors();
    // Generic validation
    final String fileName = fileNameTextBox.getText();
    if (fileName == null || fileName.trim().isEmpty()) {
        fileNameGroup.addClassName(ValidationState.ERROR.getCssName());
        fileNameHelpInline.setText(translationService.getTranslation(KieWorkbenchWidgetsConstants.NewResourceViewFileNameIsMandatory));
        return;
    }
    if (packageListBox.getSelectedPackage() == null) {
        packageGroup.addClassName(ValidationState.ERROR.getCssName());
        packageHelpInline.setText(translationService.getTranslation(KieWorkbenchWidgetsConstants.NewResourceViewMissingPath));
        return;
    }
    // Specialized validation
    presenter.validate(fileName, new ValidatorWithReasonCallback() {

        @Override
        public void onSuccess() {
            presenter.makeItem(fileName);
        }

        @Override
        public void onFailure() {
        }

        @Override
        public void onFailure(final String reason) {
            fileNameGroup.addClassName(ValidationState.ERROR.getCssName());
            fileNameHelpInline.setText(reason);
        }
    });
}
Also used : ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback)

Example 3 with ValidatorWithReasonCallback

use of org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback in project kie-wb-common by kiegroup.

the class MainDataObjectFieldEditor method doFieldNameChange.

private void doFieldNameChange(final String oldValue, final String newValue) {
    final Command afterCloseCommand = new Command() {

        @Override
        public void execute() {
            view.setNameOnError(true);
            view.selectAllNameText();
        }
    };
    // In case an invalid name (entered before), was corrected to the original value, don't do anything but reset the label style
    if (oldValue.equalsIgnoreCase(view.getName())) {
        view.setName(oldValue);
        view.setNameOnError(false);
        return;
    }
    validatorService.isValidIdentifier(newValue, new ValidatorCallback() {

        @Override
        public void onFailure() {
            view.showErrorPopup(Constants.INSTANCE.validation_error_invalid_object_attribute_identifier(newValue), null, afterCloseCommand);
        }

        @Override
        public void onSuccess() {
            validatorService.isUniqueAttributeName(newValue, getDataObject(), new ValidatorWithReasonCallback() {

                @Override
                public void onFailure() {
                    showFailure(ValidatorService.MANAGED_PROPERTY_EXISTS);
                }

                @Override
                public void onFailure(String reason) {
                    showFailure(reason);
                }

                private void showFailure(String reason) {
                    if (ValidatorService.UN_MANAGED_PROPERTY_EXISTS.equals(reason)) {
                        ObjectProperty unmanagedProperty = getDataObject().getUnManagedProperty(newValue);
                        view.showErrorPopup(Constants.INSTANCE.validation_error_object_un_managed_attribute_already_exists(unmanagedProperty.getName(), unmanagedProperty.getClassName()));
                    } else {
                        view.showErrorPopup(Constants.INSTANCE.validation_error_object_attribute_already_exists(newValue));
                    }
                }

                @Override
                public void onSuccess() {
                    view.setNameOnError(false);
                    objectField.setName(newValue);
                    notifyChange(createFieldChangeEvent(ChangeType.FIELD_NAME_CHANGE).withOldValue(oldValue).withNewValue(newValue));
                }
            });
        }
    });
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ValidatorCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorCallback) DataModelCommand(org.kie.workbench.common.screens.datamodeller.client.command.DataModelCommand) Command(org.uberfire.mvp.Command) ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback)

Example 4 with ValidatorWithReasonCallback

use of org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback in project kie-wb-common by kiegroup.

the class DefaultNewResourceHandlerTest method testValidateInvalidFileName.

@Test
public void testValidateInvalidFileName() {
    final org.guvnor.common.services.project.model.Package pkg = mock(Package.class);
    final ValidatorWithReasonCallback callback = mock(ValidatorWithReasonCallback.class);
    when(validationService.isFileNameValid("filename.suffix")).thenReturn(false);
    handler.validate("filename", callback);
    verify(callback, times(1)).onFailure(any(String.class));
    verify(callback, never()).onFailure();
    verify(callback, never()).onSuccess();
}
Also used : ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback) Package(org.guvnor.common.services.project.model.Package) Test(org.junit.Test)

Example 5 with ValidatorWithReasonCallback

use of org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback in project kie-wb-common by kiegroup.

the class DefaultNewResourceHandlerTest method testValidateValidFileName.

@Test
public void testValidateValidFileName() {
    final org.guvnor.common.services.project.model.Package pkg = mock(Package.class);
    final ValidatorWithReasonCallback callback = mock(ValidatorWithReasonCallback.class);
    when(validationService.isFileNameValid("filename.suffix")).thenReturn(true);
    handler.validate("filename", callback);
    verify(callback, times(1)).onSuccess();
    verify(callback, never()).onFailure();
    verify(callback, never()).onFailure(any(String.class));
}
Also used : ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback) Package(org.guvnor.common.services.project.model.Package) Test(org.junit.Test)

Aggregations

ValidatorWithReasonCallback (org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback)5 Package (org.guvnor.common.services.project.model.Package)2 Test (org.junit.Test)2 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)2 ValidatorCallback (org.uberfire.ext.editor.commons.client.validation.ValidatorCallback)2 DataModelCommand (org.kie.workbench.common.screens.datamodeller.client.command.DataModelCommand)1 Command (org.uberfire.mvp.Command)1