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