Search in sources :

Example 1 with Type

use of org.kie.workbench.common.stunner.core.definition.annotation.property.Type in project kie-wb-common by kiegroup.

the class BackendPropertyAdapter method getType.

@Override
public PropertyType getType(final T property) {
    PropertyType pType = null;
    try {
        pType = getAnnotatedFieldValue(property, Type.class);
        // If no type found from annotations, try to figure it out given the class for the value instance.
        if (null == pType) {
            final Collection<Field> valueFields = ReflectionAdapterUtils.getFieldAnnotations(property.getClass(), Value.class);
            if (null != valueFields && !valueFields.isEmpty()) {
                final Class<?> valueType = valueFields.iterator().next().getType();
                final Class<? extends PropertyType> defaultPropertyType = DefinitionUtils.getDefaultPropertyType(valueType);
                if (null != defaultPropertyType) {
                    pType = defaultPropertyType.newInstance();
                }
            }
        }
    } catch (Exception e) {
        LOG.error("Error obtaining annotated category for Property with id " + getId(property));
    }
    if (null == pType) {
        LOG.error("No property type specified for Property with id " + getId(property));
    }
    return pType;
}
Also used : Field(java.lang.reflect.Field) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType) Type(org.kie.workbench.common.stunner.core.definition.annotation.property.Type) PropertyType(org.kie.workbench.common.stunner.core.definition.property.PropertyType)

Aggregations

Field (java.lang.reflect.Field)1 Type (org.kie.workbench.common.stunner.core.definition.annotation.property.Type)1 PropertyType (org.kie.workbench.common.stunner.core.definition.property.PropertyType)1