public class DesignContext extends Object implements Serializable
Constants.SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX
.Modifier and Type | Class and Description |
---|---|
class |
DesignContext.ComponentCreatedEvent
Component creation event that is fired when a component is created in the
context
|
static interface |
DesignContext.ComponentCreationListener
Interface to be implemented by component creation listeners
|
Modifier and Type | Field and Description |
---|---|
static String |
CAPTION_ATTRIBUTE |
static String |
ID_ATTRIBUTE |
static String |
LOCAL_ID_ATTRIBUTE |
Constructor and Description |
---|
DesignContext() |
DesignContext(org.jsoup.nodes.Document doc) |
Modifier and Type | Method and Description |
---|---|
void |
addComponentCreationListener(DesignContext.ComponentCreationListener listener)
Adds a component creation listener.
|
void |
addPackagePrefix(String prefix,
String packageName)
Creates a two-way mapping between a prefix and a package name.
|
org.jsoup.nodes.Element |
createElement(Component childComponent)
Creates an html tree node corresponding to the given element.
|
Component |
getComponentByCaption(String caption)
Returns a component having the specified caption.
|
Component |
getComponentById(String globalId)
Returns a component having the specified global id.
|
Component |
getComponentByLocalId(String localId)
Returns a component having the specified local id.
|
String |
getComponentLocalId(Component component)
Returns the local id for a component.
|
Map<String,String> |
getCustomAttributes(Component component)
Gets the attributes that the component did not handle
|
<T> T |
getDefaultInstance(Component component)
Returns the default instance for the given class.
|
String |
getPackage(String prefix)
Gets the package corresponding to the give prefix, or
null
no package has been registered for the prefix |
String |
getPackagePrefix(String packageName)
Gets the prefix mapping for a given package, or
null if
there is no mapping for the package. |
Collection<String> |
getPackagePrefixes()
Gets all registered package prefixes.
|
Component |
getRootComponent()
Returns the root component of a created component hierarchy.
|
ShouldWriteDataDelegate |
getShouldWriteDataDelegate()
Gets the delegate that determines whether the container data of a
component should be written out.
|
protected boolean |
isLegacyPrefixEnabled()
Check whether the legacy prefix "v" or the default prefix "vaadin" should
be used when writing designs.
|
Component |
readDesign(org.jsoup.nodes.Element componentDesign)
Reads the given design node and creates the corresponding component tree
|
void |
readDesign(org.jsoup.nodes.Element componentDesign,
Component component)
Reads the given design node and populates the given component with the
corresponding component tree
|
protected void |
readPackageMappings(org.jsoup.nodes.Document doc)
Reads and stores the mappings from prefixes to package names from meta
tags located under in the html document.
|
void |
removeComponentCreationListener(DesignContext.ComponentCreationListener listener)
Removes a component creation listener.
|
boolean |
setComponentLocalId(Component component,
String localId)
Creates a mapping between the given local id and the component.
|
void |
setCustomAttribute(Component component,
String attribute,
String value)
Sets a custom attribute not handled by the component.
|
void |
setRootComponent(Component rootComponent)
Sets the root component of a created component hierarchy.
|
void |
setShouldWriteDataDelegate(ShouldWriteDataDelegate shouldWriteDataDelegate)
Sets the delegate that determines whether the container data of a
component should be written out.
|
boolean |
shouldWriteChildren(Component c,
Component defaultC)
Helper method for component write implementors to determine whether their
children should be written out or not
|
boolean |
shouldWriteData(Component component)
Determines whether the container data of a component should be written
out by delegating to a
ShouldWriteDataDelegate . |
void |
writePackageMappings(org.jsoup.nodes.Document doc)
Writes the package mappings (prefix -> package name) of this object to
the specified document.
|
public static final String ID_ATTRIBUTE
public static final String CAPTION_ATTRIBUTE
public static final String LOCAL_ID_ATTRIBUTE
public DesignContext(org.jsoup.nodes.Document doc)
public DesignContext()
public Component getComponentByLocalId(String localId)
localId
- The local id of the componentpublic Component getComponentById(String globalId)
globalId
- The global id of the componentpublic Component getComponentByCaption(String caption)
caption
- The caption of the componentpublic boolean setComponentLocalId(Component component, String localId)
component
- The component whose local id is to be set.localId
- The new local id of the component.public String getComponentLocalId(Component component)
component
- The component whose local id to get.public void addPackagePrefix(String prefix, String packageName)
prefix
- the prefix name without an ending dash (for instance, "vaadin"
is by default used for "com.vaadin.ui")packageName
- the name of the package corresponding to prefixgetPackagePrefixes()
,
getPackagePrefix(String)
,
getPackage(String)
public String getPackagePrefix(String packageName)
null
if
there is no mapping for the package.packageName
- the package name to get a prefix fornull
if no prefix is
registeredaddPackagePrefix(String, String)
,
getPackagePrefixes()
public Collection<String> getPackagePrefixes()
getPackage(String)
public String getPackage(String prefix)
null
no package has been registered for the prefixprefix
- the prefix to find a package fornull
if no package is
registered for the provided prefixaddPackagePrefix(String, String)
public <T> T getDefaultInstance(Component component)
abstractComponent
- protected void readPackageMappings(org.jsoup.nodes.Document doc)
public void writePackageMappings(org.jsoup.nodes.Document doc)
The prefixes are stored as tags under in the document.
doc
- the Jsoup document tree where the package mappings are writtenprotected boolean isLegacyPrefixEnabled()
Constants.SERVLET_PARAMETER_LEGACY_DESIGN_PREFIX
can be used to
switch to the legacy prefix.public org.jsoup.nodes.Element createElement(Component childComponent)
childComponent
- The component with state that is written in to the nodepublic Component readDesign(org.jsoup.nodes.Element componentDesign)
componentDesign
- The design element containing the description of the component
to be created.public void readDesign(org.jsoup.nodes.Element componentDesign, Component component)
Additionally registers the component id, local id and caption of the given component and all its children in the context
componentDesign
- The design element containing the description of the component
to be createdcomponent
- The component which corresponds to the design elementpublic Component getRootComponent()
public void setRootComponent(Component rootComponent)
rootComponent
- the root component of the hierarchypublic void addComponentCreationListener(DesignContext.ComponentCreationListener listener)
listener
- the component creation listener to be addedpublic void removeComponentCreationListener(DesignContext.ComponentCreationListener listener)
listener
- the component creation listener to be removedpublic boolean shouldWriteChildren(Component c, Component defaultC)
c
- The component being writtendefaultC
- The default instance for the componentpublic boolean shouldWriteData(Component component)
ShouldWriteDataDelegate
. The default
delegate assumes that all component data is provided by a data source
connected to a back end system and that the data should thus not be
written.component
- the component to checktrue
if container data should be written out for the
provided component; otherwise false
.setShouldWriteDataDelegate(ShouldWriteDataDelegate)
public void setShouldWriteDataDelegate(ShouldWriteDataDelegate shouldWriteDataDelegate)
shouldWriteDataDelegate
- the delegate to set, not null
IllegalArgumentException
- if the provided delegate is null
shouldWriteChildren(Component, Component)
,
getShouldWriteDataDelegate()
public ShouldWriteDataDelegate getShouldWriteDataDelegate()
setShouldWriteDataDelegate(ShouldWriteDataDelegate)
,
shouldWriteChildren(Component, Component)
public Map<String,String> getCustomAttributes(Component component)
component
- the component to get the attributes forpublic void setCustomAttribute(Component component, String attribute, String value)
component
- the component to set the attribute forattribute
- the attribute to setvalue
- the value of the attributeCopyright © 2019 Vaadin Ltd. All rights reserved.