com.vaadin.ui.declarative
Class DesignContext

java.lang.Object
  extended by com.vaadin.ui.declarative.DesignContext
All Implemented Interfaces:
java.io.Serializable

public class DesignContext
extends java.lang.Object
implements java.io.Serializable

This class contains contextual information that is collected when a component tree is constructed based on HTML design template. This information includes mappings from local ids, global ids and captions to components , as well as a mapping between prefixes and package names (such as "v" -> "com.vaadin.ui").

Since:
7.4
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
 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
 
Field Summary
static java.lang.String CAPTION_ATTRIBUTE
           
static java.lang.String ID_ATTRIBUTE
           
static java.lang.String LOCAL_ID_ATTRIBUTE
           
 
Constructor Summary
DesignContext()
           
DesignContext(org.jsoup.nodes.Document doc)
           
 
Method Summary
 void addComponentCreationListener(DesignContext.ComponentCreationListener listener)
          Adds a component creation listener.
 org.jsoup.nodes.Element createElement(Component childComponent)
          Creates an html tree node corresponding to the given element.
 Component getComponentByCaption(java.lang.String caption)
          Returns a component having the specified caption.
 Component getComponentById(java.lang.String globalId)
          Returns a component having the specified global id.
 Component getComponentByLocalId(java.lang.String localId)
          Returns a component having the specified local id.
<T> T
getDefaultInstance(Component component)
          Returns the default instance for the given class.
 Component getRootComponent()
          Returns the root component of a created component hierarchy.
 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.
 void setRootComponent(Component rootComponent)
          Sets the root component of a created component hierarchy.
 boolean shouldWriteChildren(Component c, Component defaultC)
          Helper method for component write implementors to determine whether their children should be written out or not
 void writePackageMappings(org.jsoup.nodes.Document doc)
          Writes the package mappings (prefix -> package name) of this object to the specified document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID_ATTRIBUTE

public static final java.lang.String ID_ATTRIBUTE
See Also:
Constant Field Values

CAPTION_ATTRIBUTE

public static final java.lang.String CAPTION_ATTRIBUTE
See Also:
Constant Field Values

LOCAL_ID_ATTRIBUTE

public static final java.lang.String LOCAL_ID_ATTRIBUTE
See Also:
Constant Field Values
Constructor Detail

DesignContext

public DesignContext(org.jsoup.nodes.Document doc)

DesignContext

public DesignContext()
Method Detail

getComponentByLocalId

public Component getComponentByLocalId(java.lang.String localId)
Returns a component having the specified local id. If no component is found, returns null.

Parameters:
localId - The local id of the component
Returns:
a component whose local id equals localId

getComponentById

public Component getComponentById(java.lang.String globalId)
Returns a component having the specified global id. If no component is found, returns null.

Parameters:
globalId - The global id of the component
Returns:
a component whose global id equals globalId

getComponentByCaption

public Component getComponentByCaption(java.lang.String caption)
Returns a component having the specified caption. If no component is found, returns null.

Parameters:
caption - The caption of the component
Returns:
a component whose caption equals the caption given as a parameter

getDefaultInstance

public <T> T getDefaultInstance(Component component)
Returns the default instance for the given class. The instance must not be modified by the caller.

Parameters:
abstractComponent -
Returns:
the default instance for the given class. The return value must not be modified by the caller

readPackageMappings

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.


writePackageMappings

public void writePackageMappings(org.jsoup.nodes.Document doc)
Writes the package mappings (prefix -> package name) of this object to the specified document.

The prefixes are stored as tags under in the document.

Parameters:
doc - the Jsoup document tree where the package mappings are written

createElement

public org.jsoup.nodes.Element createElement(Component childComponent)
Creates an html tree node corresponding to the given element. Also initializes its attributes by calling writeDesign. As a result of the writeDesign() call, this method creates the entire subtree rooted at the returned Node.

Parameters:
childComponent - The component with state that is written in to the node
Returns:
An html tree node corresponding to the given component. The tag name of the created node is derived from the class name of childComponent.

readDesign

public Component readDesign(org.jsoup.nodes.Element componentDesign)
Reads the given design node and creates the corresponding component tree

Parameters:
componentDesign - The design element containing the description of the component to be created.
Returns:
the root component of component tree

readDesign

public void readDesign(org.jsoup.nodes.Element componentDesign,
                       Component component)
Reads the given design node and populates the given component with the corresponding component tree

Additionally registers the component id, local id and caption of the given component and all its children in the context

Parameters:
componentDesign - The design element containing the description of the component to be created
component - The component which corresponds to the design element

getRootComponent

public Component getRootComponent()
Returns the root component of a created component hierarchy.

Returns:
the root component of the hierarchy

setRootComponent

public void setRootComponent(Component rootComponent)
Sets the root component of a created component hierarchy.

Parameters:
rootComponent - the root component of the hierarchy

addComponentCreationListener

public void addComponentCreationListener(DesignContext.ComponentCreationListener listener)
Adds a component creation listener. The listener will be notified when components are created while parsing a design template

Parameters:
listener - the component creation listener to be added

removeComponentCreationListener

public void removeComponentCreationListener(DesignContext.ComponentCreationListener listener)
Removes a component creation listener.

Parameters:
listener - the component creation listener to be removed

shouldWriteChildren

public boolean shouldWriteChildren(Component c,
                                   Component defaultC)
Helper method for component write implementors to determine whether their children should be written out or not

Parameters:
c - The component being written
defaultC - The default instance for the component
Returns:
whether the children of c should be written


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.