Search in sources :

Example 31 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent 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)

Example 32 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class CreateDbEntityAction method fireDbEntityEvent.

/**
 * Fires events when a db entity was added
 */
static void fireDbEntityEvent(Object src, ProjectController mediator, DbEntity entity) {
    mediator.fireDbEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
    EntityDisplayEvent displayEvent = new EntityDisplayEvent(src, entity, mediator.getCurrentDataMap(), mediator.getCurrentDataNode(), (DataChannelDescriptor) mediator.getProject().getRootNode());
    displayEvent.setMainTabFocus(true);
    mediator.fireDbEntityDisplayEvent(displayEvent);
}
Also used : EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 33 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class CreateObjEntityAction method fireObjEntityEvent.

static void fireObjEntityEvent(Object src, ProjectController mediator, DataMap dataMap, ObjEntity entity) {
    mediator.fireObjEntityEvent(new EntityEvent(src, entity, MapEvent.ADD));
    EntityDisplayEvent displayEvent = new EntityDisplayEvent(src, entity, dataMap, mediator.getCurrentDataNode(), (DataChannelDescriptor) mediator.getProject().getRootNode());
    displayEvent.setMainTabFocus(true);
    mediator.fireObjEntityDisplayEvent(displayEvent);
}
Also used : EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 34 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class EntityEventTest method testConstructor1.

@Test
public void testConstructor1() throws Exception {
    Object src = new Object();
    Entity d = new DbEntity("abc");
    EntityEvent e = new EntityEvent(src, d);
    assertSame(src, e.getSource());
    assertSame(d, e.getEntity());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) Test(org.junit.Test)

Example 35 with EntityEvent

use of org.apache.cayenne.map.event.EntityEvent in project cayenne by apache.

the class EntityEventTest method testEntity.

@Test
public void testEntity() throws Exception {
    Object src = new Object();
    Entity d = new DbEntity("abc");
    EntityEvent e = new EntityEvent(src, null);
    e.setEntity(d);
    assertSame(d, e.getEntity());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) Test(org.junit.Test)

Aggregations

EntityEvent (org.apache.cayenne.map.event.EntityEvent)36 DbEntity (org.apache.cayenne.map.DbEntity)14 ObjEntity (org.apache.cayenne.map.ObjEntity)13 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)7 ProjectController (org.apache.cayenne.modeler.ProjectController)6 Entity (org.apache.cayenne.map.Entity)5 Test (org.junit.Test)5 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)4 ArrayList (java.util.ArrayList)3 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)3 DbAttribute (org.apache.cayenne.map.DbAttribute)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)3 ValidationException (org.apache.cayenne.validation.ValidationException)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)2 EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)2 Expression (org.apache.cayenne.exp.Expression)2 DbKeyGenerator (org.apache.cayenne.map.DbKeyGenerator)2