Search in sources :

Example 6 with Attribute

use of org.apache.cayenne.map.Attribute in project cayenne by apache.

the class AttributeDisplayEventType method getLastEntityAttributes.

protected Attribute[] getLastEntityAttributes(Entity entity) {
    List<Attribute> attributeList = new ArrayList<>();
    String attrs = (entity instanceof ObjEntity) ? preferences.getObjAttrs() : preferences.getDbAttrs();
    for (String attrName : attrs.split(",")) {
        Attribute attr = entity.getAttribute(attrName);
        if (attr != null) {
            attributeList.add(attr);
        }
    }
    return attributeList.toArray(new Attribute[0]);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Attribute(org.apache.cayenne.map.Attribute) ArrayList(java.util.ArrayList)

Example 7 with Attribute

use of org.apache.cayenne.map.Attribute in project cayenne by apache.

the class AttributeDisplayEventType method fireLastDisplayEvent.

@Override
public void fireLastDisplayEvent() {
    DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
    if (!dataChannel.getName().equals(preferences.getDomain())) {
        return;
    }
    DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
    DataMap dataMap = dataChannel.getDataMap(preferences.getDataMap());
    if (dataMap == null) {
        return;
    }
    Entity entity = getLastEntity(dataMap);
    if (entity == null) {
        return;
    }
    Attribute[] attributes = getLastEntityAttributes(entity);
    EntityDisplayEvent entityDisplayEvent = new EntityDisplayEvent(this, entity, dataMap, dataNode, dataChannel);
    AttributeDisplayEvent attributeDisplayEvent = new AttributeDisplayEvent(this, attributes, entity, dataMap, dataChannel);
    if (entity instanceof ObjEntity) {
        controller.fireObjEntityDisplayEvent(entityDisplayEvent);
        controller.fireObjAttributeDisplayEvent(attributeDisplayEvent);
    } else if (entity instanceof DbEntity) {
        controller.fireDbEntityDisplayEvent(entityDisplayEvent);
        controller.fireDbAttributeDisplayEvent(attributeDisplayEvent);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) DbEntity(org.apache.cayenne.map.DbEntity) Attribute(org.apache.cayenne.map.Attribute) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 8 with Attribute

use of org.apache.cayenne.map.Attribute in project cayenne by apache.

the class EntityTreeModel method sortedChildren.

private ConfigurationNode[] sortedChildren(Object node) {
    Entity entity = entityForNonLeafNode(node);
    // may happen in incomplete relationships
    if (entity == null) {
        return new ConfigurationNode[0];
    }
    ConfigurationNode[] sortedForNode = sortedChildren.get(node);
    if (sortedForNode == null) {
        Collection<? extends Attribute> attributes = entity.getAttributes();
        Collection<? extends Relationship> relationships = entity.getRelationships();
        List<ConfigurationNode> nodes = new ArrayList<>();
        // combine two collections in an array
        for (Attribute attr : attributes) {
            if (filter == null || filter.attributeMatch(node, attr)) {
                nodes.add((ConfigurationNode) attr);
            }
        }
        for (Relationship rel : relationships) {
            if (filter == null || filter.relationshipMatch(node, rel)) {
                nodes.add((ConfigurationNode) rel);
            }
        }
        sortedForNode = nodes.toArray(new ConfigurationNode[0]);
        Arrays.sort(sortedForNode, Comparators.getEntityChildrenComparator());
        sortedChildren.put(node, sortedForNode);
    }
    return sortedForNode;
}
Also used : Entity(org.apache.cayenne.map.Entity) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) Attribute(org.apache.cayenne.map.Attribute) Relationship(org.apache.cayenne.map.Relationship) ArrayList(java.util.ArrayList)

Example 9 with Attribute

use of org.apache.cayenne.map.Attribute 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

Attribute (org.apache.cayenne.map.Attribute)9 Entity (org.apache.cayenne.map.Entity)5 Relationship (org.apache.cayenne.map.Relationship)5 ObjEntity (org.apache.cayenne.map.ObjEntity)4 DbAttribute (org.apache.cayenne.map.DbAttribute)3 DbEntity (org.apache.cayenne.map.DbEntity)3 ArrayList (java.util.ArrayList)2 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)2 DataMap (org.apache.cayenne.map.DataMap)2 DbRelationship (org.apache.cayenne.map.DbRelationship)2 DetectedDbEntity (org.apache.cayenne.map.DetectedDbEntity)2 EmbeddableAttribute (org.apache.cayenne.map.EmbeddableAttribute)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 AttributeDisplayEvent (org.apache.cayenne.modeler.event.AttributeDisplayEvent)2 EntityTreeFilter (org.apache.cayenne.modeler.util.EntityTreeFilter)2 EntityTreeModel (org.apache.cayenne.modeler.util.EntityTreeModel)2 ConfigurationNode (org.apache.cayenne.configuration.ConfigurationNode)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 EJBQLQueryDescriptor (org.apache.cayenne.map.EJBQLQueryDescriptor)1