Search in sources :

Example 1 with AbstractConfigurationObject

use of com.vaadin.addon.charts.model.AbstractConfigurationObject in project charts by vaadin.

the class ChartDesignReader method addToConfiguration.

private static void addToConfiguration(Element element, AbstractConfigurationObject parent) {
    resolvePropertySettersFor(parent.getClass());
    Object value = createValueObjectForElement(element, parent);
    readTextContentNodes(element, value);
    readAttributeValues(element, value);
    setValueToParent(parent, element, value);
    if (element.children().size() > 0 && value instanceof AbstractConfigurationObject) {
        addToConfiguration(element.children(), (AbstractConfigurationObject) value);
    }
}
Also used : AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject) AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject)

Example 2 with AbstractConfigurationObject

use of com.vaadin.addon.charts.model.AbstractConfigurationObject in project charts by vaadin.

the class ChartDesignWriter method resolveDefaultConfiguration.

private static AbstractConfigurationObject resolveDefaultConfiguration(Class<? extends AbstractConfigurationObject> clazz) {
    if (cache.containsKey(clazz)) {
        return cache.get(clazz);
    }
    AbstractConfigurationObject defaultObject = readDefaultFromChartConfigurationObject(clazz);
    if (defaultObject == null) {
        try {
            defaultObject = clazz.newInstance();
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Was not able to create default instance for" + clazz.getName());
        }
    }
    cache.put(clazz, defaultObject);
    return defaultObject;
}
Also used : AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject) DesignException(com.vaadin.ui.declarative.DesignException)

Example 3 with AbstractConfigurationObject

use of com.vaadin.addon.charts.model.AbstractConfigurationObject in project charts by vaadin.

the class ChartDesignWriter method writeAttribute.

private static void writeAttribute(AbstractConfigurationObject configuration, Element parent, Field field, DesignContext context) {
    AbstractConfigurationObject defaultConfiguration = resolveDefaultConfiguration(configuration.getClass());
    String attributeName = toNodeName(field.getName().replace("_fn_", ""));
    ChartDesignAttributeHandler.writeAttribute(configuration, attributeName, parent.attributes(), defaultConfiguration, context);
    if (ChartDesignCommon.isReservedProperty(attributeName) && parent.attributes().hasKey(attributeName)) {
        // Reserved properties should be removed from parent and re-added
        // with the prefix
        String attributeValue = parent.attributes().get(attributeName);
        parent.attributes().remove(attributeName);
        parent.attributes().put(new Attribute(ChartDesignCommon.RESERVED_PROPERTY_PREFIX + attributeName, attributeValue));
    }
}
Also used : Attribute(org.jsoup.nodes.Attribute) AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject)

Example 4 with AbstractConfigurationObject

use of com.vaadin.addon.charts.model.AbstractConfigurationObject in project charts by vaadin.

the class ChartDesignWriter method resolveFields.

private static List<Field> resolveFields(Class<? extends AbstractConfigurationObject> clazz) {
    List<Field> allFields = new ArrayList<Field>();
    for (Field field : clazz.getDeclaredFields()) {
        allFields.add(field);
    }
    Class<?> superclass = clazz.getSuperclass();
    if (superclass != null && isConfigurationObject(superclass)) {
        allFields.addAll(resolveFields((Class<? extends AbstractConfigurationObject>) superclass));
    }
    return allFields;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject)

Example 5 with AbstractConfigurationObject

use of com.vaadin.addon.charts.model.AbstractConfigurationObject in project charts by vaadin.

the class ChartDesignWriter method writeCollectionElement.

private static void writeCollectionElement(AbstractConfigurationObject configuration, Element parent, Field field, Collection collection) {
    Element element = parent.appendElement(toNodeName(field.getName()));
    StringBuilder collectionValue = new StringBuilder();
    for (Object object : collection) {
        if (collectionValue.length() > 0) {
            collectionValue.append(", ");
        }
        if (!isAttribute(object.getClass())) {
            logger.log(Level.WARNING, "Cannot convert class " + object.getClass().getName() + " in field " + field.getName() + " in a class " + configuration.getClass().getName());
            continue;
        }
        String formatted = ChartDesignAttributeHandler.getFormatter().format(object);
        collectionValue.append(formatted);
    }
    if ("".equals(collectionValue)) {
        element.remove();
    } else {
        element.appendText(collectionValue.toString());
    }
}
Also used : Element(org.jsoup.nodes.Element) AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject)

Aggregations

AbstractConfigurationObject (com.vaadin.addon.charts.model.AbstractConfigurationObject)7 DesignException (com.vaadin.ui.declarative.DesignException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Attribute (org.jsoup.nodes.Attribute)1 Element (org.jsoup.nodes.Element)1