Search in sources :

Example 6 with ViewDefinitionImpl

use of org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl in project kie-wb-common by kiegroup.

the class SVGGeneratorImpl method parseSVGViewSource.

private void parseSVGViewSource(final String viewId, final String svgPath, final StyleSheetDefinition styleSheetDefinition, final Consumer<ViewDefinitionImpl> viewDefinitionConsumer) {
    final InputStream svgStream = loadResource(svgPath);
    if (null != svgStream) {
        try {
            final ViewDefinitionImpl viewDefinition = parseSVGView(viewId, svgPath, svgStream, styleSheetDefinition);
            viewDefinitionConsumer.accept(viewDefinition);
        } catch (Exception e) {
            throw new RuntimeException("Error while processing the SVG file [" + svgPath + "]", e);
        }
    } else {
        throw new RuntimeException("No SVG file found at [" + svgPath + "]");
    }
}
Also used : ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) InputStream(java.io.InputStream) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) GeneratorException(org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)

Example 7 with ViewDefinitionImpl

use of org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl in project kie-wb-common by kiegroup.

the class SVGGeneratorImpl method translate.

private ViewDefinitionImpl translate(final String viewId, final String svgPath, final Document document, final StyleSheetDefinition styleSheetDefinition) throws Exception {
    final Path path = Paths.get(svgPath);
    final String relativePath = path.getNameCount() > 1 ? path.subpath(0, path.getNameCount() - 1).toString() : "";
    final SVGTranslatorContext context = new SVGTranslatorContext(document, relativePath, styleSheetDefinition);
    if (null != viewId) {
        context.setViewId(viewId);
    }
    final ViewDefinitionImpl viewDefinition = (ViewDefinitionImpl) translator.translate(context);
    viewDefinition.setPath(svgPath);
    viewDefinition.getStaticFields().putAll(context.getStaticStringMembers());
    return viewDefinition;
}
Also used : Path(java.nio.file.Path) ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) SVGTranslatorContext(org.kie.workbench.common.stunner.svg.gen.translator.SVGTranslatorContext)

Example 8 with ViewDefinitionImpl

use of org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl 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();
}
Also used : CircleDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition) ViewRefDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewRefDefinitionImpl) ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) ViewFactoryImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl) ViewFactory(org.kie.workbench.common.stunner.svg.gen.model.ViewFactory) ViewRefDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition) ViewBoxDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Aggregations

ViewDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl)8 GeneratorException (org.kie.workbench.common.stunner.svg.gen.exception.GeneratorException)4 LinkedList (java.util.LinkedList)3 ViewRefDefinition (org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition)3 HashMap (java.util.HashMap)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Test (org.junit.Test)2 PrimitiveDefinition (org.kie.workbench.common.stunner.svg.gen.model.PrimitiveDefinition)2 StyleSheetDefinition (org.kie.workbench.common.stunner.svg.gen.model.StyleSheetDefinition)2 ViewDefinition (org.kie.workbench.common.stunner.svg.gen.model.ViewDefinition)2 ViewFactory (org.kie.workbench.common.stunner.svg.gen.model.ViewFactory)2 CircleDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition)2 RectDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition)2 ViewBoxDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl)2 ViewFactoryImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl)2 GenerationException (org.uberfire.annotations.processors.exceptions.GenerationException)2 Document (org.w3c.dom.Document)2 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1