Search in sources :

Example 1 with LinkDataMapsUndoableEdit

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

the class LinkDataMapsAction method performAction.

@Override
public void performAction(ActionEvent e) {
    ProjectController mediator = getProjectController();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) mediator.getProject().getRootNode();
    Collection<String> linkedDataMaps = new ArrayList<>();
    DataNodeDescriptor dataNodeDescriptor = mediator.getCurrentDataNode();
    for (DataNodeDescriptor dataNodeDesc : dataChannelDescriptor.getNodeDescriptors()) {
        linkedDataMaps.addAll(dataNodeDesc.getDataMapNames());
    }
    for (DataMap dataMap : dataChannelDescriptor.getDataMaps()) {
        if (!linkedDataMaps.contains(dataMap.getName())) {
            dataNodeDescriptor.getDataMapNames().add(dataMap.getName());
            mediator.fireDataNodeEvent(new DataNodeEvent(this, dataNodeDescriptor));
        }
    }
    application.getUndoManager().addEdit(new LinkDataMapsUndoableEdit(dataNodeDescriptor, linkedDataMaps, mediator));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) ArrayList(java.util.ArrayList) LinkDataMapsUndoableEdit(org.apache.cayenne.modeler.undo.LinkDataMapsUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController) DataMap(org.apache.cayenne.map.DataMap)

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 DataMap (org.apache.cayenne.map.DataMap)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 LinkDataMapsUndoableEdit (org.apache.cayenne.modeler.undo.LinkDataMapsUndoableEdit)1