String errorMessage = null;
Object object = listBuilder.getObjectControl().getValue();
if (object != null && object instanceof Validatable) {
ModelFactory modelFactory = ModelFactory.getDefaultInstance();
Validator validator = modelFactory.createValidator();
// Validate the object being created
validator.validate((Validatable) object);
// Validate the already created selectors
List selectors = listBuilder.getItems();
Iterator it = selectors.iterator();
while (it.hasNext() && validator.getDiagnostics().isEmpty()) {
validator.validate((Validatable) it.next());
}
// Retrieve the first error message
List diagnostics = validator.getDiagnostics();
if (!diagnostics.isEmpty()) {
Diagnostic firstDiagnostic = (Diagnostic) diagnostics.get(0);
errorMessage = firstDiagnostic.getMessage().getMessage();
}
}