Search in sources :

Example 6 with AttributeEvent

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

the class RemoveAttributeAction method removeDbAttributes.

public void removeDbAttributes(DataMap dataMap, DbEntity entity, DbAttribute[] attribs) {
    ProjectController mediator = getProjectController();
    for (DbAttribute attrib : attribs) {
        entity.removeAttribute(attrib.getName());
        AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
        mediator.fireDbAttributeEvent(e);
    }
    ProjectUtil.cleanObjMappings(dataMap);
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 7 with AttributeEvent

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

the class DbAttribute method setPrimaryKey.

/**
 * Updates attribute "primaryKey" property.
 */
public void setPrimaryKey(boolean primaryKey) {
    if (this.primaryKey != primaryKey) {
        this.primaryKey = primaryKey;
        Entity e = this.getEntity();
        if (e instanceof DbAttributeListener) {
            ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent(this, this, e));
        }
    }
}
Also used : DbAttributeListener(org.apache.cayenne.map.event.DbAttributeListener) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 8 with AttributeEvent

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

the class DbEntity method addAttribute.

/**
 * Adds a new attribute to this entity.
 *
 * @throws IllegalArgumentException if Attribute has no name or there is an existing attribute
 *                                  with the same name
 * @throws IllegalArgumentException if a relationship has the same name as this attribute
 * @since 3.0
 */
public void addAttribute(DbAttribute attr) {
    super.addAttribute(attr);
    this.dbAttributeAdded(new AttributeEvent(this, attr, this, MapEvent.ADD));
}
Also used : AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 9 with AttributeEvent

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

the class DbAttribute method setGenerated.

/**
 * Updates attribute "generated" property.
 *
 * @since 1.2
 */
public void setGenerated(boolean generated) {
    if (this.generated != generated) {
        this.generated = generated;
        Entity e = this.getEntity();
        if (e instanceof DbAttributeListener) {
            ((DbAttributeListener) e).dbAttributeChanged(new AttributeEvent(this, this, e));
        }
    }
}
Also used : DbAttributeListener(org.apache.cayenne.map.event.DbAttributeListener) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent)

Example 10 with AttributeEvent

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

the class DbEntity method removeAttribute.

/**
 * Removes attribute from the entity, removes any relationship joins
 * containing this attribute. Does nothing if the attribute name is not
 * found.
 *
 * @see org.apache.cayenne.map.Entity#removeAttribute(String)
 */
@Override
public void removeAttribute(String attrName) {
    Attribute attr = getAttribute(attrName);
    if (attr == null) {
        return;
    }
    DataMap map = getDataMap();
    if (map != null) {
        for (DbEntity ent : map.getDbEntities()) {
            for (DbRelationship relationship : ent.getRelationships()) {
                Iterator<DbJoin> joins = relationship.getJoins().iterator();
                while (joins.hasNext()) {
                    DbJoin join = joins.next();
                    if (join.getSource() == attr || join.getTarget() == attr) {
                        joins.remove();
                    }
                }
            }
        }
    }
    super.removeAttribute(attrName);
    this.dbAttributeRemoved(new AttributeEvent(this, attr, this, MapEvent.REMOVE));
}
Also used : 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