Search in sources :

Example 1 with RemoveRelationshipUndoableEdit

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

the class RemoveRelationshipAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ProjectController mediator = getProjectController();
    ObjRelationship[] rels = getProjectController().getCurrentObjRelationships();
    if (rels != null && rels.length > 0) {
        if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            removeObjRelationships(entity, rels);
            Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
        }
    } else {
        DbRelationship[] dbRels = getProjectController().getCurrentDbRelationships();
        if (dbRels != null && dbRels.length > 0) {
            if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
                DbEntity entity = mediator.getCurrentDbEntity();
                removeDbRelationships(entity, dbRels);
                Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
            }
        }
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 2 with RemoveRelationshipUndoableEdit

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

the class RemoveAction method removeObjRelationships.

private void removeObjRelationships(ProjectController mediator, ConfirmRemoveDialog dialog, ObjRelationship[] rels) {
    if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
        ObjEntity entity = mediator.getCurrentObjEntity();
        for (ObjRelationship rel : rels) {
            entity.removeRelationship(rel.getName());
            RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
            mediator.fireObjRelationshipEvent(e);
        }
        Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 3 with RemoveRelationshipUndoableEdit

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

the class RemoveAction method removeDBRelationships.

private void removeDBRelationships(ProjectController mediator, ConfirmRemoveDialog dialog, DbRelationship[] dbRels) {
    if (dbRels != null && dbRels.length > 0) {
        if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
            DbEntity entity = mediator.getCurrentDbEntity();
            for (DbRelationship rel : dbRels) {
                entity.removeRelationship(rel.getName());
                RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
                mediator.fireDbRelationshipEvent(e);
            }
            ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
            Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Aggregations

RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)3 DbEntity (org.apache.cayenne.map.DbEntity)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 RelationshipEvent (org.apache.cayenne.map.event.RelationshipEvent)2 ProjectController (org.apache.cayenne.modeler.ProjectController)1 ConfirmRemoveDialog (org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)1