Search in sources :

Example 16 with ProjectController

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

the class ShowGraphEntityAction method performAction.

@Override
public void performAction(ActionEvent e) {
    Entity entity = null;
    ProjectController mediator = getProjectController();
    if (mediator.getCurrentDbEntity() != null) {
        entity = mediator.getCurrentDbEntity();
    } else if (mediator.getCurrentObjEntity() != null) {
        entity = mediator.getCurrentObjEntity();
    }
    if (entity != null) {
        showEntity(entity);
    }
}
Also used : Entity(org.apache.cayenne.map.Entity) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 17 with ProjectController

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

Example 18 with ProjectController

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

Example 19 with ProjectController

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

the class NavigateBackwardAction method performAction.

/**
 * Moves to the next element in the navigation history
 */
public void performAction(ActionEvent e) {
    ProjectController mediator = getProjectController();
    EventObject newEvent = new EventObject(this);
    mediator.fireNavigationEvent(newEvent);
}
Also used : ProjectController(org.apache.cayenne.modeler.ProjectController) EventObject(java.util.EventObject)

Example 20 with ProjectController

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

the class ObjEntitySyncAction method syncObjEntity.

protected void syncObjEntity() {
    ProjectController mediator = getProjectController();
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity != null && entity.getDbEntity() != null) {
        EntityMergeSupport merger = new EntitySyncController(Application.getInstance().getFrameController(), entity).createMerger();
        if (merger == null) {
            return;
        }
        merger.setNameGenerator(new DbEntitySyncAction.PreserveRelationshipNameGenerator());
        if (merger.synchronizeWithDbEntity(entity)) {
            mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
            mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
        }
    }
}
Also used : EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) EntitySyncController(org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)

Aggregations

ProjectController (org.apache.cayenne.modeler.ProjectController)59 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)12 ObjEntity (org.apache.cayenne.map.ObjEntity)10 DbEntity (org.apache.cayenne.map.DbEntity)8 DataMap (org.apache.cayenne.map.DataMap)7 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)6 EntityEvent (org.apache.cayenne.map.event.EntityEvent)6 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 ProcedureParameter (org.apache.cayenne.map.ProcedureParameter)5 ArrayList (java.util.ArrayList)4 DbAttribute (org.apache.cayenne.map.DbAttribute)4 DbRelationship (org.apache.cayenne.map.DbRelationship)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