Example usage for com.vaadin.ui.declarative Design setComponentFactory

List of usage examples for com.vaadin.ui.declarative Design setComponentFactory

Introduction

In this page you can find the example usage for com.vaadin.ui.declarative Design setComponentFactory.

Prototype

public static void setComponentFactory(ComponentFactory componentFactory) 

Source Link

Document

Sets the component factory that is used for creating component instances based on fully qualified class names derived from a design file.

Usage

From source file:org.lucidj.vaadin.VaadinSerializer.java

License:Apache License

@Override // Serializer
public boolean serializeObject(SerializerInstance instance, Object object) {
    try {/*from   w w w. j  a va 2 s  . com*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        // TODO: BETTER WAY TO SET COMPONENT FACTORY
        Design.setComponentFactory(vcf);
        Design.write((Component) object, baos);
        instance.setValue(baos.toString("UTF-8"));
        instance.setObjectClass(Vaadin.class);
        return (true);
    } catch (Exception e) {
        log.error("Exception serializing object", e);
        return (false);
    }
}

From source file:org.lucidj.vaadin.VaadinSerializer.java

License:Apache License

@Override // Serializer
public Object deserializeObject(SerializerInstance instance) {
    Design.setComponentFactory(vcf);
    // TODO: WRAP MANAGED OBJECT
    return (Design.read(new ByteArrayInputStream(instance.getValue().getBytes())));
}

From source file:org.vaadin.declarative.DesignToJavaConverter.java

License:Apache License

public static void convertDeclarativeToJava(String packageName, String className, String baseClassName,
        InputStream input, OutputStream output) throws Exception {

    JCodeModel jCodeModel = new JCodeModel();
    JPackage jPackage = jCodeModel._package(packageName);
    JDefinedClass declarativeClass = jPackage._class(className);
    if (baseClassName != null) {
        declarativeClass._extends(jCodeModel.directClass(baseClassName));
    }//  ww  w  . j av a2 s . co  m
    JMethod init = declarativeClass.method(Modifier.PUBLIC + Modifier.STATIC, void.class, "init");
    Design.setComponentFactory(new SpyComponentFactory(jCodeModel, declarativeClass, init.body()));
    Design.read(input);
    jCodeModel.build(new MyCodeWriter(output));
}