Search in sources :

Example 6 with IValidationMessage

use of org.jowidgets.validation.IValidationMessage in project jo-client-platform by jo-source.

the class DataModelSaveCommand method getVetoEnabledState.

@Override
IEnabledState getVetoEnabledState(final IDataModel model) {
    if (model.hasExecutions()) {
        return AbstractDataModelCommand.IN_PROCESS_STATE.get();
    }
    final IValidationResult validationResult = model.validate();
    if (!validationResult.isValid()) {
        final IValidationMessage worstFirst = validationResult.getWorstFirst();
        final String context = worstFirst.getContext();
        final String text = worstFirst.getText();
        if (EmptyCheck.isEmpty(context)) {
            return EnabledState.disabled(text);
        } else {
            return EnabledState.disabled(context + ": " + text);
        }
    }
    return EnabledState.ENABLED;
}
Also used : IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult)

Example 7 with IValidationMessage

use of org.jowidgets.validation.IValidationMessage in project jo-client-platform by jo-source.

the class BeanFormDefaults method initialize.

@Override
public void initialize(final IBeanFormBluePrint<?> bluePrint) {
    bluePrint.setAutoResetValidation(true);
    bluePrint.setCreateModeForegroundColor(Colors.GREEN);
    bluePrint.setModifiedForegroundColor(Colors.STRONG);
    bluePrint.setScrollbarsAllowed(true);
    final IInputComponentValidationLabelBluePrint editModeValidationLabel = BPF.inputComponentValidationLabel();
    final IDecorator<IValidationResult> editModeValidationDecorator = new IDecorator<IValidationResult>() {

        @Override
        public IValidationResult decorate(final IValidationResult original) {
            if (original != null) {
                final IValidationMessage worstFirst = original.getWorstFirst();
                if (worstFirst != null && worstFirst.getType().equalOrWorse(MessageType.WARNING)) {
                    return original;
                }
            }
            return null;
        }
    };
    editModeValidationLabel.setInitialValidationDecorator(editModeValidationDecorator);
    editModeValidationLabel.setUnmodifiedValidationDecorator(editModeValidationDecorator);
    editModeValidationLabel.setEmptyIcon(IconsSmall.OK_GREYED);
    bluePrint.setEditModeValidationLabel(editModeValidationLabel);
    final IInputComponentValidationLabelBluePrint createModeValidationLabel = BPF.inputComponentValidationLabel();
    final IDecorator<IValidationResult> createModeValidationDecorator = new IDecorator<IValidationResult>() {

        @Override
        public IValidationResult decorate(final IValidationResult original) {
            if (original != null) {
                final IValidationMessage worstFirst = original.getWorstFirst();
                if (worstFirst != null && worstFirst.getType().equalOrWorse(MessageType.WARNING)) {
                    return original;
                }
            }
            return null;
        }
    };
    createModeValidationLabel.setInitialValidationDecorator(createModeValidationDecorator);
    createModeValidationLabel.setUnmodifiedValidationDecorator(createModeValidationDecorator);
    bluePrint.setCreateModeValidationLabel(createModeValidationLabel);
    bluePrint.setCreateModeInputHint(Messages.getString("BeanFormDefaults.fill_out_mandatory_fields"));
    bluePrint.setMandatoryBackgroundColor(CapColors.MANDATORY_BACKGROUND);
    bluePrint.setMandatoryLabelDecorator(new IDecorator<String>() {

        @Override
        public String decorate(final String original) {
            if (original != null) {
                return original + "*";
            }
            return null;
        }
    });
    bluePrint.setPropertyValidationLabel(BPF.validationResultLabel().setShowValidationMessage(false));
}
Also used : IValidationMessage(org.jowidgets.validation.IValidationMessage) IValidationResult(org.jowidgets.validation.IValidationResult) IInputComponentValidationLabelBluePrint(org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint) IDecorator(org.jowidgets.util.IDecorator)

Aggregations

IValidationMessage (org.jowidgets.validation.IValidationMessage)7 IValidationResult (org.jowidgets.validation.IValidationResult)5 IPerson (org.jowidgets.cap.ui.impl.beans.IPerson)3 IBeanValidationResult (org.jowidgets.cap.common.api.validation.IBeanValidationResult)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 IInputComponentValidationLabelBluePrint (org.jowidgets.api.widgets.blueprint.IInputComponentValidationLabelBluePrint)1 BeansValidationException (org.jowidgets.cap.common.api.exception.BeansValidationException)1 KeyType (org.jowidgets.cap.common.api.exception.BeansValidationException.KeyType)1 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)1 IDecorator (org.jowidgets.util.IDecorator)1