Search in sources :

Example 1 with PropertySelectorAttribute

use of com.codename1.rad.attributes.PropertySelectorAttribute in project CodeRAD by shannah.

the class FieldNode method getPropertySelector.

/**
 * Gets a property selector for this field node.  If the field contained
 * a PropertyNode or a Tags node, then it will construct a selector from those.
 *
 * Otherwise it will check for a {@link ProeprtySelectorAttribute}, and return
 * a selector constructed form that, with the provided entity root.
 * @param context
 * @return A property selector, or null if no property or tag is set, and no property selector is set.
 */
public PropertySelector getPropertySelector(Entity context) {
    if (context == null) {
        return null;
    }
    Property prop = getProperty(context.getEntity().getEntityType());
    if (prop != null) {
        return new PropertySelector(context, prop);
    }
    Tags tags = getTags();
    if (tags != null) {
        return new PropertySelector(context, tags.toArray());
    }
    PropertySelectorAttribute selectorProvider = (PropertySelectorAttribute) findAttribute(PropertySelectorAttribute.class);
    if (selectorProvider != null) {
        return selectorProvider.getValue(context);
    }
    return null;
}
Also used : PropertySelector(com.codename1.rad.models.PropertySelector) PropertySelectorAttribute(com.codename1.rad.attributes.PropertySelectorAttribute) Property(com.codename1.rad.models.Property) Tags(com.codename1.rad.models.Tags)

Example 2 with PropertySelectorAttribute

use of com.codename1.rad.attributes.PropertySelectorAttribute in project CodeRAD by shannah.

the class Node method createPropertySelector.

/**
 * Creates a property selector on the given entity using (in order of decreasing precedence):
 *
 * 1. A {@link PropertyNode} attribute on the node.
 * 2. A {@link Tags} attribute on the node.
 * 3. A {@link PropertySelectorAttribute} on the node.
 *
 * @param entity The entity on which the property selector should be created.
 * @return The property selector.
 */
public PropertySelector createPropertySelector(Entity entity) {
    PropertyNode prop = findAttribute(PropertyNode.class);
    if (prop != null) {
        return new PropertySelector(entity, prop.getValue());
    }
    Tags tags = findAttribute(Tags.class);
    if (tags != null) {
        return new PropertySelector(entity, tags.toArray());
    }
    PropertySelectorAttribute att = (PropertySelectorAttribute) findAttribute(PropertySelectorAttribute.class);
    if (att != null) {
        return att.getValue(entity);
    }
    return null;
}
Also used : PropertySelectorAttribute(com.codename1.rad.attributes.PropertySelectorAttribute)

Aggregations

PropertySelectorAttribute (com.codename1.rad.attributes.PropertySelectorAttribute)2 Property (com.codename1.rad.models.Property)1 PropertySelector (com.codename1.rad.models.PropertySelector)1 Tags (com.codename1.rad.models.Tags)1