Search in sources :

Example 1 with DataMapDisplayEvent

use of org.apache.cayenne.modeler.event.DataMapDisplayEvent in project cayenne by apache.

the class ProjectController method removeFromHistory.

private void removeFromHistory(EventObject e) {
    int count = controllerStateHistory.size();
    List<ControllerState> removeList = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        ControllerState cs = controllerStateHistory.get(i);
        if (cs == null || cs.event == null) {
            continue;
        }
        EventObject csEvent = cs.event;
        if (e instanceof EntityEvent && csEvent instanceof EntityDisplayEvent) {
            if (((EntityEvent) e).getEntity() == ((EntityDisplayEvent) csEvent).getEntity()) {
                removeList.add(cs);
            }
        } else if (e instanceof EmbeddableEvent && csEvent instanceof EmbeddableDisplayEvent) {
            if (((EmbeddableEvent) e).getEmbeddable() == ((EmbeddableDisplayEvent) csEvent).getEmbeddable()) {
                removeList.add(cs);
            }
        } else if (e instanceof ProcedureEvent && csEvent instanceof ProcedureDisplayEvent) {
            if (((ProcedureEvent) e).getProcedure() == ((ProcedureDisplayEvent) csEvent).getProcedure()) {
                removeList.add(cs);
            }
        } else if (e instanceof QueryEvent && csEvent instanceof QueryDisplayEvent) {
            if (((QueryEvent) e).getQuery() == ((QueryDisplayEvent) csEvent).getQuery()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataMapEvent && csEvent instanceof DataMapDisplayEvent) {
            if (((DataMapEvent) e).getDataMap() == ((DataMapDisplayEvent) csEvent).getDataMap()) {
                removeList.add(cs);
            }
        } else if (e instanceof DataNodeEvent && csEvent instanceof DataNodeDisplayEvent) {
            if (((DataNodeEvent) e).getDataNode() == ((DataNodeDisplayEvent) csEvent).getDataNode()) {
                removeList.add(cs);
            }
        } else if (e instanceof DomainEvent && csEvent instanceof DomainDisplayEvent) {
            if (((DomainEvent) e).getDomain() == ((DomainDisplayEvent) csEvent).getDomain()) {
                removeList.add(cs);
            }
        }
    }
    for (ControllerState o : removeList) {
        controllerStateHistory.remove(o);
    }
}
Also used : ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) DomainEvent(org.apache.cayenne.configuration.event.DomainEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent) ArrayList(java.util.ArrayList) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) EventObject(java.util.EventObject) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 2 with DataMapDisplayEvent

use of org.apache.cayenne.modeler.event.DataMapDisplayEvent in project cayenne by apache.

the class DataMapErrorMsg method displayField.

public void displayField(ProjectController mediator, JFrame frame) {
    DataMapDisplayEvent event;
    event = new DataMapDisplayEvent(frame, map, domain);
    mediator.fireDataMapDisplayEvent(event);
}
Also used : DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent)

Example 3 with DataMapDisplayEvent

use of org.apache.cayenne.modeler.event.DataMapDisplayEvent in project cayenne by apache.

the class ProjectController method addDataMap.

public void addDataMap(Object src, DataMap map, boolean makeCurrent) {
    map.setDataChannelDescriptor(currentState.domain);
    // new map was added.. link it to domain (and node if possible)
    currentState.domain.getDataMaps().add(map);
    if (currentState.node != null && !currentState.node.getDataMapNames().contains(map.getName())) {
        currentState.node.getDataMapNames().add(map.getName());
        fireDataNodeEvent(new DataNodeEvent(this, currentState.node));
    }
    fireDataMapEvent(new DataMapEvent(src, map, MapEvent.ADD));
    if (makeCurrent) {
        fireDataMapDisplayEvent(new DataMapDisplayEvent(src, map, currentState.domain, currentState.node));
    }
}
Also used : DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) DataMapEvent(org.apache.cayenne.configuration.event.DataMapEvent)

