public class Design extends Object implements Serializable
In html form a valid nonempty component hierarchy contains a single root element located under the <body> tag. A hierarchy of components is achieved by nesting other elements under the root element. An empty component hierarchy is represented as no elements under the <body> tag.
For writing a component hierarchy the root element is specified as a Component parameter or as a DesignContext object containing the root Component. An empty hierarchy can be written by giving a null root Component.
| Modifier and Type | Class and Description |
|---|---|
static interface |
Design.ComponentFactory
Callback for creating instances of a given component class when reading
designs.
|
static interface |
Design.ComponentMapper
Delegate for handling the mapping between tag names and component
instances.
|
static class |
Design.DefaultComponentFactory
Default implementation of
Design.ComponentFactory, using
Class.forName(className).newInstance() for finding the
component class and creating a component instance. |
static class |
Design.DefaultComponentMapper
Default implementation of
Design.ComponentMapper. |
| Modifier and Type | Method and Description |
|---|---|
static Design.ComponentFactory |
getComponentFactory()
Gets the currently used component factory.
|
static Design.ComponentMapper |
getComponentMapper()
Gets the currently used component mapper.
|
static DesignContext |
read(Component rootComponent)
Loads a design for the given root component.
|
static Component |
read(InputStream design)
Loads a design from the given input stream.
|
static DesignContext |
read(InputStream stream,
Component rootComponent)
Loads a design from the given stream using the given root component.
|
static DesignContext |
read(String filename,
Component rootComponent)
Loads a design from the given file name using the given root component.
|
static void |
setComponentFactory(Design.ComponentFactory componentFactory)
Sets the component factory that is used for creating component instances
based on fully qualified class names derived from a design file.
|
static void |
setComponentMapper(Design.ComponentMapper componentMapper)
Sets the component mapper that is used for resolving between tag names
and component instances.
|
static void |
write(Component component,
OutputStream outputStream)
Writes the given component tree in design format to the given output
stream.
|
static void |
write(DesignContext designContext,
OutputStream outputStream)
Writes the component, given in the design context, in design format to
the given output stream.
|
public static void setComponentFactory(Design.ComponentFactory componentFactory)
Please note that this setting is global, so care should be taken to avoid conflicting changes.
componentFactory - the component factory to set; not nullpublic static Design.ComponentFactory getComponentFactory()
setComponentFactory(ComponentFactory)public static void setComponentMapper(Design.ComponentMapper componentMapper)
Please note that this setting is global, so care should be taken to avoid conflicting changes.
componentMapper - the component mapper to set; not nullpublic static Design.ComponentMapper getComponentMapper()
setComponentMapper(ComponentMapper)public static DesignContext read(Component rootComponent) throws DesignException
This methods assumes that the component class (or a super class) has been
marked with an DesignRoot annotation and will either use the
value from the annotation to locate the design file, or will fall back to
using a design with the same same as the annotated class file (with an
.html extension)
Any Component type fields in the root component which are not
assigned (i.e. are null) are mapped to corresponding components in the
design. Matching is done based on field name in the component class and
id/local id/caption in the design file.
The type of the root component must match the root element in the design
or the root component must be a CustomComponent or
Composite. If the root is a custom component or composite, its
composition root will be populated with the design contents. Note that
even if the root component is a custom component/composite, the root
element of the design should not be to avoid nesting a custom component
in a custom component.
rootComponent - The root component of the layoutDesignException - If the design could not be loadedpublic static DesignContext read(String filename, Component rootComponent) throws DesignException
Any Component type fields in the root component which are not
assigned (i.e. are null) are mapped to corresponding components in the
design. Matching is done based on field name in the component class and
id/local id/caption in the design file.
The type of the root component must match the root element in the design
or the root component must be a CustomComponent or
Composite. If the root is a custom component or composite, its
composition root will be populated with the design contents. Note that
even if the root component is a custom component/composite, the root
element of the design should not be to avoid nesting a custom component
in a custom component.
filename - The file name to load. Loaded from the same package as the
root componentrootComponent - The root component of the layoutDesignException - If the design could not be loadedpublic static DesignContext read(InputStream stream, Component rootComponent)
Any Component type fields in the root component which are not
assigned (i.e. are null) are mapped to corresponding components in the
design. Matching is done based on field name in the component class and
id/local id/caption in the design file.
The type of the root component must match the root element in the design
or the root component must be a CustomComponent or
Composite. If the root is a custom component or composite, its
composition root will be populated with the design contents. Note that
even if the root component is a custom component/composite, the root
element of the design should not be to avoid nesting a custom component
in a custom component.
stream - The stream to read the design fromrootComponent - The root component of the layoutDesignException - If the design could not be loadedpublic static Component read(InputStream design)
design - The stream to read the design frompublic static void write(Component component, OutputStream outputStream) throws IOException
component - the root component of the component tree, null can be used for
generating an empty designoutputStream - the output stream to write the design to. The design is always
written as UTF-8IOException - if writing failspublic static void write(DesignContext designContext, OutputStream outputStream) throws IOException
designContext - The DesignContext object specifying the component hierarchy
and the local id values of the objects. If
designContext.getRootComponent() is null, an empty design will
be generated.outputStream - the output stream to write the design to. The design is always
written as UTF-8IOException - if writing failsCopyright © 2018 Vaadin Ltd. All rights reserved.