use of org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl in project kie-wb-common by kiegroup.
the class SVGGeneratorImpl method generate.
@Override
public StringBuffer generate(final SVGGeneratorRequest request) throws GeneratorException {
final String name = request.getName();
final String pkg = request.getPkg();
final String typeOf = request.getImplementedType();
final String cssPath = request.getCssPath();
final Map<String, String> viewSources = request.getViewSources();
final ViewFactoryImpl viewFactory = new ViewFactoryImpl(name, pkg, typeOf);
// Process the global CSS declaration specified in the factory, if any.
final StyleSheetDefinition[] styleSheetDefinition = new StyleSheetDefinition[1];
if (null != cssPath && cssPath.trim().length() > 0) {
final InputStream cssStream = loadResource(cssPath);
if (null != cssStream) {
try {
styleSheetDefinition[0] = SVGStyleTranslator.parseStyleSheetDefinition(cssPath, cssStream);
viewFactory.setStyleSheetDefinition(styleSheetDefinition[0]);
} catch (Exception e) {
throw new RuntimeException("Error while processing the glocal CSS file [" + cssPath + "] ", e);
}
}
}
// Process all SVG files specified in the factory.
// TODO: Hmmm
final Set<String> processedSvgIds = new LinkedHashSet<>();
viewSources.forEach((fMethodName, svgPath) -> {
parseSVGViewSource(fMethodName, svgPath, styleSheetDefinition[0], result -> {
result.setId(fMethodName);
result.setFactoryMethodName(fMethodName);
viewFactory.getViewDefinitions().add(result);
});
processedSvgIds.add(fMethodName);
});
// Parse referenced svg files as well, if any.
final List<ViewDefinition<?>> referencedViewDefinitions = new LinkedList<>();
viewFactory.getViewDefinitions().stream().flatMap(v -> v.getSVGViewRefs().stream()).filter(vd -> !processedSvgIds.contains(vd.getViewRefId())).forEach(vd -> parseSVGViewSource(vd.getViewRefId(), vd.getFilePath(), styleSheetDefinition[0], result -> {
final String id = SVGGeneratorFormatUtils.getValidInstanceId(result);
result.setFactoryMethodName(id);
referencedViewDefinitions.add(result);
processedSvgIds.add(id);
}));
viewFactory.getViewDefinitions().addAll(referencedViewDefinitions);
return viewFactoryGenerator.generate(viewFactory);
}
use of org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl in project kie-wb-common by kiegroup.
the class SVGViewDefinitionGeneratorTest method testGenerate.
@Test
public void testGenerate() throws Exception {
final ViewFactory viewFactory = new ViewFactoryImpl("view1", "org.kie.test", "MyType.¢lass");
final RectDefinition mainDef = new RectDefinition("rect1", 1, 2, 0);
final CircleDefinition circleDefinition = new CircleDefinition("circle1", 25);
final ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(ID, X, Y, WIDTH, HEIGHT, styleSheetDefinition, new ViewBoxDefinitionImpl(VBOX_MIN_X, VBOX_MIN_Y, VBOX_WIDTH, VBOX_HEIGHT), mainDef, circleDefinition);
viewDefinition.setFactoryMethodName("svgViewTest");
viewDefinition.setPath("svg-view-test.svg");
final String generated = tested.generate(viewFactory, viewDefinition).toString();
assertTrue(generated.contains("public SVGShapeViewResource svgViewTest()"));
assertTrue(generated.contains("private SVGShapeView svgViewTestView(final boolean resizable)"));
assertTrue(generated.contains("return this.svgViewTestView(25.50d, 225.45d, resizable);"));
assertTrue(generated.contains("private SVGShapeView svgViewTestView(final double width, final double height, final boolean resizable) {"));
assertTrue(generated.contains("final SVGShapeViewImpl view = new SVGShapeViewImpl(\"viewDef1\", mainShape, width, height, resizable)"));
assertTrue(generated.contains("private SVGBasicShapeView svgViewTestBasicView() {"));
assertTrue(generated.contains("return this.svgViewTestBasicView(25.50d, 225.45d);"));
assertTrue(generated.contains("private SVGBasicShapeView svgViewTestBasicView(final double width, final double height) {"));
assertTrue(generated.contains("final SVGBasicShapeViewImpl view = new SVGBasicShapeViewImpl(\"viewDef1\", mainShape, width, height)"));
}
use of org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl in project kie-wb-common by kiegroup.
the class SVGViewDefinitionGeneratorTest method testCheckReferencesExist.
@Test(expected = RuntimeException.class)
public void testCheckReferencesExist() throws Exception {
final ViewFactory viewFactory = new ViewFactoryImpl("view1", "org.kie.test", "MyType.¢lass");
final RectDefinition mainDef = new RectDefinition("rect1", 1, 2, 0);
final CircleDefinition circleDefinition = new CircleDefinition("circle1", 25);
final ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(ID, X, Y, WIDTH, HEIGHT, styleSheetDefinition, new ViewBoxDefinitionImpl(VBOX_MIN_X, VBOX_MIN_Y, VBOX_WIDTH, VBOX_HEIGHT), null, mainDef, circleDefinition);
viewDefinition.setFactoryMethodName("svgViewTest");
viewDefinition.setPath("svg-view-test.svg");
final ViewRefDefinition refDefinition = new ViewRefDefinitionImpl("#circle1", "rect1", "circle1", "circle1");
viewDefinition.getSVGViewRefs().add(refDefinition);
tested.generate(viewFactory, viewDefinition).toString();
}
Aggregations