Search in sources :

Example 1 with AttributeEvent

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

the class SetPrimaryKeyToModel method execute.

@Override
public void execute(MergerContext mergerContext) {
    DbEntity e = getEntity();
    for (DbAttribute attr : e.getAttributes()) {
        boolean wasPrimaryKey = attr.isPrimaryKey();
        boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr.getName().toUpperCase());
        if (wasPrimaryKey != willBePrimaryKey) {
            attr.setPrimaryKey(willBePrimaryKey);
            e.dbAttributeChanged(new AttributeEvent(this, attr, e));
            mergerContext.getDelegate().dbAttributeModified(attr);
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 2 with AttributeEvent

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

the class ObjAttributeTableModel method setObjAttributeType.

private void setObjAttributeType(ObjAttributeWrapper attribute, Object value) {
    String oldType = attribute.getType();
    String newType = value != null ? value.toString() : null;
    attribute.setType(newType);
    if (oldType == null || newType == null) {
        return;
    }
    String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
    Collection<String> registeredTypesList = Arrays.asList(registeredTypes);
    if (registeredTypesList.contains(oldType) == registeredTypesList.contains(newType)) {
        return;
    }
    ObjEntity entity = attribute.getEntity();
    ObjAttribute attributeNew;
    if (registeredTypesList.contains(newType) || !mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
        attributeNew = new ObjAttribute();
        attributeNew.setDbAttributePath(attribute.getDbAttributePath());
    } else {
        attributeNew = new EmbeddedAttribute();
        attributeNew.setDbAttributePath(null);
    }
    attributeNew.setName(attribute.getName());
    attributeNew.setEntity(entity);
    attributeNew.setParent(attribute.getParent());
    attributeNew.setType(attribute.getType());
    attributeNew.setUsedForLocking(attribute.isUsedForLocking());
    entity.updateAttribute(attributeNew);
    mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
    mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
    mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeNew, entity, MapEvent.CHANGE));
    mediator.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(this, attributeNew, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) ObjAttribute(org.apache.cayenne.map.ObjAttribute) EntityEvent(org.apache.cayenne.map.event.EntityEvent) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 3 with AttributeEvent

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

the class DbAttributeTableModel method setUpdatedValueAt.

public void setUpdatedValueAt(Object newVal, int row, int col) {
    DbAttribute attr = getAttribute(row);
    if (attr == null) {
        return;
    }
    AttributeEvent e = new AttributeEvent(eventSource, attr, entity);
    switch(col) {
        case DB_ATTRIBUTE_NAME:
            e.setOldName(attr.getName());
            attr.setName((String) newVal);
            attr.getEntity().dbAttributeChanged(e);
            fireTableCellUpdated(row, col);
            break;
        case DB_ATTRIBUTE_TYPE:
            setAttributeType((String) newVal, attr);
            break;
        case DB_ATTRIBUTE_PRIMARY_KEY:
            if (!setPrimaryKey(((Boolean) newVal), attr, row)) {
                return;
            }
            break;
        case DB_ATTRIBUTE_SCALE:
            setScale((String) newVal, attr);
            break;
        case DB_ATTRIBUTE_MANDATORY:
            setMandatory((Boolean) newVal, attr);
            break;
        case DB_ATTRIBUTE_MAX:
            setMaxLength((String) newVal, attr);
            break;
        case DB_ATTRIBUTE_COMMENT:
            setComment((String) newVal, attr);
            break;
    }
    mediator.fireDbAttributeEvent(e);
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 4 with AttributeEvent

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

the class CreateAttributeAction method fireDbAttributeEvent.

/**
 * Fires events when a db attribute was added
 */
static void fireDbAttributeEvent(Object src, ProjectController mediator, DataMap map, DbEntity dbEntity, DbAttribute attr) {
    mediator.fireDbAttributeEvent(new AttributeEvent(src, attr, dbEntity, MapEvent.ADD));
    AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, dbEntity, map, (DataChannelDescriptor) mediator.getProject().getRootNode());
    mediator.fireDbAttributeDisplayEvent(ade);
}
Also used : EmbeddableAttributeDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 5 with AttributeEvent

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

the class RemoveAction method removeDbAttributes.

private void removeDbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, DbAttribute[] dbAttrs) {
    if (dbAttrs != null && dbAttrs.length > 0) {
        if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName())) || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
            DbEntity entity = mediator.getCurrentDbEntity();
            application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
            for (DbAttribute attrib : dbAttrs) {
                entity.removeAttribute(attrib.getName());
                AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
                mediator.fireDbAttributeEvent(e);
            }
            ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
        }
    }
}
Also used : RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Aggregations

AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)19 EmbeddableAttributeEvent (org.apache.cayenne.map.event.EmbeddableAttributeEvent)6 DbAttribute (org.apache.cayenne.map.DbAttribute)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 ObjEntity (org.apache.cayenne.map.ObjEntity)5 AttributeDisplayEvent (org.apache.cayenne.modeler.event.AttributeDisplayEvent)4 EmbeddedAttribute (org.apache.cayenne.map.EmbeddedAttribute)3 EntityEvent (org.apache.cayenne.map.event.EntityEvent)3 ProjectController (org.apache.cayenne.modeler.ProjectController)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)2 DbEntity (org.apache.cayenne.map.DbEntity)2 DbAttributeListener (org.apache.cayenne.map.event.DbAttributeListener)2 EmbeddableAttributeDisplayEvent (org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent)2 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)2 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 Attribute (org.apache.cayenne.map.Attribute)1 Embeddable (org.apache.cayenne.map.Embeddable)1