Example 4 with DataMapDisplayEvent

use of org.apache.cayenne.modeler.event.DataMapDisplayEvent in project cayenne by apache.

the class ProjectTreeView method processSelection.

/**
 * Processes node selection regardless of whether a new node was selected, or an
 * already selected node was clicked again. Normally called from event listener
 * methods.
 */
public void processSelection(TreePath path) {
    if (path == null) {
        return;
    }
    DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object[] data = getUserObjects(currentNode);
    if (data.length == 0) {
        // this should clear the right-side panel
        DomainDisplayEvent domEvent = new DomainDisplayEvent(this, null);
        domEvent.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireDomainDisplayEvent(domEvent);
        return;
    }
    Object obj = data[data.length - 1];
    if (obj instanceof DataChannelDescriptor) {
        mediator.fireDomainDisplayEvent(new DomainDisplayEvent(this, (DataChannelDescriptor) obj));
    } else if (obj instanceof DataMap) {
        if (data.length == 2) {
            mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(this, (DataMap) obj, (DataChannelDescriptor) mediator.getProject().getRootNode(), (DataNodeDescriptor) data[data.length - 2]));
        } else if (data.length == 1) {
            mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(this, (DataMap) obj, (DataChannelDescriptor) mediator.getProject().getRootNode()));
        }
    } else if (obj instanceof DataNodeDescriptor) {
        if (data.length == 1) {
            mediator.fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, (DataChannelDescriptor) mediator.getProject().getRootNode(), (DataNodeDescriptor) obj));
        }
    } else if (obj instanceof Entity) {
        EntityDisplayEvent e = new EntityDisplayEvent(this, (Entity) obj);
        e.setUnselectAttributes(true);
        if (data.length == 3) {
            e.setDataMap((DataMap) data[data.length - 2]);
            e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
            e.setDataNode((DataNodeDescriptor) data[data.length - 3]);
        } else if (data.length == 2) {
            e.setDataMap((DataMap) data[data.length - 2]);
            e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
        }
        if (obj instanceof ObjEntity) {
            mediator.fireObjEntityDisplayEvent(e);
        } else if (obj instanceof DbEntity) {
            mediator.fireDbEntityDisplayEvent(e);
        }
    } else if (obj instanceof Embeddable) {
        EmbeddableDisplayEvent e = new EmbeddableDisplayEvent(this, (Embeddable) obj, (DataMap) data[data.length - 2], (DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireEmbeddableDisplayEvent(e);
    } else if (obj instanceof Procedure) {
        ProcedureDisplayEvent e = new ProcedureDisplayEvent(this, (Procedure) obj, (DataMap) data[data.length - 2], (DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireProcedureDisplayEvent(e);
    } else if (obj instanceof QueryDescriptor) {
        QueryDisplayEvent e = new QueryDisplayEvent(this, (QueryDescriptor) obj, (DataMap) data[data.length - 2], (DataChannelDescriptor) mediator.getProject().getRootNode());
        mediator.fireQueryDisplayEvent(e);
    }
    this.scrollPathToVisible(path);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) DomainDisplayEvent(org.apache.cayenne.modeler.event.DomainDisplayEvent) DbEntity(org.apache.cayenne.map.DbEntity) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) Procedure(org.apache.cayenne.map.Procedure)

Example 5 with DataMapDisplayEvent

use of org.apache.cayenne.modeler.event.DataMapDisplayEvent in project cayenne by apache.

the class ImportEOModelAction method addDataMap.

/**
 * Adds DataMap into the project.
 */
protected void addDataMap(DataMap map, DataMap currentMap) {
    ProjectController mediator = getProjectController();
    if (currentMap != null) {
        // merge with existing map... have to memorize map state before and after
        // to do the right events
        Collection<ObjEntity> originalOE = new ArrayList<>(currentMap.getObjEntities());
        Collection<DbEntity> originalDE = new ArrayList<>(currentMap.getDbEntities());
        Collection<QueryDescriptor> originalQueries = new ArrayList<>(currentMap.getQueryDescriptors());
        currentMap.mergeWithDataMap(map);
        map = currentMap;
        // postprocess changes
        Collection<ObjEntity> newOE = new ArrayList<>(currentMap.getObjEntities());
        Collection<DbEntity> newDE = new ArrayList<>(currentMap.getDbEntities());
        Collection<QueryDescriptor> newQueries = new ArrayList<>(currentMap.getQueryDescriptors());
        EntityEvent entityEvent = new EntityEvent(Application.getFrame(), null);
        QueryEvent queryEvent = new QueryEvent(Application.getFrame(), null);
        // 1. ObjEntities
        Collection<ObjEntity> addedOE = new ArrayList<>(newOE);
        addedOE.removeAll(originalOE);
        for (ObjEntity e : addedOE) {
            entityEvent.setEntity(e);
            entityEvent.setId(MapEvent.ADD);
            mediator.fireObjEntityEvent(entityEvent);
        }
        Collection<ObjEntity> removedOE = new ArrayList<>(originalOE);
        removedOE.removeAll(newOE);
        for (ObjEntity e : removedOE) {
            entityEvent.setEntity(e);
            entityEvent.setId(MapEvent.REMOVE);
            mediator.fireObjEntityEvent(entityEvent);
        }
        // 2. DbEntities
        Collection<DbEntity> addedDE = new ArrayList<>(newDE);
        addedDE.removeAll(originalDE);
        for (DbEntity e : addedDE) {
            entityEvent.setEntity(e);
            entityEvent.setId(MapEvent.ADD);
            mediator.fireDbEntityEvent(entityEvent);
        }
        Collection<DbEntity> removedDE = new ArrayList<>(originalDE);
        removedDE.removeAll(newDE);
        for (DbEntity e : removedDE) {
            entityEvent.setEntity(e);
            entityEvent.setId(MapEvent.REMOVE);
            mediator.fireDbEntityEvent(entityEvent);
        }
        // 3. queries
        Collection<QueryDescriptor> addedQueries = new ArrayList<>(newQueries);
        addedQueries.removeAll(originalQueries);
        for (QueryDescriptor q : addedQueries) {
            queryEvent.setQuery(q);
            queryEvent.setId(MapEvent.ADD);
            mediator.fireQueryEvent(queryEvent);
        }
        Collection<QueryDescriptor> removedQueries = new ArrayList<>(originalQueries);
        removedQueries.removeAll(newQueries);
        for (QueryDescriptor q : removedQueries) {
            queryEvent.setQuery(q);
            queryEvent.setId(MapEvent.REMOVE);
            mediator.fireQueryEvent(queryEvent);
        }
        mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(Application.getFrame(), map, (DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataNode()));
    } else {
        // fix DataMap name, as there maybe a map with the same name already
        ConfigurationNode root = mediator.getProject().getRootNode();
        map.setName(NameBuilder.builder(map, root).baseName(map.getName()).name());
        // side effect of this operation is that if a node was created, this DataMap
        // will be linked with it...
        mediator.addDataMap(Application.getFrame(), map);
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ArrayList(java.util.ArrayList) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMapDisplayEvent(org.apache.cayenne.modeler.event.DataMapDisplayEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Aggregations

DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)9 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 DbEntity (org.apache.cayenne.map.DbEntity)3 ObjEntity (org.apache.cayenne.map.ObjEntity)3 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)3 DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)3 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)3 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)3 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)3 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)3 ArrayList (java.util.ArrayList)2 EventObject (java.util.EventObject)2 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)2 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)2 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)2 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)2 DataMap (org.apache.cayenne.map.DataMap)2 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)2 EntityEvent (org.apache.cayenne.map.event.EntityEvent)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1