use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.
the class BeanDialogImpl method setOkButtonEnabledState.
private void setOkButtonEnabledState() {
final IValidationResult validationResult = beanForm.validate();
final IBeanProxy<BEAN_TYPE> bean = beanForm.getValue();
if (validationResult.isValid()) {
if (!bean.isTransient() && !bean.hasModifications()) {
okButton.setToolTipText(NO_MODIFICATIONS.get());
okButton.setEnabled(false);
} else {
okButton.setToolTipText(okButtonTooltip);
okButton.setEnabled(true);
}
} else {
okButton.setToolTipText(validationResult.getWorstFirst().getText());
okButton.setEnabled(false);
}
}
use of org.jowidgets.validation.IValidationResult in project jo-client-platform by jo-source.
the class BeanFormControl method validate.
private IBeanValidationResult validate(final IBeanValidationResult parentResult) {
final String propertyName = parentResult.getPropertyName();
final IValidationResult parentValidationResult = parentResult.getValidationResult();
boolean validationChanged = false;
IValidationResult validationResult = ValidationResult.ok();
final IInputControl<?> control = controls.get(propertyName);
final String propertyLabel = getLabel(propertyName);
if (bean != null && control != null && EmptyCompatibleEquivalence.equals(control.getValue(), bean.getValue(propertyName))) {
validationResult = control.validate();
// use the parent result if the control result is valid and the parent result is not valid
if (validationResult.isValid() && !parentValidationResult.isValid()) {
validationResult = parentValidationResult;
} else if (validationResult.isOk() && !parentValidationResult.isOk()) {
validationResult = parentValidationResult;
}
// change the validation map, if the worst first changed
final IValidationResult lastResult = validationResults.get(propertyName);
if (lastResult == null || !validationResult.getWorstFirst().equals(lastResult.getWorstFirst())) {
boolean hasMessage = false;
boolean hasHint = false;
final IAttribute<Object> attribute = attributes.get(propertyName);
if (!validationResult.isValid() && !control.hasModifications() && !bean.isModified(propertyName) && inputHint != null && attribute != null && attribute.isMandatory() && EmptyCheck.isEmpty(bean.getValue(propertyName))) {
validationResults.put(propertyName, ValidationResult.infoError(inputHint));
hasHint = true;
} else {
validationResults.put(propertyName, validationResult.withContext(propertyLabel));
hasMessage = validationResult.getWorstFirst().getType() != MessageType.OK;
}
validationChanged = true;
// update the validation label
final IValidationResultLabel validationLabel = validationLabels.get(propertyName);
if (validationLabel != null) {
if (hasMessage || control.hasModifications() || bean.isModified(propertyName)) {
if (!hasHint) {
validationLabel.setResult(validationResult);
}
} else {
validationLabel.setEmpty();
}
}
}
} else if (bean != null && control == null) {
// change the validation map, if the worst first changed
validationResult = parentValidationResult;
final IValidationResult lastResult = validationResults.get(propertyName);
if (lastResult == null || !validationResult.getWorstFirst().equals(lastResult.getWorstFirst())) {
if (propertyLabel != null) {
validationResults.put(propertyName, validationResult.withContext(propertyLabel));
} else {
validationResults.put(propertyName, validationResult);
}
validationChanged = true;
}
}
if (validationChanged) {
final IValidationResult newValidationResult = validationResult;
return new IBeanValidationResult() {
@Override
public IValidationResult getValidationResult() {
return newValidationResult.withContext(propertyLabel);
}
@Override
public String getPropertyName() {
return propertyName;
}
};
} else {
return null;
}
}
use of org.jowidgets.validation.IValidationResult 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));
}
Aggregations