Search in sources :

Example 1 with ConfirmRemoveDialog

use of org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog 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 2 with ConfirmRemoveDialog

use of org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog in project cayenne by apache.

the class RemoveCallbackMethodAction method performAction.

/**
 * performs callback method removing
 * @param e event
 */
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ObjCallbackMethod[] methods = getProjectController().getCurrentCallbackMethods();
    if ((methods.length == 1 && dialog.shouldDelete("callback method", methods[0].getName())) || (methods.length > 1 && dialog.shouldDelete("selected callback methods"))) {
        removeCallbackMethods();
    }
}
Also used : ObjCallbackMethod(org.apache.cayenne.modeler.editor.ObjCallbackMethod) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 3 with ConfirmRemoveDialog

use of org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog 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 4 with ConfirmRemoveDialog

use of org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog 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 5 with ConfirmRemoveDialog

use of org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog 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

ConfirmRemoveDialog (org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)6 DbEntity (org.apache.cayenne.map.DbEntity)3 ObjEntity (org.apache.cayenne.map.ObjEntity)3 ProjectController (org.apache.cayenne.modeler.ProjectController)3 RemoveUndoableEdit (org.apache.cayenne.modeler.undo.RemoveUndoableEdit)2 CompoundEdit (javax.swing.undo.CompoundEdit)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 DbRelationship (org.apache.cayenne.map.DbRelationship)1 Embeddable (org.apache.cayenne.map.Embeddable)1 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)1 Entity (org.apache.cayenne.map.Entity)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjRelationship (org.apache.cayenne.map.ObjRelationship)1 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)1 ObjCallbackMethod (org.apache.cayenne.modeler.editor.ObjCallbackMethod)1 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)1 RemoveCompoundUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit)1 RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)1