Search in sources :

Example 1 with GeneratorException

use of org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException in project kie-wb-common by kiegroup.

the class CircleDefinitionGenerator method doGenerate.

@Override
public StringBuffer doGenerate(final CircleDefinition input) throws GeneratorException {
    final double radius = input.getRadius();
    final Map<String, Object> root = new HashMap<String, Object>();
    root.put("className", Circle.class.getName());
    root.put("radius", formatDouble(radius));
    // Generate the code using the given template.
    try {
        return writeTemplate(root);
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
}
Also used : Circle(com.ait.lienzo.client.core.shape.Circle) HashMap(java.util.HashMap) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 2 with GeneratorException

use of org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException in project kie-wb-common by kiegroup.

the class GroupDefinitionGenerator method generate.

@Override
public StringBuffer generate(final GroupDefinition input) throws GeneratorException {
    final StringBuffer wrapped = super.generate(input);
    final StringBuffer wrapper;
    try {
        wrapper = writeTemplate(new HashMap<>());
        super.appendDraggable(wrapper, input);
        super.appendListening(wrapped, input);
        wrapper.append(formatString(ADD_WRAPPED, wrapped.toString()));
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
    return wrapper;
}
Also used : HashMap(java.util.HashMap) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 3 with GeneratorException

use of org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException in project kie-wb-common by kiegroup.

the class RectDefinitionGenerator method doGenerate.

@Override
public StringBuffer doGenerate(final RectDefinition input) throws GeneratorException {
    final double width = input.getWidth();
    final double height = input.getHeight();
    final double radius = input.getCornerRadius();
    final Map<String, Object> root = new HashMap<String, Object>();
    root.put("className", Rectangle.class.getName());
    root.put("width", formatDouble(width));
    root.put("height", formatDouble(height));
    root.put("radius", formatDouble(radius));
    // Generate the code using the given template.
    try {
        return writeTemplate(root);
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
}
Also used : HashMap(java.util.HashMap) Rectangle(com.ait.lienzo.client.core.shape.Rectangle) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 4 with GeneratorException

use of org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException in project kie-wb-common by kiegroup.

the class SVGPrimitiveGeneratorUtils method generateSvgPrimitive.

public static String generateSvgPrimitive(final String instanceId, final Function<PrimitiveDefinition, PrimitiveDefinitionGenerator<PrimitiveDefinition<?>>> generatorProvider, final PrimitiveDefinition child, final Predicate<PrimitiveDefinition> generationFilter) {
    String childRaw = null;
    try {
        final StringBuffer childBuffer = generatorProvider.apply(child).generate(child);
        final String scalableRaw = String.valueOf(child.isScalable());
        final LayoutDefinition layoutDefinition = child.getLayoutDefinition();
        final String childLayoutRaw = formatLayout(layoutDefinition);
        if (generationFilter.test(child)) {
            if (child instanceof ShapeDefinition) {
                childRaw = AbstractGenerator.formatString(NEW_SVG_SHAPE_TEMPLATE, instanceId, childBuffer.toString(), scalableRaw, childLayoutRaw);
            } else if (child instanceof GroupDefinition) {
                final GroupDefinition groupDefinition = (GroupDefinition) child;
                final List<PrimitiveDefinition> children = groupDefinition.getChildren();
                if (children.stream().anyMatch(generationFilter)) {
                    // Generate the group primitive.
                    childRaw = AbstractGenerator.formatString(NEW_SVG_CONTAINER_TEMPLATE, instanceId, groupDefinition.getId(), childBuffer.toString(), scalableRaw, childLayoutRaw);
                    // Generate the group children ones.
                    for (final PrimitiveDefinition childDef : children) {
                        final String childDefInstanceId = SVGGeneratorFormatUtils.getValidInstanceId(childDef);
                        final String childDefRaw = generateSvgPrimitive(childDefInstanceId, generatorProvider, childDef, generationFilter);
                        if (null != childDefRaw) {
                            childRaw += childDefRaw;
                            childRaw += AbstractGenerator.formatString(GROUP_ADD_CHILD_TEMPLATE, instanceId, childDefInstanceId);
                        }
                    }
                }
            }
        }
    } catch (GeneratorException e) {
        throw new RuntimeException(e);
    }
    return childRaw;
}
Also used : ShapeDefinition(org.kie.workbench.common.stunner.svg.gen.model.ShapeDefinition) GroupDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.GroupDefinition) List(java.util.List) PrimitiveDefinition(org.kie.workbench.common.stunner.svg.gen.model.PrimitiveDefinition) LayoutDefinition(org.kie.workbench.common.stunner.svg.gen.model.LayoutDefinition) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 5 with GeneratorException

use of org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException in project kie-wb-common by kiegroup.

the class SVGViewFactoryGenerator method generate.

@Override
public StringBuffer generate(final ViewFactory viewFactory) throws GeneratorException {
    final List<StringBuffer> viewBuffers = new LinkedList<>();
    final String name = viewFactory.getSimpleName();
    final String pkg = viewFactory.getPackage();
    final List<ViewDefinition<?>> viewDefinitions = viewFactory.getViewDefinitions();
    final Map<String, String> staticFields = new LinkedHashMap<>();
    viewDefinitions.stream().forEach((viewDefinition) -> {
        try {
            if (viewDefinition instanceof ViewDefinitionImpl) {
                staticFields.putAll(((ViewDefinitionImpl) viewDefinition).getStaticFields());
            }
            final StringBuffer viewBuffer = generateView(viewFactory, viewDefinition);
            viewBuffers.add(viewBuffer);
        } catch (GeneratorException e) {
            throw new RuntimeException(e);
        }
    });
    // Generate template context.
    final List<String> viewsContent = new LinkedList<>();
    viewBuffers.forEach(b -> viewsContent.add(b.toString()));
    Map<String, Object> root = new HashMap<>();
    root.put("genClassName", this.getClass().getName());
    root.put("name", name);
    root.put("pkg", pkg);
    root.put("implementedTypeName", viewFactory.getImplementedType());
    root.put("fmethods", viewsContent);
    root.put("fields", generateStaticFields(staticFields));
    // Generate the code using the given template.
    StringBuffer result;
    try {
        result = writeTemplate(root);
    } catch (final GenerationException e) {
        throw new GeneratorException(e);
    }
    return result;
}
Also used : ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ViewDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewDefinition) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) GenerationException(org.uberfire.annotations.processors.exceptions.GenerationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Aggregations

GeneratorException (org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)10 HashMap (java.util.HashMap)7 GenerationException (org.uberfire.annotations.processors.exceptions.GenerationException)7 ViewDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl)4 LinkedList (java.util.LinkedList)3 List (java.util.List)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 LayoutDefinition (org.kie.workbench.common.stunner.svg.gen.model.LayoutDefinition)2 PrimitiveDefinition (org.kie.workbench.common.stunner.svg.gen.model.PrimitiveDefinition)2 ShapeDefinition (org.kie.workbench.common.stunner.svg.gen.model.ShapeDefinition)2 StyleSheetDefinition (org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition)2 ViewDefinition (org.kie.workbench.common.stunner.svg.gen.model.ViewDefinition)2 Document (org.w3c.dom.Document)2 Circle (com.ait.lienzo.client.core.shape.Circle)1 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 Picture (com.ait.lienzo.client.core.shape.Picture)1 Rectangle (com.ait.lienzo.client.core.shape.Rectangle)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1