Search in sources :

Example 1 with RemoveUndoableEdit

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

the class RemoveEntityAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    Entity entity = builder.getSelectedEntity();
    if (entity == null) {
        return;
    }
    if (entity instanceof ObjEntity) {
        if (dialog.shouldDelete("ObjEntity", entity.getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(entity.getDataMap(), (ObjEntity) entity));
            removeObjEntity(entity.getDataMap(), (ObjEntity) entity);
        }
    } else {
        if (dialog.shouldDelete("DbEntity", entity.getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(entity.getDataMap(), (DbEntity) entity));
            removeDbEntity(entity.getDataMap(), (DbEntity) entity);
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 2 with RemoveUndoableEdit

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

the class RemoveAction method performAction.

/**
 * Performs delete action
 *
 * @param allowAsking If false, no question will be asked no matter what settings are
 */
public void performAction(ActionEvent e, boolean allowAsking) {
    ProjectController mediator = getProjectController();
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    if (mediator.getCurrentObjEntity() != null) {
        if (dialog.shouldDelete("ObjEntity", mediator.getCurrentObjEntity().getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentObjEntity()));
            removeObjEntity(mediator.getCurrentDataMap(), mediator.getCurrentObjEntity());
        }
    } else if (mediator.getCurrentDbEntity() != null) {
        if (dialog.shouldDelete("DbEntity", mediator.getCurrentDbEntity().getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentDbEntity()));
            removeDbEntity(mediator.getCurrentDataMap(), mediator.getCurrentDbEntity());
        }
    } else if (mediator.getCurrentQuery() != null) {
        if (dialog.shouldDelete("query", mediator.getCurrentQuery().getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentQuery()));
            removeQuery(mediator.getCurrentDataMap(), mediator.getCurrentQuery());
        }
    } else if (mediator.getCurrentProcedure() != null) {
        if (dialog.shouldDelete("procedure", mediator.getCurrentProcedure().getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentProcedure()));
            removeProcedure(mediator.getCurrentDataMap(), mediator.getCurrentProcedure());
        }
    } else if (mediator.getCurrentEmbeddable() != null) {
        if (dialog.shouldDelete("embeddable", mediator.getCurrentEmbeddable().getClassName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentEmbeddable()));
            removeEmbeddable(mediator.getCurrentDataMap(), mediator.getCurrentEmbeddable());
        }
    } else if (mediator.getCurrentDataMap() != null) {
        if (dialog.shouldDelete("data map", mediator.getCurrentDataMap().getName())) {
            // In context of Data node just remove from Data Node
            if (mediator.getCurrentDataNode() != null) {
                application.getUndoManager().addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataNode(), mediator.getCurrentDataMap()));
                removeDataMapFromDataNode(mediator.getCurrentDataNode(), mediator.getCurrentDataMap());
            } else {
                // Not under Data Node, remove completely
                application.getUndoManager().addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataMap()));
                removeDataMap(mediator.getCurrentDataMap());
            }
        }
    } else if (mediator.getCurrentDataNode() != null) {
        if (dialog.shouldDelete("data node", mediator.getCurrentDataNode().getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataNode()));
            removeDataNode(mediator.getCurrentDataNode());
        }
    } else if (mediator.getCurrentPaths() != null) {
        // multiple deletion
        if (dialog.shouldDelete("selected objects")) {
            ConfigurationNode[] paths = mediator.getCurrentPaths();
            ConfigurationNode parentPath = mediator.getCurrentParentPath();
            CompoundEdit compoundEdit = new RemoveCompoundUndoableEdit();
            for (ConfigurationNode path : paths) {
                compoundEdit.addEdit(removeLastPathComponent(path, parentPath));
            }
            compoundEdit.end();
            application.getUndoManager().addEdit(compoundEdit);
        }
    } else if (mediator.getCurrentCallbackMethods().length > 0) {
        removeMethods(mediator, dialog, getProjectController().getCurrentCallbackMethods());
    } else if (mediator.getCurrentObjRelationships().length > 0) {
        removeObjRelationships(mediator, dialog, getProjectController().getCurrentObjRelationships());
    } else if (mediator.getCurrentDbRelationships().length > 0) {
        removeDBRelationships(mediator, dialog, getProjectController().getCurrentDbRelationships());
    } else if (mediator.getCurrentObjAttributes().length > 0) {
        removeObjAttributes(mediator, dialog, getProjectController().getCurrentObjAttributes());
    } else if (mediator.getCurrentEmbAttributes().length > 0) {
        removeEmbAttributes(mediator, dialog, getProjectController().getCurrentEmbAttributes());
    } else if (mediator.getCurrentDbAttributes().length > 0) {
        removeDbAttributes(mediator, dialog, getProjectController().getCurrentDbAttributes());
    } else if (mediator.getCurrentProcedureParameters().length > 0) {
        removeProcedureParameters(mediator.getCurrentProcedure(), mediator.getCurrentProcedureParameters());
    }
}
Also used : ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) CompoundEdit(javax.swing.undo.CompoundEdit) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) RemoveCompoundUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 3 with RemoveUndoableEdit

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

