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]);
}
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);
}
}
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;
}
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());
}
Aggregations