Class Tree<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.Composite
-
- com.vaadin.ui.Tree<T>
-
- Type Parameters:
T
- the data type
- All Implemented Interfaces:
HasDataProvider<T>
,HasHierarchicalDataProvider<T>
,HasItems<T>
,ContextClickEvent.ContextClickNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,HasComponents
,Serializable
,Iterable<Component>
public class Tree<T> extends Composite implements HasHierarchicalDataProvider<T>, Component.Focusable
Tree component. A Tree can be used to select an item from a hierarchical set of items.- Since:
- 8.1
- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Tree.ItemClick<T>
Tree item click event.static interface
Tree.ItemClickListener<T>
A listener for item click events.static class
Tree.TreeContextClickEvent<T>
ContextClickEvent for the Tree Component.static class
Tree.TreeMultiSelectionModel<T>
Custom MultiSelectionModel for Tree.class
Tree.TreeRenderer
String renderer that handles icon resources and stores their identifiers into data objects.-
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.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
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
Constructors Constructor Description Tree()
Constructs a new Tree Component.Tree(HierarchicalDataProvider<T,?> dataProvider)
Constructs a new Tree Component with givenHierarchicalDataProvider
.Tree(String caption)
Constructs a new Tree Component with given caption.Tree(String caption, HierarchicalDataProvider<T,?> dataProvider)
Constructs a new Tree Component with given caption andHierarchicalDataProvider
.Tree(String caption, TreeData<T> treeData)
Constructs a new Tree Component with given caption andTreeData
.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Registration
addCollapseListener(CollapseEvent.CollapseListener<T> listener)
Adds a CollapseListener to this Tree.Registration
addContextClickListener(ContextClickEvent.ContextClickListener listener)
Adds a context click listener that gets notified when a context click happens.Registration
addExpandListener(ExpandEvent.ExpandListener<T> listener)
Adds an ExpandListener to this Tree.Registration
addItemClickListener(Tree.ItemClickListener<T> listener)
Adds an item click listener.Registration
addSelectionListener(SelectionListener<T> listener)
Adds a selection listener to the current selection model.void
addStyleName(String style)
Adds one or more style names to this component.MultiSelect<T>
asMultiSelect()
Use this tree as a multi select inBinder
.SingleSelect<T>
asSingleSelect()
Use this tree as a single select inBinder
.void
collapse(Collection<T> items)
Collapse the given items.void
collapse(T... items)
Collapse the given items.void
collapseRecursively(Collection<T> items, int depth)
Collapse the given items and their children recursively until the given depth.protected TreeGrid<T>
createTreeGrid()
Create innerTreeGrid
object.void
deselect(T item)
This method is a shorthand that delegates to the currently set selection model.protected T
deserializeDeclarativeRepresentation(String item)
Deserializes a string to a data item.void
expand(Collection<T> items)
Expands the given items.void
expand(T... items)
Expands the given items.void
expandRecursively(Collection<T> items, int depth)
Expands the given items and their children recursively until the given depth.protected void
fireCollapseEvent(T item, boolean userOriginated)
Fires a collapse event with given item.protected void
fireExpandEvent(T item, boolean userOriginated)
Fires an expand event with given item.void
focus()
Sets the focus for this component if the component isComponent.Focusable
.String
getCaption()
Gets the caption of the component.ErrorMessage
getComponentError()
Gets the component's error message.ContentMode
getContentMode()
Gets the currently set content mode of the item captions of this Tree.HierarchicalDataProvider<T,?>
getDataProvider()
Returns the source of data items used by this listing.ErrorMessage
getErrorMessage()
Gets the error message for this component.Resource
getIcon()
Gets the icon resource of the component.String
getId()
Gets currently set debug identifier.ItemCaptionGenerator<T>
getItemCaptionGenerator()
Gets the item caption generator.ItemCollapseAllowedProvider<T>
getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.DescriptionGenerator<T>
getItemDescriptionGenerator()
Gets the item description generator.IconGenerator<T>
getItemIconGenerator()
Gets the item icon generator.String
getPrimaryStyleName()
Gets the primary style name of the component.Set<T>
getSelectedItems()
This method is a shorthand that delegates to the currently set selection model.SelectionModel<T>
getSelectionModel()
Returns the selection model for this Tree.StyleGenerator<T>
getStyleGenerator()
Gets the style generator.String
getStyleName()
Gets all user-defined CSS style names of a component.int
getTabIndex()
Gets the tabulator index of theFocusable
component.boolean
isAutoRecalculateWidth()
Returns the current state of automatic width recalculation.boolean
isCaptionAsHtml()
Checks whether captions are rendered as HTMLboolean
isExpanded(T item)
Returns whether a given item is expanded or collapsed.void
readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Reads the component state from the given design.void
removeContextClickListener(ContextClickEvent.ContextClickListener listener)
Deprecated.void
removeStyleName(String style)
Removes one or more style names from component.void
scrollTo(int row)
Scrolls to a certain item, usingScrollDestination.ANY
.void
scrollTo(int row, ScrollDestination destination)
Scrolls to a certain item, using user-specified scroll destination.void
scrollToEnd()
Scrolls to the end of the last data row.void
scrollToStart()
Scrolls to the beginning of the first data row.void
select(T item)
This method is a shorthand that delegates to the currently set selection model.protected String
serializeDeclarativeRepresentation(T item)
Serializes anitem
to a string.void
setAutoRecalculateWidth(boolean autoRecalculateWidth)
Sets the automatic width recalculation on or off.void
setCaption(String caption)
Sets the caption of the component.void
setCaptionAsHtml(boolean captionAsHtml)
Sets whether the caption is rendered as HTML.void
setComponentError(ErrorMessage componentError)
Sets the component's error message.void
setContentMode(ContentMode contentMode)
Sets the content mode of the item caption.void
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.void
setDescription(String description)
Sets the component's description.void
setDescription(String description, ContentMode mode)
Sets the component's description using given contentmode
.void
setIcon(Resource icon)
Sets the component's icon.void
setId(String id)
Adds an unique id for component that is used in the client-side for testing purposes.void
setItemCaptionGenerator(ItemCaptionGenerator<T> captionGenerator)
Sets the item caption generator that is used to produce the strings shown as the text for each item.void
setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this Tree.void
setItemDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator)
Sets the description generator that is used for generating tooltip descriptions for items.void
setItemDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator, ContentMode contentMode)
Sets the description generator that is used for generating HTML tooltip descriptions for items.void
setItemIconGenerator(IconGenerator<T> iconGenerator)
Sets the item icon generator that is used to produce custom icons for items.void
setPrimaryStyleName(String style)
Changes the primary style name of the component.void
setRowHeight(double rowHeight)
Sets the height of a row.SelectionModel<T>
setSelectionMode(Grid.SelectionMode selectionMode)
Sets the tree's selection mode.void
setStyleGenerator(StyleGenerator<T> styleGenerator)
Sets the style generator that is used for generating class names for items in this tree.void
setStyleName(String style)
Sets one or more user-defined style names of the component, replacing any previous user-defined styles.void
setStyleName(String style, boolean add)
Adds or removes a style name.void
setTabIndex(int tabIndex)
Sets the tabulator index of theFocusable
component.void
writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Writes the component state to the given design.-
Methods inherited from class com.vaadin.ui.Composite
beforeClientResponse, getCompositionRoot, getDebugId, getDescription, getHeight, getHeightUnits, getState, getState, getWidth, getWidthUnits, isEnabled, iterator, setCompositionRoot, setDebugId, setEnabled, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCustomAttributes, getData, getLocale, getParent, isConnectorEnabled, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, removeListener, removeShortcutListener, setData, setHeightFull, setLocale, setParent, setReadOnly, setRequiredIndicatorVisible, setResponsive, setVisible, setWidthFull
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, 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, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleNames, attach, getDescription, getLocale, getParent, getUI, isEnabled, isVisible, removeListener, removeStyleNames, setEnabled, setParent, setVisible
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasHierarchicalDataProvider
getTreeData, setItems, setItems, setItems, setItems, setItems, setTreeData
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
Tree
public Tree()
Constructs a new Tree Component.
-
Tree
public Tree(String caption)
Constructs a new Tree Component with given caption.- Parameters:
caption
- the caption for component
-
Tree
public Tree(String caption, TreeData<T> treeData)
Constructs a new Tree Component with given caption andTreeData
.- Parameters:
caption
- the caption for componenttreeData
- the tree data for component
-
Tree
public Tree(String caption, HierarchicalDataProvider<T,?> dataProvider)
Constructs a new Tree Component with given caption andHierarchicalDataProvider
.- Parameters:
caption
- the caption for componentdataProvider
- the hierarchical data provider for component
-
Tree
public Tree(HierarchicalDataProvider<T,?> dataProvider)
Constructs a new Tree Component with givenHierarchicalDataProvider
.- Parameters:
dataProvider
- the hierarchical data provider for component
-
-
Method Detail
-
createTreeGrid
protected TreeGrid<T> createTreeGrid()
Create innerTreeGrid
object. May be overridden in subclasses.- Returns:
- new
TreeGrid
-
getDataProvider
public HierarchicalDataProvider<T,?> getDataProvider()
Description copied from interface:HasItems
Returns the source of data items used by this listing.- Specified by:
getDataProvider
in interfaceHasItems<T>
- Returns:
- the data provider, not null
-
setDataProvider
public void setDataProvider(DataProvider<T,?> dataProvider)
Description copied from interface:HasDataProvider
Sets the data provider for this listing. The data provider is queried for displayed items as needed.- Specified by:
setDataProvider
in interfaceHasDataProvider<T>
- Parameters:
dataProvider
- the data provider, not null
-
addExpandListener
public Registration addExpandListener(ExpandEvent.ExpandListener<T> listener)
Adds an ExpandListener to this Tree.- Parameters:
listener
- the listener to add- Returns:
- a registration for the listener
- See Also:
ExpandEvent
-
addCollapseListener
public Registration addCollapseListener(CollapseEvent.CollapseListener<T> listener)
Adds a CollapseListener to this Tree.- Parameters:
listener
- the listener to add- Returns:
- a registration for the listener
- See Also:
CollapseEvent
-
fireExpandEvent
protected void fireExpandEvent(T item, boolean userOriginated)
Fires an expand event with given item.- Parameters:
item
- the expanded itemuserOriginated
- whether the expand was triggered by a user interaction or the server
-
fireCollapseEvent
protected void fireCollapseEvent(T item, boolean userOriginated)
Fires a collapse event with given item.- Parameters:
item
- the collapsed itemuserOriginated
- whether the collapse was triggered by a user interaction or the server
-
expand
public void expand(T... items)
Expands the given items.If an item is currently expanded, does nothing. If an item does not have any children, does nothing.
- Parameters:
items
- the items to expand
-
expand
public void expand(Collection<T> items)
Expands the given items.If an item is currently expanded, does nothing. If an item does not have any children, does nothing.
- Parameters:
items
- the items to expand
-
expandRecursively
public void expandRecursively(Collection<T> items, int depth)
Expands the given items and their children recursively until the given depth.depth
describes the maximum distance between a given item and its descendant, meaning thatexpandRecursively(items, 0)
expands only the given items whileexpandRecursively(items, 2)
expands the given items as well as their children and grandchildren.- Parameters:
items
- the items to expand recursivelydepth
- the maximum depth of recursion- Since:
- 8.4
-
collapse
public void collapse(T... items)
Collapse the given items.For items that are already collapsed, does nothing.
- Parameters:
items
- the collection of items to collapse
-
collapse
public void collapse(Collection<T> items)
Collapse the given items.For items that are already collapsed, does nothing.
- Parameters:
items
- the collection of items to collapse
-
collapseRecursively
public void collapseRecursively(Collection<T> items, int depth)
Collapse the given items and their children recursively until the given depth.depth
describes the maximum distance between a given item and its descendant, meaning thatcollapseRecursively(items, 0)
collapses only the given items whilecollapseRecursively(items, 2)
collapses the given items as well as their children and grandchildren.- Parameters:
items
- the items to expand recursivelydepth
- the maximum depth of recursion- Since:
- 8.4
-
isExpanded
public boolean isExpanded(T item)
Returns whether a given item is expanded or collapsed.- Parameters:
item
- the item to check- Returns:
- true if the item is expanded, false if collapsed
-
getSelectedItems
public Set<T> getSelectedItems()
This method is a shorthand that delegates to the currently set selection model.- Returns:
- set of selected items
- See Also:
getSelectionModel()
-
select
public void select(T item)
This method is a shorthand that delegates to the currently set selection model.- Parameters:
item
- item to select- See Also:
SelectionModel.select(Object)
,getSelectionModel()
-
deselect
public void deselect(T item)
This method is a shorthand that delegates to the currently set selection model.- Parameters:
item
- item to deselect- See Also:
SelectionModel.deselect(Object)
,getSelectionModel()
-
addSelectionListener
public Registration addSelectionListener(SelectionListener<T> listener)
Adds a selection listener to the current selection model.NOTE: If selection mode is switched with
setSelectionMode(SelectionMode)
, then this listener is not triggered anymore when selection changes!- Parameters:
listener
- the listener to add- Returns:
- a registration handle to remove the listener
- Throws:
UnsupportedOperationException
- if selection has been disabled withGrid.SelectionMode.NONE
-
asMultiSelect
public MultiSelect<T> asMultiSelect()
Use this tree as a multi select inBinder
. ThrowsIllegalStateException
if the tree is not usingGrid.SelectionMode.MULTI
.- Returns:
- the multi select wrapper that can be used in binder
- Since:
- 8.11
-
asSingleSelect
public SingleSelect<T> asSingleSelect()
Use this tree as a single select inBinder
. ThrowsIllegalStateException
if the tree is not usingGrid.SelectionMode.SINGLE
.- Returns:
- the single select wrapper that can be used in binder
-
getSelectionModel
public SelectionModel<T> getSelectionModel()
Returns the selection model for this Tree.- Returns:
- the selection model, not
null
-
setItemCaptionGenerator
public void setItemCaptionGenerator(ItemCaptionGenerator<T> captionGenerator)
Sets the item caption generator that is used to produce the strings shown as the text for each item. By default,String.valueOf(Object)
is used.- Parameters:
captionGenerator
- the item caption provider to use, notnull
-
setItemIconGenerator
public void setItemIconGenerator(IconGenerator<T> iconGenerator)
Sets the item icon generator that is used to produce custom icons for items. The generator can returnnull
for items with no icon.- Parameters:
iconGenerator
- the item icon generator to set, notnull
- Throws:
NullPointerException
- ifitemIconGenerator
isnull
- See Also:
IconGenerator
-
setItemCollapseAllowedProvider
public void setItemCollapseAllowedProvider(ItemCollapseAllowedProvider<T> provider)
Sets the item collapse allowed provider for this Tree. The provider should returntrue
for any item that the user can collapse.Note: This callback will be accessed often when sending data to the client. The callback should not do any costly operations.
- Parameters:
provider
- the item collapse allowed provider, notnull
-
setStyleGenerator
public void setStyleGenerator(StyleGenerator<T> styleGenerator)
Sets the style generator that is used for generating class names for items in this tree. Returning null from the generator results in no custom style name being set.- Parameters:
styleGenerator
- the item style generator to set, notnull
- Throws:
NullPointerException
- ifstyleGenerator
isnull
- See Also:
StyleGenerator
-
setItemDescriptionGenerator
public void setItemDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator)
Sets the description generator that is used for generating tooltip descriptions for items.- Parameters:
descriptionGenerator
- the item description generator to set, ornull
to remove a previously set generator- Since:
- 8.2
-
setItemDescriptionGenerator
public void setItemDescriptionGenerator(DescriptionGenerator<T> descriptionGenerator, ContentMode contentMode)
Sets the description generator that is used for generating HTML tooltip descriptions for items.- Parameters:
descriptionGenerator
- the item description generator to set, ornull
to remove a previously set generatorcontentMode
- how client should interpret textual values- Since:
- 8.4
-
getItemCaptionGenerator
public ItemCaptionGenerator<T> getItemCaptionGenerator()
Gets the item caption generator.- Returns:
- the item caption generator
-
getItemIconGenerator
public IconGenerator<T> getItemIconGenerator()
Gets the item icon generator.- Returns:
- the item icon generator
- See Also:
IconGenerator
-
getItemCollapseAllowedProvider
public ItemCollapseAllowedProvider<T> getItemCollapseAllowedProvider()
Gets the item collapse allowed provider.- Returns:
- the item collapse allowed provider
-
getStyleGenerator
public StyleGenerator<T> getStyleGenerator()
Gets the style generator.- Returns:
- the item style generator
- See Also:
StyleGenerator
-
getItemDescriptionGenerator
public DescriptionGenerator<T> getItemDescriptionGenerator()
Gets the item description generator.- Returns:
- the item description generator
- Since:
- 8.2
-
addItemClickListener
public Registration addItemClickListener(Tree.ItemClickListener<T> listener)
Adds an item click listener. The listener is called when an item of thisTree
is clicked.- Parameters:
listener
- the item click listener, not null- Returns:
- a registration for the listener
- See Also:
addContextClickListener(com.vaadin.event.ContextClickEvent.ContextClickListener)
-
setSelectionMode
public SelectionModel<T> setSelectionMode(Grid.SelectionMode selectionMode)
Sets the tree's selection mode.The built-in selection modes are:
Grid.SelectionMode.SINGLE
the default modelGrid.SelectionMode.MULTI
Grid.SelectionMode.NONE
preventing selection
- Parameters:
selectionMode
- the selection mode to switch to, notnull
- Returns:
- the used selection model
- See Also:
Grid.SelectionMode
-
setCaption
public void setCaption(String caption)
Description copied from interface:Component
Sets the caption of the component.A caption is an explanatory textual label accompanying a user interface component, usually shown above, left of, or inside the component. Icon (see
setIcon()
is closely related to caption and is usually displayed horizontally before or after it, depending on the component and the containing layout.The caption can usually also be given as the first parameter to a constructor, though some components do not support it.
RichTextArea area = new RichTextArea(); area.setCaption("You can edit stuff here"); area.setValue("<h1>Helpful Heading</h1>" + "<p>All this is for you to edit.</p>");
The contents of a caption are automatically quoted, so no raw HTML can be rendered in a caption. The validity of the used character encoding, usually UTF-8, is not checked.
The caption of a component is, by default, managed and displayed by the layout component or component container in which the component is placed. For example, the
VerticalLayout
component shows the captions left-aligned above the contained components, while theFormLayout
component shows the captions on the left side of the vertically laid components, with the captions and their associated components left-aligned in their own columns. TheCustomComponent
does not manage the caption of its composition root, so if the root component has a caption, it will not be rendered. Some components, such asButton
andPanel
, manage the caption themselves and display it inside the component.- Specified by:
setCaption
in interfaceComponent
- Overrides:
setCaption
in classComposite
- Parameters:
caption
- the new caption for the component. If the caption isnull
, no caption is shown and it does not normally take any space
-
getCaption
public String getCaption()
Description copied from interface:Component
Gets the caption of the component.See
Component.setCaption(String)
for a detailed description of the caption.- Specified by:
getCaption
in interfaceComponent
- Overrides:
getCaption
in classComposite
- Returns:
- the caption of the component or
null
if the caption is not set. - See Also:
Component.setCaption(String)
-
setIcon
public void setIcon(Resource icon)
Description copied from class:AbstractComponent
Sets the component's icon.- Specified by:
setIcon
in interfaceComponent
- Overrides:
setIcon
in classComposite
- Parameters:
icon
- the icon to be shown with the component's caption.- See Also:
Component.getIcon()
,Component.setCaption(String)
-
getIcon
public Resource getIcon()
Description copied from interface:Component
Gets the icon resource of the component.See
Component.setIcon(Resource)
for a detailed description of the icon.- Specified by:
getIcon
in interfaceComponent
- Overrides:
getIcon
in classComposite
- Returns:
- the icon resource of the component or
null
if the component has no icon - See Also:
Component.setIcon(Resource)
-
getStyleName
public String getStyleName()
Description copied from interface:Component
Gets all user-defined CSS style names of a component. If the component has multiple style names defined, the return string is a space-separated list of style names. Built-in style names defined in Vaadin or GWT are not returned.The style names are returned only in the basic form in which they were added; each user-defined style name shows as two CSS style class names in the rendered HTML: one as it was given and one prefixed with the component-specific style name. Only the former is returned.
- Specified by:
getStyleName
in interfaceComponent
- Overrides:
getStyleName
in classComposite
- Returns:
- the style name or a space-separated list of user-defined style names of the component
- See Also:
Component.setStyleName(String)
,Component.addStyleName(String)
,Component.removeStyleName(String)
-
setStyleName
public void setStyleName(String style)
Description copied from interface:Component
Sets one or more user-defined style names of the component, replacing any previous user-defined styles. Multiple styles can be specified as a space-separated list of style names. The style names must be valid CSS class names and should not conflict with any built-in style names in Vaadin or GWT.Label label = new Label("This text has a lot of style"); label.setStyleName("myonestyle myotherstyle");
Each style name will occur in two versions: one as specified and one that is prefixed with the style name of the component. For example, if you have a
Button
component and give it "mystyle
" style, the component will have both "mystyle
" and "v-button-mystyle
" styles. You could then style the component either with:.myonestyle {background: blue;}
or
.v-button-myonestyle {background: blue;}
It is normally a good practice to use
addStyleName()
rather than this setter, as different software abstraction layers can then add their own styles without accidentally removing those defined in other layers.- Specified by:
setStyleName
in interfaceComponent
- Overrides:
setStyleName
in classComposite
- Parameters:
style
- the new style or styles of the component as a space-separated list- See Also:
Component.getStyleName()
,Component.addStyleName(String)
,Component.removeStyleName(String)
-
setStyleName
public void setStyleName(String style, boolean add)
Description copied from interface:Component
Adds or removes a style name. Multiple styles can be specified as a space-separated list of style names. If theadd
parameter is true, the style name is added to the component. If theadd
parameter is false, the style name is removed from the component.Functionally this is equivalent to using
Component.addStyleName(String)
orComponent.removeStyleName(String)
- Specified by:
setStyleName
in interfaceComponent
- Overrides:
setStyleName
in classComposite
- Parameters:
style
- the style name to be added or removedadd
-true
to add the given style,false
to remove it- See Also:
Component.addStyleName(String)
,Component.removeStyleName(String)
-
addStyleName
public void addStyleName(String style)
Description copied from interface:Component
Adds one or more style names to this component. Multiple styles can be specified as a space-separated list of style names. The style name will be rendered as a HTML class name, which can be used in a CSS definition.Label label = new Label("This text has style"); label.addStyleName("mystyle");
Each style name will occur in two versions: one as specified and one that is prefixed with the style name of the component. For example, if you have a
Button
component and give it "mystyle
" style, the component will have both "mystyle
" and "v-button-mystyle
" styles. You could then style the component either with:.mystyle {font-style: italic;}
or
.v-button-mystyle {font-style: italic;}
- Specified by:
addStyleName
in interfaceComponent
- Overrides:
addStyleName
in classComposite
- Parameters:
style
- the new style to be added to the component- See Also:
Component.getStyleName()
,Component.setStyleName(String)
,Component.removeStyleName(String)
-
removeStyleName
public void removeStyleName(String style)
Description copied from interface:Component
Removes one or more style names from component. Multiple styles can be specified as a space-separated list of style names.The parameter must be a valid CSS style name. Only user-defined style names added with
addStyleName()
orsetStyleName()
can be removed; built-in style names defined in Vaadin or GWT can not be removed.- Specified by:
removeStyleName
in interfaceComponent
- Overrides:
removeStyleName
in classComposite
- Parameters:
style
- the style name or style names to be removed- See Also:
Component.getStyleName()
,Component.setStyleName(String)
,Component.addStyleName(String)
-
getPrimaryStyleName
public String getPrimaryStyleName()
Description copied from interface:Component
Gets the primary style name of the component. SeeComponent.setPrimaryStyleName(String)
for a better description of the primary stylename.- Specified by:
getPrimaryStyleName
in interfaceComponent
- Overrides:
getPrimaryStyleName
in classComposite
- Returns:
- the primary style name
-
setPrimaryStyleName
public void setPrimaryStyleName(String style)
Description copied from interface:Component
Changes the primary style name of the component.The primary style name identifies the component when applying the CSS theme to the Component. By changing the style name all CSS rules targeted for that style name will no longer apply, and might result in the component not working as intended.
To preserve the original style of the component when changing to a new primary style you should make your new primary style inherit the old primary style using the SASS @include directive. See more in the SASS tutorials.
- Specified by:
setPrimaryStyleName
in interfaceComponent
- Overrides:
setPrimaryStyleName
in classComposite
- Parameters:
style
- The new primary style name
-
setId
public void setId(String id)
Description copied from interface:Component
Adds an unique id for component that is used in the client-side for testing purposes. Keeping identifiers unique is the responsibility of the programmer.
-
getId
public String getId()
Description copied from interface:Component
Gets currently set debug identifier.
-
setCaptionAsHtml
public void setCaptionAsHtml(boolean captionAsHtml)
Description copied from class:AbstractComponent
Sets whether the caption is rendered as HTML.If set to true, the captions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the caption is rendered in the browser as plain text.
The default is false, i.e. to render that caption as plain text.
- Overrides:
setCaptionAsHtml
in classComposite
- Parameters:
captionAsHtml
- true if the captions are rendered as HTML, false if rendered as plain text
-
isCaptionAsHtml
public boolean isCaptionAsHtml()
Description copied from class:AbstractComponent
Checks whether captions are rendered as HTMLThe default is false, i.e. to render that caption as plain text.
- Overrides:
isCaptionAsHtml
in classComposite
- Returns:
- true if the captions are rendered as HTML, false if rendered as plain text
-
setDescription
public void setDescription(String description)
Description copied from class:AbstractComponent
Sets the component's description. SeeAbstractComponent.getDescription()
for more information on what the description is.- Overrides:
setDescription
in classComposite
- Parameters:
description
- the new description string for the component.- See Also:
AbstractComponent.setDescription(String, ContentMode)
-
setDescription
public void setDescription(String description, ContentMode mode)
Description copied from class:AbstractComponent
Sets the component's description using given contentmode
. SeeAbstractComponent.getDescription()
for more information on what the description is.If the content
mode
is ContentMode.HTML the description is displayed as HTML in tooltips or directly in certain components so care should be taken to avoid creating the possibility for HTML injection and possibly XSS vulnerabilities.- Overrides:
setDescription
in classComposite
- Parameters:
description
- the new description string for the component.mode
- the content mode for the description
-
getErrorMessage
public ErrorMessage getErrorMessage()
Description copied from class:AbstractComponent
Gets the error message for this component.- Overrides:
getErrorMessage
in classComposite
- Returns:
- ErrorMessage containing the description of the error state of the component or null, if the component contains no errors. Extending classes should override this method if they support other error message types such as validation errors or buffering errors. The returned error message contains information about all the errors.
-
getComponentError
public ErrorMessage getComponentError()
Description copied from class:AbstractComponent
Gets the component's error message.- Overrides:
getComponentError
in classComposite
- Returns:
- the component's error message.
-
setComponentError
public void setComponentError(ErrorMessage componentError)
Description copied from class:AbstractComponent
Sets the component's error message. The message may contain certain XML tags, for more information seeErrorMessage
.- Overrides:
setComponentError
in classComposite
- Parameters:
componentError
- the newErrorMessage
of the component.
-
setRowHeight
public void setRowHeight(double rowHeight)
Sets the height of a row. If -1 (default), the row height is calculated based on the theme for an empty row before the Tree is displayed.- Parameters:
rowHeight
- The height of a row in pixels or -1 for automatic calculation
-
getContentMode
public ContentMode getContentMode()
Gets the currently set content mode of the item captions of this Tree.- Returns:
- the content mode of the item captions of this Tree
- Since:
- 8.1.3
- See Also:
ContentMode
-
setContentMode
public void setContentMode(ContentMode contentMode)
Sets the content mode of the item caption.- Parameters:
contentMode
- the content mode- See Also:
ContentMode
-
isAutoRecalculateWidth
public boolean isAutoRecalculateWidth()
Returns the current state of automatic width recalculation.- Returns:
true
if enabled;false
if disabled- Since:
- 8.1.1
-
setAutoRecalculateWidth
public void setAutoRecalculateWidth(boolean autoRecalculateWidth)
Sets the automatic width recalculation on or off. This feature is on by default.- Parameters:
autoRecalculateWidth
-true
to enable recalculation;false
to turn it off- Since:
- 8.1.1
-
addContextClickListener
public Registration addContextClickListener(ContextClickEvent.ContextClickListener listener)
Adds a context click listener that gets notified when a context click happens.- Specified by:
addContextClickListener
in interfaceContextClickEvent.ContextClickNotifier
- Overrides:
addContextClickListener
in classAbstractComponent
- Parameters:
listener
- the context click listener to add, not null actual event provided to the listener isTree.TreeContextClickEvent
- Returns:
- a registration object for removing the listener
- Since:
- 8.1
- See Also:
addItemClickListener(com.vaadin.ui.Tree.ItemClickListener<T>)
,Registration
-
removeContextClickListener
@Deprecated public void removeContextClickListener(ContextClickEvent.ContextClickListener listener)
Deprecated.Description copied from interface:ContextClickEvent.ContextClickNotifier
Removes a context click listener that was previously added withContextClickEvent.ContextClickNotifier.addContextClickListener(ContextClickListener)
.- Specified by:
removeContextClickListener
in interfaceContextClickEvent.ContextClickNotifier
- Overrides:
removeContextClickListener
in classAbstractComponent
- Parameters:
listener
- the context click listener to remove
-
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 interfaceComponent
- Overrides:
writeDesign
in classAbstractComponent
- 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
-
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 interfaceComponent
- Overrides:
readDesign
in classAbstractComponent
- Parameters:
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the design
-
deserializeDeclarativeRepresentation
protected T deserializeDeclarativeRepresentation(String item)
Deserializes a string to a data item. Used when reading from the declarative format of this Tree.Default implementation is able to handle only
String
as an item type. There will be aClassCastException
ifT
is not aString
.- Parameters:
item
- string to deserialize- Returns:
- deserialized item
- Throws:
ClassCastException
- if typeT
is not aString
- Since:
- 8.1.3
- See Also:
serializeDeclarativeRepresentation(Object)
-
serializeDeclarativeRepresentation
protected String serializeDeclarativeRepresentation(T item)
Serializes anitem
to a string. Used when saving this Tree to its declarative format.Default implementation delegates a call to
item.toString()
.- Parameters:
item
- a data item- Returns:
- string representation of the
item
. - Since:
- 8.1.3
- See Also:
deserializeDeclarativeRepresentation(String)
-
scrollTo
public void scrollTo(int row) throws IllegalArgumentException
Scrolls to a certain item, usingScrollDestination.ANY
.If the item has an open details row, its size will also be taken into account.
- Parameters:
row
- zero based index of the item to scroll to in the current view.- Throws:
IllegalArgumentException
- if the provided row is outside the item range- Since:
- 8.2
-
scrollTo
public void scrollTo(int row, ScrollDestination destination)
Scrolls to a certain item, using user-specified scroll destination.If the item has an open details row, its size will also be taken into account.
- Parameters:
row
- zero based index of the item to scroll to in the current view.destination
- value specifying desired position of scrolled-to row, notnull
- Throws:
IllegalArgumentException
- if the provided row is outside the item range- Since:
- 8.2
-
scrollToStart
public void scrollToStart()
Scrolls to the beginning of the first data row.- Since:
- 8.2
-
scrollToEnd
public void scrollToEnd()
Scrolls to the end of the last data row.- Since:
- 8.2
-
getTabIndex
public int getTabIndex()
Description copied from interface:Component.Focusable
Gets the tabulator index of theFocusable
component.- Specified by:
getTabIndex
in interfaceComponent.Focusable
- Returns:
- tab index set for the
Focusable
component - See Also:
Component.Focusable.setTabIndex(int)
-
setTabIndex
public void setTabIndex(int tabIndex)
Description copied from interface:Component.Focusable
Sets the tabulator index of theFocusable
component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.Form loginBox = new Form(); loginBox.setCaption("Login"); layout.addComponent(loginBox); // Create the first field which will be focused TextField username = new TextField("User name"); loginBox.addField("username", username); // Set focus to the user name username.focus(); TextField password = new TextField("Password"); loginBox.addField("password", password); Button login = new Button("Login"); loginBox.getFooter().addComponent(login); // An additional component which natural focus order would // be after the button. CheckBox remember = new CheckBox("Remember me"); loginBox.getFooter().addComponent(remember); username.setTabIndex(1); password.setTabIndex(2); remember.setTabIndex(3); // Different than natural place login.setTabIndex(4);
After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.
If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.
A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.
- Specified by:
setTabIndex
in interfaceComponent.Focusable
- Parameters:
tabIndex
- the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.- See Also:
Component.Focusable.getTabIndex()
-
focus
public void focus()
Description copied from class:AbstractComponent
Sets the focus for this component if the component isComponent.Focusable
.- Specified by:
focus
in interfaceComponent.Focusable
- Overrides:
focus
in classAbstractComponent
- See Also:
FieldEvents
,FieldEvents.FocusEvent
,FieldEvents.FocusListener
,FieldEvents.BlurEvent
,FieldEvents.BlurListener
-
-