the class RemoveAction method removeLastPathComponent.

/**
 * Removes an object, depending on its type
 */
private UndoableEdit removeLastPathComponent(ConfigurationNode object, ConfigurationNode parentObject) {
    UndoableEdit undo = null;
    if (object instanceof DataMap) {
        if (parentObject != null && parentObject instanceof DataNodeDescriptor) {
            undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) parentObject, (DataMap) object);
            removeDataMapFromDataNode((DataNodeDescriptor) parentObject, (DataMap) object);
        } else {
            // Not under Data Node, remove completely
            undo = new RemoveUndoableEdit(application, (DataMap) object);
            removeDataMap((DataMap) object);
        }
    } else if (object instanceof DataNodeDescriptor) {
        undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) object);
        removeDataNode((DataNodeDescriptor) object);
    } else if (object instanceof DbEntity) {
        undo = new RemoveUndoableEdit(((DbEntity) object).getDataMap(), (DbEntity) object);
        removeDbEntity(((DbEntity) object).getDataMap(), (DbEntity) object);
    } else if (object instanceof ObjEntity) {
        undo = new RemoveUndoableEdit(((ObjEntity) object).getDataMap(), (ObjEntity) object);
        removeObjEntity(((ObjEntity) object).getDataMap(), (ObjEntity) object);
    } else if (object instanceof QueryDescriptor) {
        undo = new RemoveUndoableEdit(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
        removeQuery(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
    } else if (object instanceof Procedure) {
        undo = new RemoveUndoableEdit(((Procedure) object).getDataMap(), (Procedure) object);
        removeProcedure(((Procedure) object).getDataMap(), (Procedure) object);
    } else if (object instanceof Embeddable) {
        undo = new RemoveUndoableEdit(((Embeddable) object).getDataMap(), (Embeddable) object);
        removeEmbeddable(((Embeddable) object).getDataMap(), (Embeddable) object);
    }
    return undo;
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) RemoveCallbackMethodUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit) UndoableEdit(javax.swing.undo.UndoableEdit) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) RemoveCompoundUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Aggregations

RemoveUndoableEdit (org.apache.cayenne.modeler.undo.RemoveUndoableEdit)3 DbEntity (org.apache.cayenne.map.DbEntity)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 ConfirmRemoveDialog (org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)2 RemoveCompoundUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit)2 CompoundEdit (javax.swing.undo.CompoundEdit)1 UndoableEdit (javax.swing.undo.UndoableEdit)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DataMap (org.apache.cayenne.map.DataMap)1 Embeddable (org.apache.cayenne.map.Embeddable)1 Entity (org.apache.cayenne.map.Entity)1 Procedure (org.apache.cayenne.map.Procedure)1 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)1 RemoveCallbackMethodUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit)1 RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)1