Search in sources :

Example 1 with DesignException

use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.

the class ChartComponentMapper method tagToComponent.

@Override
public Component tagToComponent(String tagName, Design.ComponentFactory componentFactory, DesignContext context) {
    boolean isChartTag = Pattern.matches("^vaadin-.*-chart$", tagName);
    if (isChartTag) {
        String[] split = tagName.split("-");
        if (split.length != 3) {
            throw new DesignException("Unknown tag: " + tagName);
        }
        String typeName = split[1];
        ChartType chartType = resolveChartTypeFor(typeName);
        if (chartType == null) {
            throw new DesignException("Unknown tag: " + tagName);
        }
        return new Chart(chartType);
    }
    return super.tagToComponent(tagName, componentFactory, context);
}
Also used : DesignException(com.vaadin.ui.declarative.DesignException) ChartType(com.vaadin.addon.charts.model.ChartType) Chart(com.vaadin.addon.charts.Chart)

Example 2 with DesignException

use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.

the class ColorFactory method createGradientColor.

private static GradientColor createGradientColor(Element element) {
    Elements linearGradients = element.getElementsByTag("linear-gradient");
    Elements radialGradients = element.getElementsByTag("radial-gradient");
    if (!linearGradients.isEmpty() && radialGradients.isEmpty()) {
        Element linearGradient = linearGradients.first();
        double x1 = parseDoubleAttribute(linearGradient, "x1");
        double y1 = parseDoubleAttribute(linearGradient, "y1");
        double x2 = parseDoubleAttribute(linearGradient, "x2");
        double y2 = parseDoubleAttribute(linearGradient, "y2");
        return GradientColor.createLinear(x1, y1, x2, y2);
    }
    if (!radialGradients.isEmpty() && linearGradients.isEmpty()) {
        Element radialGradient = radialGradients.first();
        double cx = parseDoubleAttribute(radialGradient, "cx");
        double cy = parseDoubleAttribute(radialGradient, "cy");
        double r = parseDoubleAttribute(radialGradient, "r");
        return GradientColor.createRadial(cx, cy, r);
    }
    throw new DesignException("Cannot create color for element: " + element.nodeName());
}
Also used : DesignException(com.vaadin.ui.declarative.DesignException) Element(org.jsoup.nodes.Element) Elements(org.jsoup.select.Elements)

Example 3 with DesignException

use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.

the class ColorFactory method addStops.

private static void addStops(GradientColor gradientColor, Element element) {
    Elements stops = element.getElementsByTag("stops");
    for (Element stop : stops) {
        double position = parseDoubleAttribute(stop, "position");
        String color = stop.attr("color");
        if (color == null || "".equals(color)) {
            throw new DesignException("No color defined in stops: " + stop);
        }
        gradientColor.addColorStop(position, new SolidColor(color));
    }
}
Also used : DesignException(com.vaadin.ui.declarative.DesignException) Element(org.jsoup.nodes.Element) SolidColor(com.vaadin.addon.charts.model.style.SolidColor) Elements(org.jsoup.select.Elements)

Example 4 with DesignException

use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.

the class ChartDesignReader method setValueToParent.

private static void setValueToParent(AbstractConfigurationObject parent, Element element, Object value) {
    String propertyName = resolvePropertyName(element);
    Method setter = cache.get(parent.getClass()).getSetter(propertyName);
    if (setter == null) {
        throw new DesignException("Could not find setter for " + propertyName + " in class " + parent.getClass());
    }
    try {
        setter.invoke(parent, value);
    } catch (Exception e) {
        throw new DesignException("Could not set value type " + value.getClass() + " to class " + parent.getClass(), e);
    }
}
Also used : DesignException(com.vaadin.ui.declarative.DesignException) Method(java.lang.reflect.Method) DesignException(com.vaadin.ui.declarative.DesignException) IntrospectionException(java.beans.IntrospectionException)

Example 5 with DesignException

use of com.vaadin.ui.declarative.DesignException in project charts by vaadin.

the class ChartDesignReader method createPlotOptionsFor.

private static AbstractPlotOptions createPlotOptionsFor(String type) {
    String plotOptionsClassName = "com.vaadin.addon.charts.model.PlotOptions" + toClassName(type);
    try {
        Class<?> plotOptionsClass = Class.forName(plotOptionsClassName);
        Object plotOptions = plotOptionsClass.newInstance();
        return (AbstractPlotOptions) plotOptions;
    } catch (ClassNotFoundException e) {
        throw new DesignException("Cannot find plot options class: " + plotOptionsClassName);
    } catch (InstantiationException e) {
        throw new DesignException("Cannot create options class: " + plotOptionsClassName);
    } catch (IllegalAccessException e) {
        throw new DesignException("Cannot create options class: " + plotOptionsClassName);
    }
}
Also used : DesignException(com.vaadin.ui.declarative.DesignException) AbstractPlotOptions(com.vaadin.addon.charts.model.AbstractPlotOptions) AbstractConfigurationObject(com.vaadin.addon.charts.model.AbstractConfigurationObject)

Aggregations

DesignException (com.vaadin.ui.declarative.DesignException)5 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 Chart (com.vaadin.addon.charts.Chart)1 AbstractConfigurationObject (com.vaadin.addon.charts.model.AbstractConfigurationObject)1 AbstractPlotOptions (com.vaadin.addon.charts.model.AbstractPlotOptions)1 ChartType (com.vaadin.addon.charts.model.ChartType)1 SolidColor (com.vaadin.addon.charts.model.style.SolidColor)1 IntrospectionException (java.beans.IntrospectionException)1 Method (java.lang.reflect.Method)1