use of org.apache.cayenne.configuration.event.QueryEvent in project cayenne by apache.
the class RemoveAction method removeQuery.
/**
* Removes current Query from its DataMap and fires "remove" QueryEvent.
*/
public void removeQuery(DataMap map, QueryDescriptor query) {
ProjectController mediator = getProjectController();
QueryEvent e = new QueryEvent(Application.getFrame(), query, MapEvent.REMOVE, map);
e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
map.removeQueryDescriptor(query.getName());
mediator.fireQueryEvent(e);
}
use of org.apache.cayenne.configuration.event.QueryEvent in project cayenne by apache.
the class CreateQueryAction method fireQueryEvent.
/**
* Fires events when a query was added
*/
public static void fireQueryEvent(Object src, ProjectController mediator, DataChannelDescriptor domain, DataMap dataMap, QueryDescriptor query) {
mediator.fireQueryEvent(new QueryEvent(src, query, MapEvent.ADD, dataMap));
mediator.fireQueryDisplayEvent(new QueryDisplayEvent(src, query, dataMap, domain));
}
use of org.apache.cayenne.configuration.event.QueryEvent in project cayenne by apache.
the class EjbqlQueryMainTab method setQueryName.
/**
* Initializes Query name from string.
*/
void setQueryName(String newName) {
if (newName != null && newName.trim().length() == 0) {
newName = null;
}
QueryDescriptor query = getQuery();
if (query == null) {
return;
}
if (Util.nullSafeEquals(newName, query.getName())) {
return;
}
if (newName == null) {
throw new ValidationException("Query name is required.");
}
DataMap map = mediator.getCurrentDataMap();
if (map.getQueryDescriptor(newName) == null) {
// completely new name, set new name for entity
QueryEvent e = new QueryEvent(this, query, query.getName());
ProjectUtil.setQueryName(map, query, newName);
mediator.fireQueryEvent(e);
} else {
// there is a query with the same name
throw new ValidationException("There is another query named '" + newName + "'. Use a different name.");
}
}
use of org.apache.cayenne.configuration.event.QueryEvent in project cayenne by apache.
the class EjbqlQueryScriptsTab method setEJBQL.
void setEJBQL(String text) {
EJBQLQueryDescriptor query = getQuery();
if (query == null) {
return;
}
if (text != null && text.trim().isEmpty()) {
text = null;
}
// will call "verify" even if no changes have occured....
if (!Util.nullSafeEquals(text, query.getEjbql())) {
query.setEjbql(text);
mediator.fireQueryEvent(new QueryEvent(this, query));
}
}
use of org.apache.cayenne.configuration.event.QueryEvent 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);
}
}
Aggregations