Search in sources :

Example 1 with CreateEmbAttributeUndoableEdit

use of org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit 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));
    }
}
Also used : CreateEmbAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) CreateAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbEntity (org.apache.cayenne.map.DbEntity)1 Embeddable (org.apache.cayenne.map.Embeddable)1 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 CreateAttributeUndoableEdit (org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit)1 CreateEmbAttributeUndoableEdit (org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit)1