Search in sources :

Example 11 with AttributeEvent

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

the class DbEntity method clearAttributes.

@Override
public void clearAttributes() {
    super.clearAttributes();
    // post dummy event for no specific attribute
    this.dbAttributeRemoved(new AttributeEvent(this, null, this, MapEvent.REMOVE));
}
Also used : AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 12 with AttributeEvent

use of org.apache.cayenne.map.event.AttributeEvent 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 13 with AttributeEvent

use of org.apache.cayenne.map.event.AttributeEvent 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();
        Pattern p = Pattern.compile("[.]");
        String[] tokens = p.split(oldName);
        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 : Pattern(java.util.regex.Pattern) 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 14 with AttributeEvent

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

Example 15 with AttributeEvent

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

the class ObjAttributeTableModel method setUpdatedValueAt.

@Override
public void setUpdatedValueAt(Object value, int row, int column) {
    ObjAttributeWrapper attribute = getAttribute(row);
    attribute.resetEdits();
    AttributeEvent event = new AttributeEvent(eventSource, attribute.getValue(), entity);
    switch(column) {
        case OBJ_ATTRIBUTE:
            event.setOldName(attribute.getName());
            setObjAttribute(attribute, value);
            fireTableCellUpdated(row, column);
            break;
        case OBJ_ATTRIBUTE_TYPE:
            setObjAttributeType(attribute, value);
            fireTableCellUpdated(row, column);
            break;
        case LOCKING:
            setColumnLocking(attribute, value);
            fireTableCellUpdated(row, column);
            break;
        case DB_ATTRIBUTE:
            setDbAttribute(attribute, value);
            fireTableRowsUpdated(row, row);
            break;
        case COMMENT:
            setComment((String) value, attribute.getValue());
        default:
            fireTableRowsUpdated(row, row);
            break;
    }
    mediator.fireObjAttributeEvent(event);
}
Also used : ObjAttributeWrapper(org.apache.cayenne.modeler.editor.wrapper.ObjAttributeWrapper) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

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