Search in sources :

Example 6 with ConfigurationNode

use of org.apache.cayenne.configuration.ConfigurationNode 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 7 with ConfigurationNode

use of org.apache.cayenne.configuration.ConfigurationNode in project cayenne by apache.

the class DbLoaderContext method prepareDataMap.

private void prepareDataMap() {
    dataMap = getProjectController().getCurrentDataMap();
    existingMap = dataMap != null;
    if (!existingMap) {
        ConfigurationNode root = getProjectController().getProject().getRootNode();
        dataMap = new DataMap();
        dataMap.setName(NameBuilder.builder(dataMap, root).name());
    }
    if (dataMap.getConfigurationSource() != null) {
        getConfig().setTargetDataMap(new File(dataMap.getConfigurationSource().getURL().getPath()));
    }
}
Also used : ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) File(java.io.File) DataMap(org.apache.cayenne.map.DataMap)

Example 8 with ConfigurationNode

use of org.apache.cayenne.configuration.ConfigurationNode in project cayenne by apache.

the class MultipleObjectsDisplayEventType method fireLastDisplayEvent.

@Override
public void fireLastDisplayEvent() {
    DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
    String parentObjectName = preferences.getParentObject();
    ConfigurationNode parentObject;
    ConfigurationNode[] multipleObjects;
    if (dataChannel.getDataMap(parentObjectName) != null) {
        DataMap dataMap = dataChannel.getDataMap(parentObjectName);
        parentObject = dataMap;
        multipleObjects = getLastMultipleObjects(dataMap);
    } else if (dataChannel.getNodeDescriptor(parentObjectName) != null) {
        DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(parentObjectName);
        parentObject = dataNode;
        multipleObjects = getLastMultipleObjects(dataNode);
    } else {
        parentObject = dataChannel;
        multipleObjects = getLastMultipleObjects(dataChannel);
    }
    MultipleObjectsDisplayEvent multipleDisplayEvent = new MultipleObjectsDisplayEvent(this, multipleObjects, parentObject);
    controller.fireMultipleObjectsDisplayEvent(multipleDisplayEvent);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) MultipleObjectsDisplayEvent(org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 9 with ConfigurationNode

use of org.apache.cayenne.configuration.ConfigurationNode in project cayenne by apache.

the class MultipleObjectsDisplayEventType method saveLastDisplayEvent.

@Override
public void saveLastDisplayEvent() {
    preferences.setEvent(MultipleObjectsDisplayEvent.class.getSimpleName());
    preferences.setParentObject(getObjectName(controller.getCurrentParentPath()));
    ConfigurationNode[] multipleObjects = controller.getCurrentPaths();
    if (multipleObjects == null) {
        preferences.setMultipleObjects("");
    } else {
        StringBuilder sb = new StringBuilder();
        for (ConfigurationNode object : multipleObjects) {
            String objectName = getObjectName(object);
            if (!objectName.isEmpty()) {
                sb.append(objectName).append(",");
            }
        }
        preferences.setMultipleObjects(sb.toString());
    }
}
Also used : MultipleObjectsDisplayEvent(org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode)

Example 10 with ConfigurationNode

use of org.apache.cayenne.configuration.ConfigurationNode in project cayenne by apache.

the class ProjectStateUtil method saveLastState.

public void saveLastState(ProjectController controller) {
    EventObject displayEvent = controller.getLastDisplayEvent();
    ConfigurationNode[] multiplyObjects = controller.getCurrentPaths();
    if (displayEvent == null && multiplyObjects == null) {
        return;
    }
    ProjectStatePreferences preferences = controller.getProjectStatePreferences();
    if (preferences.getCurrentPreference() == null) {
        return;
    }
    try {
        preferences.getCurrentPreference().clear();
    } catch (BackingStoreException e) {
    // ignore exception
    }
    if (displayEvent != null) {
        DisplayEventTypes.valueOf(displayEvent.getClass().getSimpleName()).createDisplayEventType(controller).saveLastDisplayEvent();
    } else if (multiplyObjects.length != 0) {
        new MultipleObjectsDisplayEventType(controller).saveLastDisplayEvent();
    }
}
Also used : ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) ProjectStatePreferences(org.apache.cayenne.modeler.pref.ProjectStatePreferences) BackingStoreException(java.util.prefs.BackingStoreException) EventObject(java.util.EventObject)

Aggregations

ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)16 ArrayList (java.util.ArrayList)5 DataMap (org.apache.cayenne.map.DataMap)5 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)4 MultipleObjectsDisplayEvent (org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent)3 URLResource (org.apache.cayenne.resource.URLResource)3 File (java.io.File)2 URL (java.net.URL)2 EventObject (java.util.EventObject)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 TreePath (javax.swing.tree.TreePath)2 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 Resource (org.apache.cayenne.resource.Resource)2 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 BackingStoreException (java.util.prefs.BackingStoreException)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 CompoundEdit (javax.swing.undo.CompoundEdit)1