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