Search in sources :

Example 1 with RemoveAttributeUndoableEdit

use of org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit in project cayenne by apache.

the class RemoveAction method removeDbAttributes.

private void removeDbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, DbAttribute[] dbAttrs) {
    if (dbAttrs != null && dbAttrs.length > 0) {
        if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            DbEntity entity = mediator.getCurrentDbEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
            for (DbAttribute attrib : dbAttrs) {
                entity.removeAttribute(attrib.getName());
                AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
                mediator.fireDbAttributeEvent(e);
            }
            ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 2 with RemoveAttributeUndoableEdit

use of org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit in project cayenne by apache.

the class RemoveAction method removeObjAttributes.

private void removeObjAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, ObjAttribute[] objAttrs) {
    if (objAttrs != null && objAttrs.length > 0) {
        if ((objAttrs.length == 1 && dialog.shouldDelete("DbAttribute", objAttrs[0].getName())) || (objAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
            for (ObjAttribute attrib : objAttrs) {
                entity.removeAttribute(attrib.getName());
                AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
                mediator.fireObjAttributeEvent(e);
            }
            ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 3 with RemoveAttributeUndoableEdit

use of org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit in project cayenne by apache.

the class RemoveAction method removeEmbAttributes.

private void removeEmbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, EmbeddableAttribute[] embAttrs) {
    if (embAttrs != null && embAttrs.length > 0) {
        if ((embAttrs.length == 1 && dialog.shouldDelete("DbAttribute", embAttrs[0].getName())) || (embAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            Embeddable embeddable = mediator.getCurrentEmbeddable();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(embeddable, embAttrs));
            for (EmbeddableAttribute attrib : embAttrs) {
                embeddable.removeAttribute(attrib.getName());
                EmbeddableAttributeEvent e = new EmbeddableAttributeEvent(Application.getFrame(), attrib, embeddable, MapEvent.REMOVE);
                mediator.fireEmbeddableAttributeEvent(e);
            }
            ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
        }
    }
}
Also used : EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent) RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Embeddable(org.apache.cayenne.map.Embeddable)

Example 4 with RemoveAttributeUndoableEdit

use of org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit in project cayenne by apache.

the class RemoveAttributeAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ProjectController mediator = getProjectController();
    EmbeddableAttribute[] embAttrs = getProjectController().getCurrentEmbAttributes();
    ObjAttribute[] objAttrs = getProjectController().getCurrentObjAttributes();
    DbAttribute[] dbAttrs = getProjectController().getCurrentDbAttributes();
    if (embAttrs != null && embAttrs.length > 0) {
        if ((embAttrs.length == 1 && dialog.shouldDelete("Embeddable Attribute", embAttrs[0].getName())) || (embAttrs.length > 1 && dialog.shouldDelete("selected EmbAttributes"))) {
            Embeddable embeddable = mediator.getCurrentEmbeddable();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(embeddable, embAttrs));
            removeEmbeddableAttributes(embeddable, embAttrs);
        }
    } else if (objAttrs != null && objAttrs.length > 0) {
        if ((objAttrs.length == 1 && dialog.shouldDelete("ObjAttribute", objAttrs[0].getName())) || (objAttrs.length > 1 && dialog.shouldDelete("selected ObjAttributes"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
            removeObjAttributes(entity, objAttrs);
        }
    } else if (dbAttrs != null && dbAttrs.length > 0) {
        if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            DbEntity entity = mediator.getCurrentDbEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
            removeDbAttributes(mediator.getCurrentDataMap(), entity, dbAttrs);
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog) Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)4 EmbeddableAttributeEvent (org.apache.cayenne.map.event.EmbeddableAttributeEvent)3 DbAttribute (org.apache.cayenne.map.DbAttribute)2 DbEntity (org.apache.cayenne.map.DbEntity)2 Embeddable (org.apache.cayenne.map.Embeddable)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)2 ProjectController (org.apache.cayenne.modeler.ProjectController)1 ConfirmRemoveDialog (org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)1