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