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