com.vaadin.ui
Class CustomLayout

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractComponentContainer
              extended by com.vaadin.ui.AbstractLayout
                  extended by com.vaadin.ui.CustomLayout
All Implemented Interfaces:
ConnectorEventListener, MethodEventSource, ClientConnector, Sizeable, VariableOwner, com.vaadin.shared.Connector, Component, ComponentContainer, HasComponents, HasComponents.ComponentAttachDetachNotifier, Layout, LegacyComponent, java.io.Serializable, java.lang.Iterable<Component>, java.util.EventListener

public class CustomLayout
extends AbstractLayout
implements LegacyComponent

A container component with freely designed layout and style. The layout consists of items with textually represented locations. Each item contains one sub-component, which can be any Vaadin component, such as a layout. The adapter and theme are responsible for rendering the layout with a given style by placing the items in the defined locations.

The placement of the locations is not fixed - different themes can define the locations in a way that is suitable for them. One typical example would be to create visual design for a web site as a custom layout: the visual design would define locations for "menu", "body", and "title", for example. The layout would then be implemented as an HTML template for each theme.

The default theme handles the styles that are not defined by drawing the subcomponents just as in OrderedLayout.

Since:
3.0
Author:
Vaadin Ltd.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Layout
Layout.AlignmentHandler, Layout.MarginHandler, Layout.SpacingHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
 
Field Summary
 
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
CustomLayout()
          Default constructor only used by subclasses.
CustomLayout(java.io.InputStream templateStream)
          Constructs a custom layout with the template given in the stream.
CustomLayout(java.lang.String template)
          Constructor for custom layout with given template name.
 
Method Summary
 void addComponent(Component c)
          Adds the component into this container.
 void addComponent(Component c, java.lang.String location)
          Adds the component into this container to given location.
 void changeVariables(java.lang.Object source, java.util.Map<java.lang.String,java.lang.Object> variables)
          Called when one or more variables handled by the implementing class are changed.
 Component getComponent(java.lang.String location)
          Gets the child-component by its location.
 int getComponentCount()
          Gets the number of contained components.
protected  com.vaadin.shared.ui.customlayout.CustomLayoutState getState()
          Returns the shared state bean with information to be sent from the server to the client.
protected  com.vaadin.shared.ui.customlayout.CustomLayoutState getState(boolean markAsDirty)
          Returns the shared state for this connector.
 java.lang.String getTemplateContents()
          Get the contents of the template
 java.lang.String getTemplateName()
          Get the name of the template
protected  void initTemplateContentsFromInputStream(java.io.InputStream templateStream)
           
 java.util.Iterator<Component> iterator()
          Gets the component container iterator for going trough all the components in the container.
 void paintContent(PaintTarget target)
           Paints the Paintable into a UIDL stream.
 void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
          Reads the component state from the given design.
 void removeComponent(Component c)
          Removes the component from this container.
 void removeComponent(java.lang.String location)
          Removes the component from this container from given location.
 void replaceComponent(Component oldComponent, Component newComponent)
          Replaces the component in the container with another one without changing position.
 void setTemplateContents(java.lang.String templateContents)
          Set the contents of the template used to draw the custom layout.
 void setTemplateName(java.lang.String templateName)
          Set the name of the template used to draw custom layout.
 void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
          Writes the component state to the given design.
 
Methods inherited from class com.vaadin.ui.AbstractLayout
readMargin, writeMargin
 
Methods inherited from class com.vaadin.ui.AbstractComponentContainer
addComponentAttachListener, addComponentDetachListener, addComponents, addListener, addListener, fireComponentAttachEvent, fireComponentDetachEvent, getComponentIterator, moveComponentsFrom, removeAllComponents, removeComponentAttachListener, removeComponentDetachListener, removeListener, removeListener, setHeight, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getCustomAttributes, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidthUndefined
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.LegacyComponent
markAsDirty
 
Methods inherited from interface com.vaadin.server.VariableOwner
isEnabled, isImmediate
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
 
Methods inherited from interface com.vaadin.ui.ComponentContainer
addComponents, addListener, addListener, getComponentIterator, moveComponentsFrom, removeAllComponents, removeListener, removeListener
 
Methods inherited from interface com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier
addComponentAttachListener, addComponentDetachListener, removeComponentAttachListener, removeComponentDetachListener
 

Constructor Detail

CustomLayout

public CustomLayout()
Default constructor only used by subclasses. Subclasses are responsible for setting the appropriate fields. Either setTemplateName(String), that makes layout fetch the template from theme, or setTemplateContents(String).

Since:
7.5.0

CustomLayout

public CustomLayout(java.io.InputStream templateStream)
             throws java.io.IOException
Constructs a custom layout with the template given in the stream.

Parameters:
templateStream - Stream containing template data. Must be using UTF-8 encoding. To use a String as a template use for instance new ByteArrayInputStream("<template>".getBytes()).
streamLength - Length of the templateStream
Throws:
java.io.IOException

