use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.
the class TableSelectorController method updateTables.
/**
* Performs validation of DbEntities in the current DataMap. Returns a collection of
* ValidationInfo objects describing the problems.
*/
public void updateTables(Collection<DataMap> dataMaps) {
this.tables = new ArrayList<DbEntity>();
for (DataMap dataMap : dataMaps) {
this.tables.addAll(dataMap.getDbEntities());
}
excludedTables.clear();
validationMessages.clear();
// if there were errors, filter out those related to
// non-derived DbEntities...
// TODO: this is inefficient.. we need targeted validation
// instead of doing it on the whole project
Project project = getApplication().getProject();
ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
ValidationResult validationResult = projectValidator.validate(project.getRootNode());
if (validationResult.getFailures().size() > 0) {
for (ValidationFailure nextProblem : validationResult.getFailures()) {
DbEntity failedEntity = null;
if (nextProblem.getSource() instanceof DbAttribute) {
DbAttribute failedAttribute = (DbAttribute) nextProblem.getSource();
failedEntity = (DbEntity) failedAttribute.getEntity();
} else if (nextProblem.getSource() instanceof DbRelationship) {
DbRelationship failedRelationship = (DbRelationship) nextProblem.getSource();
failedEntity = (DbEntity) failedRelationship.getSourceEntity();
} else if (nextProblem.getSource() instanceof DbEntity) {
failedEntity = (DbEntity) nextProblem.getSource();
}
if (failedEntity == null) {
continue;
}
excludedTables.put(failedEntity.getName(), failedEntity);
validationMessages.put(failedEntity.getName(), nextProblem.getDescription());
}
}
// Find selectable tables
permanentlyExcludedCount = excludedTables.size();
selectableTablesList.clear();
for (DbEntity table : tables) {
if (false == excludedTables.containsKey(table.getName())) {
selectableTablesList.add(table);
}
}
tableBinding.updateView();
tableSelectedAction();
}
use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.
the class CayenneModelerController method projectOpenedAction.
/**
* Handles project opening control. Updates main frame, then delegates control to
* child controllers.
*/
public void projectOpenedAction(Project project) {
projectController.setProject(project);
editorView = new EditorView(projectController);
frame.setView(editorView);
projectController.projectOpened();
application.getActionManager().projectOpened();
// do status update AFTER the project is actually opened...
if (project.getConfigurationResource() == null) {
updateStatus("New project created...");
frame.setTitle("[New Project]");
} else {
updateStatus("Project opened...");
frame.setTitle(project.getConfigurationResource().getURL().getPath());
}
// update preferences
if (project.getConfigurationResource() != null) {
getLastDirectory().setDirectory(new File(project.getConfigurationResource().getURL().getPath()));
frame.fireRecentFileListChanged();
}
PROJECT_STATE_UTIL.fireLastState(projectController);
// for validation purposes combine load failures with post-load validation (not
// sure if that'll cause duplicate messages?).
List<ValidationFailure> allFailures = new ArrayList<>();
Collection<ValidationFailure> loadFailures = project.getConfigurationTree().getLoadFailures();
if (!loadFailures.isEmpty()) {
// mark project as unsaved
project.setModified(true);
projectController.setDirty(true);
allFailures.addAll(loadFailures);
}
ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
ValidationResult validationResult = projectValidator.validate(project.getRootNode());
allFailures.addAll(validationResult.getFailures());
if (!allFailures.isEmpty()) {
ValidatorDialog.showDialog(frame, validationResult.getFailures());
}
}
use of org.apache.cayenne.validation.ValidationResult in project cayenne by apache.
the class SaveAsAction method performAction.
public void performAction() {
ProjectValidator projectValidator = getApplication().getInjector().getInstance(ProjectValidator.class);
ValidationResult validationResult = projectValidator.validate(getCurrentProject().getRootNode());
getProjectController().fireProjectOnSaveEvent(new ProjectOnSaveEvent(SaveAsAction.class));
try {
if (!saveAll()) {
return;
}
} catch (Exception ex) {
throw new CayenneRuntimeException("Error on save", ex);
}
getApplication().getFrameController().projectSavedAction();
// If there were errors or warnings at validation, display them
if (validationResult.getFailures().size() > 0) {
ValidatorDialog.showDialog(Application.getFrame(), validationResult.getFailures());
}
}
Aggregations