if (tokensToMigrate.isEmpty()) {
JOptionPane.showMessageDialog(getView(), "Nothing to migrate.");
return;
}
final ProjectController c = getProjectController();
final Object src = this;
final DataDomain domain = getProjectController().getCurrentDataDomain();
final DataNode node = getProjectController().getCurrentDataNode();
final ModelMergeDelegate delegate = new ModelMergeDelegate (){
public void dbAttributeAdded(DbAttribute att) {
if (c.getCurrentDbEntity() == att.getEntity()) {
c.fireDbAttributeDisplayEvent(new AttributeDisplayEvent(src, att, att.getEntity(), dataMap, domain));
}
}
public void dbAttributeModified(DbAttribute att) {
if (c.getCurrentDbEntity() == att.getEntity()) {
c.fireDbAttributeDisplayEvent(new AttributeDisplayEvent(src, att, att.getEntity(), dataMap, domain));
}
}
public void dbAttributeRemoved(DbAttribute att) {
if (c.getCurrentDbEntity() == att.getEntity()) {
c.fireDbAttributeDisplayEvent(new AttributeDisplayEvent(src, att, att.getEntity(), dataMap, domain));
}
}
public void dbEntityAdded(DbEntity ent) {
c.fireDbEntityEvent(new EntityEvent(src, ent, MapEvent.ADD));
c.fireDbEntityDisplayEvent(new EntityDisplayEvent(src, ent, dataMap, node, domain));
}
public void dbEntityRemoved(DbEntity ent) {
c.fireDbEntityEvent(new EntityEvent(src, ent, MapEvent.REMOVE));
c.fireDbEntityDisplayEvent(new EntityDisplayEvent(src, ent, dataMap, node, domain));
}
public void dbRelationshipAdded(DbRelationship rel) {
if (c.getCurrentDbEntity() == rel.getSourceEntity()) {
c.fireDbRelationshipDisplayEvent(new RelationshipDisplayEvent(src, rel, rel.getSourceEntity(), dataMap, domain));
}
}
public void dbRelationshipRemoved(DbRelationship rel) {
if (c.getCurrentDbEntity() == rel.getSourceEntity()) {
c.fireDbRelationshipDisplayEvent(new RelationshipDisplayEvent(src, rel, rel.getSourceEntity(), dataMap, domain));
}
}
public void objAttributeAdded(ObjAttribute att) {
if (c.getCurrentObjEntity() == att.getEntity()) {
c.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(src, att, att.getEntity(), dataMap, domain));
}
}
public void objAttributeModified(ObjAttribute att) {
if (c.getCurrentObjEntity() == att.getEntity()) {
c.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(src, att, att.getEntity(), dataMap, domain));
}
}
public void objAttributeRemoved(ObjAttribute att) {
if (c.getCurrentObjEntity() == att.getEntity()) {
c.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(src, att, att.getEntity(), dataMap, domain));
}
}
public void objEntityAdded(ObjEntity ent) {
c.fireObjEntityEvent(new EntityEvent(src, ent, MapEvent.ADD));
c.fireObjEntityDisplayEvent(new EntityDisplayEvent(src, ent, dataMap, node, domain));
}
public void objEntityRemoved(ObjEntity ent) {
c.fireObjEntityEvent(new EntityEvent(src, ent, MapEvent.REMOVE));
c.fireObjEntityDisplayEvent(new EntityDisplayEvent(src, ent, dataMap, node, domain));
}
public void objRelationshipAdded(ObjRelationship rel) {
if (c.getCurrentObjEntity() == rel.getSourceEntity()) {
c.fireObjRelationshipDisplayEvent(new RelationshipDisplayEvent(src, rel, rel.getSourceEntity(), dataMap, domain));
}
}
public void objRelationshipRemoved(ObjRelationship rel) {
if (c.getCurrentObjEntity() == rel.getSourceEntity()) {
c.fireObjRelationshipDisplayEvent(new RelationshipDisplayEvent(src, rel, rel.getSourceEntity(), dataMap, domain));
}
}
};
try {
DataSource dataSource = connectionInfo.makeDataSource(getApplication()
.getClassLoadingService());
// generator.runGenerator(dataSource);
MergerContext mergerContext = new ExecutingMergerContext(
dataMap,
dataSource,
adapter, delegate);
boolean modelChanged = false;
for (MergerToken tok : tokensToMigrate) {
int numOfFailuresBefore = mergerContext
.getValidationResult()
.getFailures()
.size();
tok.execute(mergerContext);
if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL)) {
modelChanged = true;
}
if (numOfFailuresBefore == mergerContext
.getValidationResult()
.getFailures()
.size()) {
// looks like the token executed without failures
tokens.removeToken(tok);
}
}
if (modelChanged) {
// mark the model as unsaved
Project project = Application.getProject();
project.setModified(true);
ProjectController projectController = Application
.getInstance()
.getFrameController()
.getProjectController();
projectController.setDirty(true);
}
ValidationResult failures = mergerContext.getValidationResult();
if (failures == null || !failures.hasFailures()) {