Search in sources :

Example 1 with QueryEvent

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);
}
Also used : QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 2 with QueryEvent

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));
}
Also used : QueryDisplayEvent(org.apache.cayenne.modeler.event.QueryDisplayEvent) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent)

Example 3 with QueryEvent

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.");
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent) DataMap(org.apache.cayenne.map.DataMap)

Example 4 with QueryEvent

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));
    }
}
Also used : EJBQLQueryDescriptor(org.apache.cayenne.map.EJBQLQueryDescriptor) QueryEvent(org.apache.cayenne.configuration.event.QueryEvent)

Example 5 with QueryEvent

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

Aggregations

QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)26 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)13 ProcedureQueryDescriptor (org.apache.cayenne.map.ProcedureQueryDescriptor)4 ValidationException (org.apache.cayenne.validation.ValidationException)4 DataMap (org.apache.cayenne.map.DataMap)3 QueryDisplayEvent (org.apache.cayenne.modeler.event.QueryDisplayEvent)3 ArrayList (java.util.ArrayList)2 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)2 SelectQueryDescriptor (org.apache.cayenne.map.SelectQueryDescriptor)2 EntityEvent (org.apache.cayenne.map.event.EntityEvent)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)2 Ordering (org.apache.cayenne.query.Ordering)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 EventObject (java.util.EventObject)1 BadLocationException (javax.swing.text.BadLocationException)1 Document (javax.swing.text.Document)1 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)1