dataMap,
objEntity);
}
else if (content instanceof Embeddable) {
// paste Embeddable to DataMap
Embeddable embeddable = (Embeddable) content;
embeddable.setClassName(getFreeName(
new EmbeddableNameChecker(domain),
embeddable.getClassName()));
dataMap.addEmbeddable(embeddable);
CreateEmbeddableAction.fireEmbeddableEvent(
this,
mediator,
dataMap,
embeddable);
}
else if (content instanceof Query) {
// paste Query to DataMap
AbstractQuery query = (AbstractQuery) content;
/**
* Change Query root do current datamap's
*/
Object root = query.getRoot();
Object newRoot = root;
if (root instanceof ObjEntity) {
newRoot = dataMap.getObjEntity(((ObjEntity) root).getName());
}
else if (root instanceof DbEntity) {
newRoot = dataMap.getDbEntity(((DbEntity) root).getName());
}
else if (root instanceof Procedure) {
newRoot = dataMap.getProcedure(((Procedure) root).getName());
}
if (newRoot == null) {
JOptionPane
.showMessageDialog(
Application.getFrame(),
"Query root cannot be resolved. Pasting has not been performed.",
"Warning",
JOptionPane.WARNING_MESSAGE);
return;
}
query.setName(getFreeName(new QueryNameChecker(domain), query.getName()));
query.setDataMap(dataMap);
dataMap.addQuery(query);
QueryType.fireQueryEvent(this, mediator, dataMap, query);
}
else if (content instanceof Procedure) {
// paste Procedure to DataMap
Procedure procedure = (Procedure) content;
procedure.setName(getFreeName(new ProcedureNameChecker(domain), procedure
.getName()));
dataMap.addProcedure(procedure);
CreateProcedureAction.fireProcedureEvent(
this,
mediator,
dataMap,
procedure);
}
}
else if (where instanceof DbEntity) {
final DbEntity dbEntity = (DbEntity) where;
// attrs and rels must be unique in entity namespace
FreeNameChecker checker = new FreeNameChecker() {
public boolean isNameFree(String name) {
return dbEntity.getAttribute(name) == null
&& dbEntity.getRelationship(name) == null;
}
};
if (content instanceof DbAttribute) {
DbAttribute attr = (DbAttribute) content;
attr.setName(getFreeName(checker, attr.getName()));
dbEntity.addAttribute(attr);
CreateAttributeAction.fireDbAttributeEvent(this, mediator, mediator
.getCurrentDataMap(), dbEntity, attr);
}
else if (content instanceof DbRelationship) {
DbRelationship rel = (DbRelationship) content;
rel.setName(getFreeName(checker, rel.getName()));
dbEntity.addRelationship(rel);
CreateRelationshipAction.fireDbRelationshipEvent(
this,
mediator,
dbEntity,
rel);
}
}
else if (where instanceof ObjEntity) {
final ObjEntity objEntity = (ObjEntity) where;
// attrs and rels must be unique in entity namespace
FreeNameChecker checker = new FreeNameChecker() {
public boolean isNameFree(String name) {
return objEntity.getAttribute(name) == null
&& objEntity.getRelationship(name) == null;
}
};
if (content instanceof ObjAttribute) {
ObjAttribute attr = (ObjAttribute) content;
attr.setName(getFreeName(checker, attr.getName()));
objEntity.addAttribute(attr);
CreateAttributeAction.fireObjAttributeEvent(this, mediator, mediator
.getCurrentDataMap(), objEntity, attr);
}
else if (content instanceof ObjRelationship) {
ObjRelationship rel = (ObjRelationship) content;
rel.setName(getFreeName(checker, rel.getName()));
objEntity.addRelationship(rel);
CreateRelationshipAction.fireObjRelationshipEvent(
this,
mediator,
objEntity,
rel);
}
}
else if (where instanceof Embeddable) {
final Embeddable embeddable = (Embeddable) where;
// attrs and rels must be unique in entity namespace
FreeNameChecker checker = new FreeNameChecker() {
public boolean isNameFree(String name) {
return embeddable.getAttribute(name) == null;
}
};
if (content instanceof EmbeddableAttribute) {
EmbeddableAttribute attr = (EmbeddableAttribute) content;
attr.setName(getFreeName(checker, attr.getName()));
embeddable.addAttribute(attr);
CreateAttributeAction.fireEmbeddableAttributeEvent(
this,
mediator,
embeddable,
attr);