Search in sources :

Example 36 with PropertyAccessor

use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.

the class TableFormBuilder method configFields.

// **************************************************************************
// Builder configuration
// **************************************************************************
public TableFormBuilder configFields(String... fieldNames) {
    propertyAccessors = new ArrayList<PropertyAccessor>();
    for (String currentField : fieldNames) {
        try {
            PropertyAccessor accessor = classAccessor.getProperty(currentField);
            propertyAccessors.add(accessor);
        } catch (NoSuchFieldException e) {
            logger.warn("Field not found: {}", currentField);
        }
    }
    return this;
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor)

Example 37 with PropertyAccessor

use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.

the class ReflectionUtil method classAccessorToJson.

public static JSONWriter classAccessorToJson(ClassAccessor accessor, JSONStringer js) {
    js.object();
    js.key("name").value(accessor.getName());
    js.key("keyProperties").array();
    for (PropertyAccessor p : accessor.getKeyProperties()) {
        js.value(p.getName());
    }
    js.endArray();
    js.key("properties").array();
    for (PropertyAccessor p : accessor.getProperties()) {
        propertyAccessorToJson(js, p);
    }
    js.endArray();
    js.key("annotations").array();
    for (Annotation ann : accessor.getAnnotations()) {
        annotationToJson(js, ann);
    }
    js.endArray();
    return js.endObject();
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) Annotation(java.lang.annotation.Annotation)

Example 38 with PropertyAccessor

use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.

the class ClassAccessorDecorator method init.

private void init(ClassAccessor delegate, ClassAccessor decoratorAccessor, Object decorator) {
    int p = 0, k = 0;
    for (PropertyAccessor accessor : delegate.getProperties()) {
        try {
            PropertyAccessor decoratingProperty = decoratorAccessor.getProperty(accessor.getName());
            PropertyAccessorDecorator propertyAccessorDecorator = new PropertyAccessorDecorator(accessor, decoratingProperty);
            properties[p] = propertyAccessorDecorator;
            if (decoratingProperty.getType().isAssignableFrom(PropertyAccessor.class) && decorator != null) {
                decoratingProperty.set(decorator, propertyAccessorDecorator);
            }
        } catch (NoSuchFieldException e) {
            properties[p] = accessor;
        }
        if (ArrayUtils.contains(delegate.getKeyProperties(), accessor)) {
            keyProperties[k++] = properties[p];
        }
        p++;
    }
    for (Annotation annotation : delegate.getAnnotations()) {
        this.annotations.put(annotation.annotationType(), annotation);
    }
    for (Annotation annotation : decoratorAccessor.getAnnotations()) {
        this.annotations.put(annotation.annotationType(), annotation);
    }
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) Annotation(java.lang.annotation.Annotation)

Example 39 with PropertyAccessor

use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.

the class AbstractCrudAction method configureDetailLink.

protected void configureDetailLink(TableFormBuilder tableFormBuilder) {
    boolean isShowingKey = false;
    for (PropertyAccessor property : classAccessor.getKeyProperties()) {
        if (tableFormBuilder.getPropertyAccessors().contains(property) && tableFormBuilder.isPropertyVisible(property)) {
            isShowingKey = true;
            break;
        }
    }
    OgnlTextFormat hrefFormat = getReadURLFormat();
    if (isShowingKey) {
        logger.debug("TableForm: configuring detail links for primary key properties");
        for (PropertyAccessor property : classAccessor.getKeyProperties()) {
            tableFormBuilder.configHrefTextFormat(property.getName(), hrefFormat);
        }
    } else {
        logger.debug("TableForm: configuring detail link for the first visible property");
        for (PropertyAccessor property : classAccessor.getProperties()) {
            if (tableFormBuilder.getPropertyAccessors().contains(property) && tableFormBuilder.isPropertyVisible(property)) {
                tableFormBuilder.configHrefTextFormat(property.getName(), hrefFormat);
                break;
            }
        }
    }
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Example 40 with PropertyAccessor

use of com.manydesigns.elements.reflection.PropertyAccessor in project Portofino by ManyDesigns.

the class ManyToManyAction method loadOnePk.

protected void loadOnePk(Object key) throws Exception {
    TableAccessor tableAccessor = new TableAccessor(m2mConfiguration.getActualRelationTable());
    PropertyAccessor onePkAccessor = tableAccessor.getProperty(m2mConfiguration.getActualOnePropertyName());
    if (onePkAccessor == null) {
        logger.error("Not a property: {}", m2mConfiguration.getActualOnePropertyName());
        return;
    }
    Class type = onePkAccessor.getType();
    onePk = OgnlUtils.convertValue(key, type);
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) TableAccessor(com.manydesigns.portofino.reflection.TableAccessor) ConfigurationClass(com.manydesigns.portofino.resourceactions.annotations.ConfigurationClass)

Aggregations

PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)46 ClassAccessor (com.manydesigns.elements.reflection.ClassAccessor)13 JavaClassAccessor (com.manydesigns.elements.reflection.JavaClassAccessor)12 JSONObject (org.json.JSONObject)5 SelectionProvider (com.manydesigns.elements.options.SelectionProvider)4 Field (com.manydesigns.elements.fields.Field)3 SelectField (com.manydesigns.elements.fields.SelectField)3 OgnlTextFormat (com.manydesigns.elements.text.OgnlTextFormat)3 TableAccessor (com.manydesigns.portofino.reflection.TableAccessor)3 Session (org.hibernate.Session)3 FieldSet (com.manydesigns.elements.annotations.FieldSet)2 SelectionModel (com.manydesigns.elements.options.SelectionModel)2 QueryStringWithParameters (com.manydesigns.elements.text.QueryStringWithParameters)2 TableCriteria (com.manydesigns.portofino.persistence.TableCriteria)2 SelectionProviderReference (com.manydesigns.portofino.resourceactions.m2m.configuration.SelectionProviderReference)2 Serializable (java.io.Serializable)2 Annotation (java.lang.annotation.Annotation)2 BigDecimal (java.math.BigDecimal)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2