CustomLayout

public CustomLayout(java.lang.String template)
Constructor for custom layout with given template name. Template file is fetched from "<theme>/layout/<templateName>".

Method Detail

initTemplateContentsFromInputStream

protected void initTemplateContentsFromInputStream(java.io.InputStream templateStream)
                                            throws java.io.IOException
Throws:
java.io.IOException

getState

protected com.vaadin.shared.ui.customlayout.CustomLayoutState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Overrides:
getState in class AbstractLayout
Returns:
updated component shared state

getState

protected com.vaadin.shared.ui.customlayout.CustomLayoutState getState(boolean markAsDirty)
Description copied from class: AbstractClientConnector
Returns the shared state for this connector.

Overrides:
getState in class AbstractComponent
Parameters:
markAsDirty - true if the connector should automatically be marked dirty, false otherwise
Returns:
The shared state for this connector. Never null.
See Also:
AbstractClientConnector.getState()

addComponent

public void addComponent(Component c,
                         java.lang.String location)
Adds the component into this container to given location. If the location is already populated, the old component is removed.

Parameters:
c - the component to be added.
location - the location of the component.

addComponent

public void addComponent(Component c)
Adds the component into this container. The component is added without specifying the location (empty string is then used as location). Only one component can be added to the default "" location and adding more components into that location overwrites the old components.

Specified by:
addComponent in interface ComponentContainer
Overrides:
addComponent in class AbstractComponentContainer
Parameters:
c - the component to be added.
See Also:
ComponentContainer.addComponent(Component)

removeComponent

public void removeComponent(Component c)
Removes the component from this container.

Specified by:
removeComponent in interface ComponentContainer
Overrides:
removeComponent in class AbstractComponentContainer
Parameters:
c - the component to be removed.
See Also:
ComponentContainer.removeComponent(Component)

removeComponent

public void removeComponent(java.lang.String location)
Removes the component from this container from given location.

Parameters:
location - the Location identifier of the component.

iterator

public java.util.Iterator<Component> iterator()
Gets the component container iterator for going trough all the components in the container.

Specified by:
iterator in interface HasComponents
Specified by:
iterator in interface java.lang.Iterable<Component>
Returns:
the Iterator of the components inside the container.

getComponentCount

public int getComponentCount()
Gets the number of contained components. Consistent with the iterator returned by AbstractComponentContainer.getComponentIterator().

Specified by:
getComponentCount in interface ComponentContainer
Returns:
the number of contained components

getComponent

public Component getComponent(java.lang.String location)
Gets the child-component by its location.

Parameters:
location - the name of the location where the requested component resides.
Returns:
the Component in the given location or null if not found.

replaceComponent

public void replaceComponent(Component oldComponent,
                             Component newComponent)
Description copied from interface: ComponentContainer
Replaces the component in the container with another one without changing position.

This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.

Specified by:
replaceComponent in interface ComponentContainer
Parameters:
oldComponent - the old component that will be replaced.
newComponent - the new component to be replaced.

getTemplateName

public java.lang.String getTemplateName()
Get the name of the template


getTemplateContents

public java.lang.String getTemplateContents()
Get the contents of the template


setTemplateName

public void setTemplateName(java.lang.String templateName)
Set the name of the template used to draw custom layout. With GWT-adapter, the template with name 'templatename' is loaded from VAADIN/themes/themename/layouts/templatename.html. If the theme has not been set (with Application.setTheme()), themename is 'default'.

Parameters:
templateName -

setTemplateContents

public void setTemplateContents(java.lang.String templateContents)
Set the contents of the template used to draw the custom layout.

Parameters:
templateContents -

changeVariables

public void changeVariables(java.lang.Object source,
                            java.util.Map<java.lang.String,java.lang.Object> variables)
Description copied from interface: VariableOwner
Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
Parameters:
source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - the Mapping from variable names to new variable values.

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Description copied from interface: LegacyComponent

Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.

It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.

Specified by:
paintContent in interface LegacyComponent
Parameters:
target - the target UIDL stream where the component should paint itself to.
Throws:
PaintException - if the paint operation failed.

readDesign

public void readDesign(org.jsoup.nodes.Element design,
                       DesignContext designContext)
Description copied from interface: Component
Reads the component state from the given design.

The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.

It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.

This method must not modify the design.

Specified by:
readDesign in interface Component
Overrides:
readDesign in class AbstractComponent
Parameters:
design - The element to obtain the state from
designContext - The DesignContext instance used for parsing the design

writeDesign

public void writeDesign(org.jsoup.nodes.Element design,
                        DesignContext designContext)
Description copied from interface: Component
Writes the component state to the given design.

The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.

This method must not modify the component state.

Specified by:
writeDesign in interface Component
Overrides:
writeDesign in class AbstractComponent
Parameters:
design - The element to write the component state to. Any previous attributes or child nodes are not cleared.
designContext - The DesignContext instance used for writing the design


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