Search in sources :

Example 1 with EmbeddableEvent

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

Example 2 with EmbeddableEvent

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

the class CreateEmbeddableAction method fireEmbeddableEvent.

static void fireEmbeddableEvent(Object src, ProjectController mediator, DataMap dataMap, Embeddable embeddable) {
    mediator.fireEmbeddableEvent(new EmbeddableEvent(src, embeddable, MapEvent.ADD), dataMap);
    EmbeddableDisplayEvent displayEvent = new EmbeddableDisplayEvent(src, embeddable, dataMap, (DataChannelDescriptor) mediator.getProject().getRootNode());
    displayEvent.setMainTabFocus(true);
    mediator.fireEmbeddableDisplayEvent(displayEvent);
}
Also used : EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) EmbeddableDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)

Example 3 with EmbeddableEvent

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

the class EmbeddableTab method setComment.

void setComment(String comment) {
    Embeddable embeddable = mediator.getCurrentEmbeddable();
    if (embeddable == null) {
        return;
    }
    ObjectInfo.putToMetaData(mediator.getApplication().getMetaData(), embeddable, ObjectInfo.COMMENT, comment);
    mediator.fireEmbeddableEvent(new EmbeddableEvent(this, embeddable), mediator.getCurrentDataMap());
}
Also used : EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) Embeddable(org.apache.cayenne.map.Embeddable)

Example 4 with EmbeddableEvent

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

the class PackageUpdateController method updatePackage.

protected void updatePackage() {
    boolean doAll = isAllEntities();
    Map<String, String> oldNameEmbeddableToNewName = new HashMap<>();
    // Create local copy to escape ConcurrentModificationException
    Collection<Embeddable> embeddables = new ArrayList<>(dataMap.getEmbeddables());
    for (Embeddable embeddable : embeddables) {
        String oldName = embeddable.getClassName();
        String[] tokens = oldName.split("\\.");
        String className = tokens[tokens.length - 1];
        if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
            EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
            String newClassName = getNameWithDefaultPackage(className);
            oldNameEmbeddableToNewName.put(oldName, newClassName);
            embeddable.setClassName(newClassName);
            mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
        }
    }
    for (ObjEntity entity : dataMap.getObjEntities()) {
        String oldName = getClassName(entity);
        if (doAll || Util.isEmptyString(oldName) || oldName.indexOf('.') < 0) {
            String className = extractClassName(Util.isEmptyString(oldName) ? entity.getName() : oldName);
            setClassName(entity, getNameWithDefaultPackage(className));
        }
        for (ObjAttribute attribute : entity.getAttributes()) {
            if (attribute instanceof EmbeddedAttribute) {
                if (oldNameEmbeddableToNewName.size() > 0 && oldNameEmbeddableToNewName.containsKey(attribute.getType())) {
                    attribute.setType(oldNameEmbeddableToNewName.get(attribute.getType()));
                    AttributeEvent ev = new AttributeEvent(this, attribute, entity);
                    mediator.fireObjAttributeEvent(ev);
                }
            }
        }
    }
    view.dispose();
}
Also used : EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) ObjAttribute(org.apache.cayenne.map.ObjAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) Embeddable(org.apache.cayenne.map.Embeddable) ObjEntity(org.apache.cayenne.map.ObjEntity)

Example 5 with EmbeddableEvent

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

the class RemoveAction method removeEmbeddable.

public void removeEmbeddable(DataMap map, Embeddable embeddable) {
    ProjectController mediator = getProjectController();
    EmbeddableEvent e = new EmbeddableEvent(Application.getFrame(), embeddable, MapEvent.REMOVE);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeEmbeddable(embeddable.getClassName());
    mediator.fireEmbeddableEvent(e, map);
}
Also used : EmbeddableEvent(org.apache.cayenne.map.event.EmbeddableEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Aggregations

EmbeddableEvent (org.apache.cayenne.map.event.EmbeddableEvent)5 ArrayList (java.util.ArrayList)2 Embeddable (org.apache.cayenne.map.Embeddable)2 EmbeddableDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableDisplayEvent)2 EventObject (java.util.EventObject)1 HashMap (java.util.HashMap)1 DataMapEvent (org.apache.cayenne.configuration.event.DataMapEvent)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 DomainEvent (org.apache.cayenne.configuration.event.DomainEvent)1 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)1 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)1 EmbeddedAttribute (org.apache.cayenne.map.EmbeddedAttribute)1 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)1 EntityEvent (org.apache.cayenne.map.event.EntityEvent)1 ProjectController (org.apache.cayenne.modeler.ProjectController)1 DataMapDisplayEvent (org.apache.cayenne.modeler.event.DataMapDisplayEvent)1 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)1 DomainDisplayEvent (org.apache.cayenne.modeler.event.DomainDisplayEvent)1