Search in sources :

Example 16 with ValidatorCallback

use of org.uberfire.ext.editor.commons.client.validation.ValidatorCallback 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 17 with ValidatorCallback

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

the class NewPackagePopup method onCreatePackage.

@Override
public void onCreatePackage() {
    final String[] packageName = { DataModelerUtils.trim(view.getPackageName()) };
    packageName[0] = packageName[0] != null ? packageName[0].trim() : null;
    validatorService.isValidPackageIdentifier(packageName[0], new ValidatorCallback() {

        @Override
        public void onFailure() {
            view.setErrorMessage(Constants.INSTANCE.validation_error_invalid_package_identifier(packageName[0]));
        }

        @Override
        public void onSuccess() {
            setPackageName(packageName[0]);
            view.hide();
            if (afterAddCommand != null) {
                afterAddCommand.execute();
            }
        }
    });
}
Also used : ValidatorCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorCallback)

Aggregations

ValidatorCallback (org.uberfire.ext.editor.commons.client.validation.ValidatorCallback)17 DataModelCommand (org.kie.workbench.common.screens.datamodeller.client.command.DataModelCommand)3 Command (com.google.gwt.user.client.Command)2 ObjectProperty (org.kie.workbench.common.services.datamodeller.core.ObjectProperty)2 ValidatorWithReasonCallback (org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback)2 Command (org.uberfire.mvp.Command)2 Path (org.uberfire.backend.vfs.Path)1 CommandWithFileNameAndCommitMessage (org.uberfire.ext.editor.commons.client.file.CommandWithFileNameAndCommitMessage)1 FileNameAndCommitMessage (org.uberfire.ext.editor.commons.client.file.FileNameAndCommitMessage)1 Validator (org.uberfire.ext.editor.commons.client.validation.Validator)1