Search in sources :

Example 16 with AttributeEvent

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

the class RemoveAction method removeObjAttributes.

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

Example 17 with AttributeEvent

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

the class RemoveAttributeAction method removeObjAttributes.

public void removeObjAttributes(ObjEntity entity, ObjAttribute[] attribs) {
    ProjectController mediator = getProjectController();
    for (ObjAttribute attrib : attribs) {
        entity.removeAttribute(attrib.getName());
        AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
        mediator.fireObjAttributeEvent(e);
        Collection<ObjEntity> objEntities = ProjectUtil.getCollectionOfChildren((ObjEntity) e.getEntity());
        for (ObjEntity objEntity : objEntities) {
            objEntity.removeAttributeOverride(e.getAttribute().getName());
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) EmbeddableAttributeEvent(org.apache.cayenne.map.event.EmbeddableAttributeEvent)

Example 18 with AttributeEvent

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

the class CreateAttributeAction method fireObjAttributeEvent.

/**
 * Fires events when an obj attribute was added
 */
static void fireObjAttributeEvent(Object src, ProjectController mediator, DataMap map, ObjEntity objEntity, ObjAttribute attr) {
    mediator.fireObjAttributeEvent(new AttributeEvent(src, attr, objEntity, MapEvent.ADD));
    DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
    AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, objEntity, map, domain);
    mediator.fireObjAttributeDisplayEvent(ade);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) 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 19 with AttributeEvent

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

the class AttributeEventTest method testAttribute.

@Test
public void testAttribute() throws Exception {
    Object src = new Object();
    Attribute a = new DbAttribute();
    a.setName("xyz");
    AttributeEvent e = new AttributeEvent(src, null, null);
    e.setAttribute(a);
    assertSame(a, e.getAttribute());
}
Also used : DbAttribute(org.apache.cayenne.map.DbAttribute) Attribute(org.apache.cayenne.map.Attribute) DbAttribute(org.apache.cayenne.map.DbAttribute) AttributeEvent(org.apache.cayenne.map.event.AttributeEvent) Test(org.junit.Test)

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