Search in sources :

Example 1 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class RemoveCallbackMethodAction method removeCallbackMethods.

/**
 * base logic for callback method removing
 * @param actionEvent event
 */
private void removeCallbackMethods(ActionEvent actionEvent) {
    ProjectController mediator = getProjectController();
    CallbackType callbackType = mediator.getCurrentCallbackType();
    ObjCallbackMethod[] callbackMethods = mediator.getCurrentCallbackMethods();
    for (ObjCallbackMethod callbackMethod : callbackMethods) {
        removeCallbackMethod(callbackType, callbackMethod.getName());
    }
    Application.getInstance().getUndoManager().addEdit(new RemoveCallbackMethodUndoableEdit(callbackType, callbackMethods));
}
Also used : CallbackType(org.apache.cayenne.modeler.editor.CallbackType) RemoveCallbackMethodUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) ObjCallbackMethod(org.apache.cayenne.modeler.editor.ObjCallbackMethod)

Example 2 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class RemoveAction method removeDbEntity.

/**
 * Removes current DbEntity from its DataMap and fires "remove" EntityEvent.
 */
public void removeDbEntity(DataMap map, DbEntity ent) {
    ProjectController mediator = getProjectController();
    EntityEvent e = new EntityEvent(Application.getFrame(), ent, MapEvent.REMOVE);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeDbEntity(ent.getName(), true);
    mediator.fireDbEntityEvent(e);
}
Also used : EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 3 with ProjectController

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

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class RemoveAction method removeQuery.

/**
 * Removes current Query from its DataMap and fires "remove" QueryEvent.
 */
public void removeQuery(DataMap map, QueryDescriptor query) {
    ProjectController mediator = getProjectController();
    QueryEvent e = new QueryEvent(Application.getFrame(), query, MapEvent.REMOVE, map);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeQueryDescriptor(query.getName());
    mediator.fireQueryEvent(e);
}
Also used : QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 5 with ProjectController

use of org.apache.cayenne.modeler.ProjectController in project cayenne by apache.

the class RemoveAction method removeObjEntity.

/**
 * Removes current object entity from its DataMap.
 */
public void removeObjEntity(DataMap map, ObjEntity entity) {
    ProjectController mediator = getProjectController();
    EntityEvent e = new EntityEvent(Application.getFrame(), entity, MapEvent.REMOVE);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeObjEntity(entity.getName(), true);
    mediator.fireObjEntityEvent(e);
    // clone to be able to remove within iterator...
    for (QueryDescriptor query : new ArrayList<>(map.getQueryDescriptors())) {
        if (!QueryDescriptor.EJBQL_QUERY.equals(query.getType())) {
            Object root = query.getRoot();
            if (root == entity || (root instanceof String && root.toString().equals(entity.getName()))) {
                removeQuery(map, query);
            }
        }
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ArrayList(java.util.ArrayList) ProjectController(org.apache.cayenne.modeler.ProjectController)

Aggregations

ProjectController (org.apache.cayenne.modeler.ProjectController)61 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)12 ObjEntity (org.apache.cayenne.map.ObjEntity)10 DataMap (org.apache.cayenne.map.DataMap)8 DbEntity (org.apache.cayenne.map.DbEntity)8 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)6 EntityEvent (org.apache.cayenne.map.event.EntityEvent)6 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)5 DbAttribute (org.apache.cayenne.map.DbAttribute)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)5 ArrayList (java.util.ArrayList)4 Embeddable (org.apache.cayenne.map.Embeddable)4 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 RelationshipEvent (org.apache.cayenne.map.event.RelationshipEvent)4 ComponentAdapter (java.awt.event.ComponentAdapter)3 ComponentEvent (java.awt.event.ComponentEvent)3 EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3