use of org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit in project cayenne by apache.
the class CreateAttributeAction method performAction.
/**
* Creates ObjAttribute, DbAttribute depending on context.
*/
@Override
public void performAction(ActionEvent e) {
ProjectController mediator = getProjectController();
if (getProjectController().getCurrentEmbeddable() != null) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
EmbeddableAttribute attr = new EmbeddableAttribute();
attr.setName(NameBuilder.builder(attr, embeddable).name());
createEmbAttribute(embeddable, attr);
application.getUndoManager().addEdit(new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
}
if (getProjectController().getCurrentObjEntity() != null) {
ObjEntity objEntity = mediator.getCurrentObjEntity();
ObjAttribute attr = new ObjAttribute();
attr.setName(NameBuilder.builder(attr, objEntity).name());
createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), objEntity, attr));
} else if (getProjectController().getCurrentDbEntity() != null) {
DbEntity dbEntity = getProjectController().getCurrentDbEntity();
DbAttribute attr = new DbAttribute();
attr.setName(NameBuilder.builder(attr, dbEntity).name());
attr.setType(TypesMapping.NOT_DEFINED);
attr.setEntity(dbEntity);
createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), dbEntity, attr));
}
}
Aggregations