Search in sources :

Example 1 with LinkDataMapUndoableEdit

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

the class LinkDataMapAction method linkDataMap.

public void linkDataMap(DataMap map, DataNodeDescriptor node) {
    if (map == null) {
        return;
    }
    // no change?
    if (node != null && node.getDataMapNames().contains(map.getName())) {
        return;
    }
    ProjectController mediator = getProjectController();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) mediator.getProject().getRootNode();
    Collection<DataNodeDescriptor> unlinkedNodes = new ArrayList<>();
    // Being paranoid, we will still scan through all.
    for (DataNodeDescriptor nextNode : dataChannelDescriptor.getNodeDescriptors()) {
        if (nextNode.getDataMapNames().contains(map.getName())) {
            nextNode.getDataMapNames().remove(map.getName());
            mediator.fireDataNodeEvent(new DataNodeEvent(this, nextNode));
            unlinkedNodes.add(nextNode);
        }
    }
    // link to a selected node
    if (node != null) {
        node.getDataMapNames().add(map.getName());
        // announce DataNode change
        mediator.fireDataNodeEvent(new DataNodeEvent(this, node));
    }
    application.getUndoManager().addEdit(new LinkDataMapUndoableEdit(map, node, unlinkedNodes, mediator));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) ArrayList(java.util.ArrayList) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController) LinkDataMapUndoableEdit(org.apache.cayenne.modeler.undo.LinkDataMapUndoableEdit)

Aggregations

ArrayList (java.util.ArrayList)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 LinkDataMapUndoableEdit (org.apache.cayenne.modeler.undo.LinkDataMapUndoableEdit)1