Search in sources :

Example 21 with EntityEvent

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

the class ObjEntityTab method setQualifier.

void setQualifier(String text) {
    if (text != null && text.trim().length() == 0) {
        text = null;
    }
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity != null) {
        ExpressionConvertor convertor = new ExpressionConvertor();
        try {
            String oldQualifier = convertor.valueAsString(entity.getDeclaredQualifier());
            if (!Util.nullSafeEquals(oldQualifier, text)) {
                Expression exp = (Expression) convertor.stringAsValue(text);
                entity.setDeclaredQualifier(exp);
                mediator.fireObjEntityEvent(new EntityEvent(this, entity));
            }
        } catch (IllegalArgumentException ex) {
            // unparsable qualifier
            throw new ValidationException(ex.getMessage());
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ValidationException(org.apache.cayenne.validation.ValidationException) Expression(org.apache.cayenne.exp.Expression) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ExpressionConvertor(org.apache.cayenne.modeler.util.ExpressionConvertor)

Example 22 with EntityEvent

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

the class ObjEntityTab method setClassName.

void setClassName(String className) {
    if (className != null && className.trim().length() == 0) {
        className = null;
    }
    ObjEntity entity = mediator.getCurrentObjEntity();
    // "ent" may be null if we quit editing by changing tree selection
    if (entity != null && !Util.nullSafeEquals(entity.getClassName(), className)) {
        entity.setClassName(className);
        mediator.fireObjEntityEvent(new EntityEvent(this, entity));
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 23 with EntityEvent

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

the class LockingUpdateController method updateAction.

public void updateAction() {
    int defaultLockType = dataMap.getDefaultLockType();
    boolean on = defaultLockType == ObjEntity.LOCK_TYPE_OPTIMISTIC;
    boolean updateEntities = view.getEntities().isSelected();
    boolean updateAttributes = view.getAttributes().isSelected();
    boolean updateRelationships = view.getRelationships().isSelected();
    ProjectController parent = (ProjectController) getParent();
    for (ObjEntity entity : dataMap.getObjEntities()) {
        if (updateEntities && defaultLockType != entity.getDeclaredLockType()) {
            entity.setDeclaredLockType(defaultLockType);
            parent.fireObjEntityEvent(new EntityEvent(this, entity));
        }
        if (updateAttributes) {
            for (ObjAttribute a : entity.getAttributes()) {
                if (a.isUsedForLocking() != on) {
                    a.setUsedForLocking(on);
                    parent.fireObjAttributeEvent(new AttributeEvent(this, a, entity));
                }
            }
        }
        if (updateRelationships) {
            for (ObjRelationship r : entity.getRelationships()) {
                if (r.isUsedForLocking() != on) {
                    r.setUsedForLocking(on);
                    parent.fireObjRelationshipEvent(new RelationshipEvent(this, r, entity));
                }
            }
        }
    }
    if (view != null) {
        view.dispose();
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 24 with EntityEvent

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

the class SchemaUpdateController method updateSchema.

protected void updateSchema() {
    boolean doAll = isAllEntities();
    String defaultSchema = dataMap.getDefaultSchema();
    // set schema for DbEntities
    for (DbEntity entity : dataMap.getDbEntities()) {
        if (doAll || Util.isEmptyString(entity.getSchema())) {
            if (!Util.nullSafeEquals(defaultSchema, entity.getSchema())) {
                entity.setSchema(defaultSchema);
                // any way to batch events, a big change will flood the app with
                // entity events..?
                mediator.fireDbEntityEvent(new EntityEvent(this, entity));
            }
        }
    }
    // set schema for procedures...
    for (Procedure procedure : dataMap.getProcedures()) {
        if (doAll || Util.isEmptyString(procedure.getSchema())) {
            if (!Util.nullSafeEquals(defaultSchema, procedure.getSchema())) {
                procedure.setSchema(defaultSchema);
                // any way to batch events, a big change will flood the app with
                // procedure events..?
                mediator.fireProcedureEvent(new ProcedureEvent(this, procedure));
            }
        }
    }
    view.dispose();
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) Procedure(org.apache.cayenne.map.Procedure)

Example 25 with EntityEvent

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

the class ObjAttributeInfoDialog method changeAttributeObject.

private void changeAttributeObject() {
    if (attributeSaved instanceof EmbeddedAttribute && embeddableModel.isAttributeOverrideChange()) {
        Map<String, String> overrides = ((EmbeddedAttribute) attributeSaved).getAttributeOverrides();
        Map<String, String> currentOverrAttr = getCurrentOverrideAttribute();
        compareAndSetOverrideInEmbeddedAttribute(attributeSaved, overrides, currentOverrAttr);
    }
    if (attributeSaved instanceof EmbeddedAttribute) {
        attributeSaved.setDbAttributePath(null);
        model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
    }
    model.getEntity().removeAttribute(attribute.getName());
    model.getEntity().addAttribute(attributeSaved);
    mediator.fireObjEntityEvent(new EntityEvent(this, model.getEntity(), MapEvent.CHANGE));
    EntityDisplayEvent event = new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
    mediator.fireObjEntityDisplayEvent(event);
    mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeSaved, model.getEntity(), MapEvent.CHANGE));
    AttributeDisplayEvent eventAttr = new AttributeDisplayEvent(this, attributeSaved, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
    mediator.fireObjAttributeDisplayEvent(eventAttr);
}
Also used : AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Aggregations

EntityEvent (org.apache.cayenne.map.event.EntityEvent)36 DbEntity (org.apache.cayenne.map.DbEntity)14 ObjEntity (org.apache.cayenne.map.ObjEntity)13 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)7 ProjectController (org.apache.cayenne.modeler.ProjectController)6 Entity (org.apache.cayenne.map.Entity)5 Test (org.junit.Test)5 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)4 ArrayList (java.util.ArrayList)3 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)3 DbAttribute (org.apache.cayenne.map.DbAttribute)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)3 ValidationException (org.apache.cayenne.validation.ValidationException)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)2 EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)2 Expression (org.apache.cayenne.exp.Expression)2 DbKeyGenerator (org.apache.cayenne.map.DbKeyGenerator)2