public class CssLayout extends AbstractLayout implements LayoutEvents.LayoutClickNotifier
In comparison to HorizontalLayout
and VerticalLayout
With CustomLayout
one can often achieve similar results (good looking
layouts with web technologies), but with CustomLayout developer needs to work
with fixed templates.
By extending CssLayout one can also inject some css rules straight to child
components using getCss(Component)
.
(*) Relative sizes (set from server side) are treated bit differently than in other layouts in Vaadin. In cssLayout the size is calculated relatively to CSS layouts content area which is pretty much as in html and css. In other layouts the size of component is calculated relatively to the "slot" given by layout.
Also note that client side framework in Vaadin modifies inline style properties width and height. This happens on each update to component. If one wants to set component sizes with CSS, component must have undefined size on server side (which is not the default for all components) and the size must be defined with class styles - not by directly injecting width and height.
Layout.AlignmentHandler, Layout.MarginHandler, Layout.SpacingHandler
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
Modifier and Type | Field and Description |
---|---|
protected LinkedList<Component> |
components
Custom layout slots containing the components.
|
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
CssLayout()
Constructs an empty CssLayout.
|
CssLayout(Component... children)
Constructs a CssLayout with the given components in the given order.
|
Modifier and Type | Method and Description |
---|---|
void |
addComponent(Component c)
Add a component into this container.
|
void |
addComponent(Component c,
int index)
Adds a component into indexed position in this container.
|
void |
addComponentAsFirst(Component c)
Adds a component into this container.
|
Registration |
addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
Add a click listener to the layout.
|
void |
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the
client.
|
Component |
getComponent(int index)
Returns the component at the given position.
|
int |
getComponentCount()
Gets the number of contained components.
|
int |
getComponentIndex(Component component)
Returns the index of the given component.
|
protected String |
getCss(Component c)
Returns styles to be applied to given component.
|
protected CssLayoutState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected CssLayoutState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
Iterator<Component> |
iterator()
Gets the component container iterator for going trough all the components
in the container.
|
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 |
removeLayoutClickListener(LayoutEvents.LayoutClickListener listener)
Deprecated.
|
void |
replaceComponent(Component oldComponent,
Component newComponent)
Replaces the component in the container with another one without changing
position.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Writes the component state to the given design.
|
readMargin, writeMargin
addComponentAttachListener, addComponentDetachListener, addComponents, fireComponentAttachEvent, fireComponentDetachEvent, getComponentIterator, moveComponentsFrom, removeAllComponents, removeComponentAttachListener, removeComponentDetachListener, setHeight, setWidth
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getCustomAttributes, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setReadOnly, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidthUndefined
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, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addComponents, getComponentIterator, moveComponentsFrom, removeAllComponents
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
addAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
forEach, spliterator
addComponentAttachListener, addComponentDetachListener, removeComponentAttachListener, removeComponentDetachListener
protected LinkedList<Component> components
public CssLayout()
public CssLayout(Component... children)
children
- Components to add to the container.AbstractComponentContainer.addComponents(Component...)
public void addComponent(Component c)
addComponent
in interface ComponentContainer
addComponent
in class AbstractComponentContainer
c
- the component to be added.ComponentContainer.addComponent(Component)
public void addComponentAsFirst(Component c)
c
- the component to be added.public void addComponent(Component c, int index)
c
- the component to be added.index
- the index of the component position. The components currently
in and after the position are shifted forwards.public void removeComponent(Component c)
removeComponent
in interface ComponentContainer
removeComponent
in class AbstractComponentContainer
c
- the component to be removed.ComponentContainer.removeComponent(Component)
public Iterator<Component> iterator()
iterator
in interface HasComponents
iterator
in interface Iterable<Component>
public int getComponentCount()
AbstractComponentContainer.getComponentIterator()
.getComponentCount
in interface ComponentContainer
public void beforeClientResponse(boolean initial)
ClientConnector
beforeClientResponse
in interface ClientConnector
beforeClientResponse
in class AbstractComponent
initial
- true
if the client-side connector will be created
and initialized after this method has been invoked.
false
if there is already an initialized
client-side connector.protected CssLayoutState getState()
AbstractComponent
getState
in class AbstractLayout
protected CssLayoutState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractLayout
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
protected String getCss(Component c)
Note that styles are injected over previous styles before actual child rendering. Previous styles are not cleared, but overridden.
Note that one most often achieves better code style, by separating
styling to theme (with custom theme and AbstractComponent.addStyleName(String)
.
With own custom styles it is also very easy to break browser
compatibility.
c
- the componentpublic void replaceComponent(Component oldComponent, Component newComponent)
ComponentContainer
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.
replaceComponent
in interface ComponentContainer
oldComponent
- the old component that will be replaced.newComponent
- the new component to be replaced.public Registration addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
LayoutEvents.LayoutClickNotifier
LayoutEvents.LayoutClickEvent
.addLayoutClickListener
in interface LayoutEvents.LayoutClickNotifier
listener
- The listener to addRegistration
@Deprecated public void removeLayoutClickListener(LayoutEvents.LayoutClickListener listener)
LayoutEvents.LayoutClickNotifier
removeLayoutClickListener
in interface LayoutEvents.LayoutClickNotifier
listener
- LayoutClickListener to be removedpublic int getComponentIndex(Component component)
component
- The component to look up.public Component getComponent(int index) throws IndexOutOfBoundsException
index
- The position of the component.IndexOutOfBoundsException
- If the index is out of range.public void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
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.
readDesign
in interface Component
readDesign
in class AbstractComponent
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designpublic void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
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.
writeDesign
in interface Component
writeDesign
in class AbstractComponent
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 designCopyright © 2018 Vaadin Ltd. All rights reserved.