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));
}
Aggregations