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.
Component.ErrorEvent, Component.Event, Component.Focusable, Component.ListenerClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListenerSizeable.UnitLayout.AlignmentHandler, Layout.MarginHandler, Layout.SpacingHandlerHasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListenerDESIGN_ATTR_PLAIN_TEXTSIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS| Constructor and Description |
|---|
CustomLayout()
Default constructor only used by subclasses.
|
CustomLayout(InputStream templateStream)
Constructs a custom layout with the template given in the stream.
|
CustomLayout(String template)
Constructor for custom layout with given template name.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addComponent(Component c)
Adds the component into this container.
|
void |
addComponent(Component c,
String location)
Adds the component into this container to given location.
|
void |
changeVariables(Object source,
Map<String,Object> variables)
Called when one or more variables handled by the implementing class are
changed.
|
Component |
getComponent(String location)
Gets the child-component by its location.
|
int |
getComponentCount()
Gets the number of contained components.
|
protected CustomLayoutState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected CustomLayoutState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
String |
getTemplateContents()
Get the contents of the template
|
String |
getTemplateName()
Get the name of the template
|
protected void |
initTemplateContentsFromInputStream(InputStream templateStream) |
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(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(String templateContents)
Set the contents of the template used to draw the custom layout.
|
void |
setTemplateName(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.
|
readMargin, writeMarginaddComponentAttachListener, addComponentDetachListener, addComponents, addListener, addListener, fireComponentAttachEvent, fireComponentDetachEvent, getComponentIterator, moveComponentsFrom, removeAllComponents, removeComponentAttachListener, removeComponentDetachListener, removeListener, removeListener, setHeight, setWidthaddContextClickListener, 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, removeContextClickListener, 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, setWidthUndefinedaddAttachListener, 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, setResourceclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitmarkAsDirtyisEnabled, isImmediateaddListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisibleaddAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetConnectorIdgetHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefinedaddComponents, addListener, addListener, getComponentIterator, moveComponentsFrom, removeAllComponents, removeListener, removeListenerforEach, spliteratoraddComponentAttachListener, addComponentDetachListener, removeComponentAttachListener, removeComponentDetachListenerpublic CustomLayout()
setTemplateName(String), that makes layout fetch the template
from theme, or setTemplateContents(String).public CustomLayout(InputStream templateStream) throws IOException
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 templateStreamIOExceptionpublic CustomLayout(String template)
protected void initTemplateContentsFromInputStream(InputStream templateStream) throws IOException
IOExceptionprotected CustomLayoutState getState()
AbstractComponentgetState in class AbstractLayoutprotected CustomLayoutState getState(boolean markAsDirty)
AbstractClientConnectorgetState in class AbstractComponentmarkAsDirty - true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()public void addComponent(Component c, String location)
c - the component to be added.location - the location of the component.public void addComponent(Component c)
addComponent in interface ComponentContaineraddComponent in class AbstractComponentContainerc - the component to be added.ComponentContainer.addComponent(Component)public void removeComponent(Component c)
removeComponent in interface ComponentContainerremoveComponent in class AbstractComponentContainerc - the component to be removed.ComponentContainer.removeComponent(Component)public void removeComponent(String location)
location - the Location identifier of the component.public Iterator<Component> iterator()
iterator in interface HasComponentsiterator in interface Iterable<Component>public int getComponentCount()
AbstractComponentContainer.getComponentIterator().getComponentCount in interface ComponentContainerpublic Component getComponent(String location)
location - the name of the location where the requested component
resides.public void replaceComponent(Component oldComponent, Component newComponent)
ComponentContainerThis 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.
replaceComponent in interface ComponentContaineroldComponent - the old component that will be replaced.newComponent - the new component to be replaced.public String getTemplateName()
public String getTemplateContents()
public void setTemplateName(String templateName)
templateName - public void setTemplateContents(String templateContents)
templateContents - public void changeVariables(Object source, Map<String,Object> variables)
VariableOwnerchangeVariables in interface VariableOwnersource - 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.public void paintContent(PaintTarget target) throws PaintException
LegacyComponentPaints 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.
paintContent in interface LegacyComponenttarget - the target UIDL stream where the component should paint itself
to.PaintException - if the paint operation failed.public void readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
ComponentThe 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.
readDesign in interface ComponentreadDesign in class AbstractComponentdesign - The element to obtain the state fromdesignContext - The DesignContext instance used for parsing the designpublic void writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
ComponentThe 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.
writeDesign in interface ComponentwriteDesign in class AbstractComponentdesign - 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 designCopyright © 2022 Vaadin Ltd. All rights reserved.