Class MessageListItem
- java.lang.Object
-
- com.vaadin.flow.component.messages.MessageListItem
-
- All Implemented Interfaces:
Serializable
public class MessageListItem extends Object implements Serializable
Item to render as a message component inside aMessageList
.- Author:
- Vaadin Ltd.
- See Also:
MessageList.setItems(Collection)
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MessageListItem()
Creates an empty message list item.MessageListItem(String text)
Creates a message list item with the provided text, which will be displayed as plain text in the message body.MessageListItem(String text, Instant time, String userName)
Creates a message list item with the provided text content, time and user name.MessageListItem(String text, Instant time, String userName, String userImage)
Creates a message list item with the provided text content, time and user name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addThemeNames(String... themeNames)
Adds one or more theme names to this message.String
getText()
Gets the text content of the message.Instant
getTime()
Gets the time of sending the message.String
getUserAbbreviation()
Gets the abbreviation of the message sender.Integer
getUserColorIndex()
Gets the color index of the message sender.String
getUserImage()
Gets the URL to the message sender's image.AbstractStreamResource
getUserImageResource()
Gets the image resource of the message sender's avatar.String
getUserName()
Gets the user name of the message sender.boolean
hasThemeName(String themeName)
Checks if the message has the given theme name.void
removeThemeNames(String... themeNames)
Removes one or more theme names from this message.void
setText(String text)
Sets the text content of the message.void
setTime(Instant time)
Sets the time of sending the message.void
setUserAbbreviation(String userAbbreviation)
Sets the abbreviation of the message sender.void
setUserColorIndex(Integer userColorIndex)
Sets the color index of the message sender.void
setUserImage(String userImage)
Sets the URL to the message sender's image.void
setUserImageResource(AbstractStreamResource resource)
Sets the image for the message sender's avatar.void
setUserName(String userName)
Sets the user name of the message sender.
-
-
-
Constructor Detail
-
MessageListItem
public MessageListItem()
Creates an empty message list item. Use the setter methods to configure what will be displayed in the message.
-
MessageListItem
public MessageListItem(String text)
Creates a message list item with the provided text, which will be displayed as plain text in the message body.- Parameters:
text
- the text content of the message- See Also:
setText(String)
-
MessageListItem
public MessageListItem(String text, Instant time, String userName)
Creates a message list item with the provided text content, time and user name.The text will be rendered as plain text in the message body. The time and user name will also be displayed in the message component. The user name is also used in the message's avatar.
- Parameters:
text
- the text content of the messagetime
- the time of sending the messageuserName
- the user name of the message sender- See Also:
setText(String)
,setTime(Instant)
,setUserName(String)
-
MessageListItem
public MessageListItem(String text, Instant time, String userName, String userImage)
Creates a message list item with the provided text content, time and user name.The text will be rendered as plain text in the message body. The time and user name will also be displayed in the message component. The user image will be displayed in an avatar in the message.
- Parameters:
text
- the text content of the messagetime
- the time of sending the messageuserName
- the user name of the message senderuserImage
- the URL of the message sender's image- See Also:
setText(String)
,setTime(Instant)
,setUserName(String)
,setUserImage(String)
-
-
Method Detail
-
getText
public String getText()
Gets the text content of the message.- Returns:
- the message's text content, or
null
if none is set
-
setText
public void setText(String text)
Sets the text content of the message. It will be rendered as plain text in the message body.- Parameters:
text
- the message's text content to set, ornull
to remove the content
-
getTime
public Instant getTime()
Gets the time of sending the message.- Returns:
- the time of the message, or
null
if none is set
-
setTime
public void setTime(Instant time)
Sets the time of sending the message. It will be displayed in the message component.- Parameters:
time
- the time of the message to set, ornull
to remove the time
-
getUserName
public String getUserName()
Gets the user name of the message sender.- Returns:
- the message sender's user name, or
null
if none is set
-
setUserName
public void setUserName(String userName)
Sets the user name of the message sender. It will be displayed in the message component and used in the message's avatar.In the avatar, the user name is presented in a tooltip on hover. It will be also used to generate an abbreviation that is displayed as the avatar content, when no
setUserImage(String)
image} orsetUserAbbreviation(String)
abbreviation} is explicitly defined.- Parameters:
userName
- the message sender's user name, ornull
to remove the user name
-
getUserAbbreviation
public String getUserAbbreviation()
Gets the abbreviation of the message sender.- Returns:
- the message sender's abbreviation, or
null
if none is set
-
setUserAbbreviation
public void setUserAbbreviation(String userAbbreviation)
Sets the abbreviation of the message sender. It will be used in the message's avatar, when nosetUserImage(String)
image} is defined.- Parameters:
userAbbreviation
- the message sender's abbreviation, ornull
to remove the abbreviation
-
getUserImage
public String getUserImage()
Gets the URL to the message sender's image.If the image is set as a stream resource with
setUserImageResource(AbstractStreamResource)
, this method will return a URL that is generated for that resource.- Returns:
- the URL to the message sender's image, or
null
if none is set
-
setUserImage
public void setUserImage(String userImage)
Sets the URL to the message sender's image. The image be displayed in an avatar in the message component.Setting the image with this method resets the image resource provided with
setUserImageResource(AbstractStreamResource)
- Parameters:
userImage
- the URL to the message sender's image, ornull
to remove the image- See Also:
setUserImageResource(AbstractStreamResource)
-
getUserColorIndex
public Integer getUserColorIndex()
Gets the color index of the message sender.- Returns:
- the color index, or
null
if none is set
-
setUserColorIndex
public void setUserColorIndex(Integer userColorIndex)
Sets the color index of the message sender. It's used in the avatar that is displayed in the message component.The color index defines which color will be used for the border of the avatar. Color index N applies CSS variable
--vaadin-user-color-N
to the border.- Parameters:
userColorIndex
- the color index to set, ornull
to remove it
-
addThemeNames
public void addThemeNames(String... themeNames)
Adds one or more theme names to this message. Multiple theme names can be specified by using multiple parameters.- Parameters:
themeNames
- the theme name or theme names to be added to the message
-
removeThemeNames
public void removeThemeNames(String... themeNames)
Removes one or more theme names from this message. Multiple theme names can be specified by using multiple parameters.- Parameters:
themeNames
- the theme name or theme names to be removed from the message
-
hasThemeName
public boolean hasThemeName(String themeName)
Checks if the message has the given theme name.- Parameters:
themeName
- the theme name to check for- Returns:
true
if the message has the given theme name,false
otherwise
-
getUserImageResource
public AbstractStreamResource getUserImageResource()
Gets the image resource of the message sender's avatar.- Returns:
- the image resource value, or
null
if the image has not been set, or if the image is set with a URL by usingsetUserImage(String)
-
setUserImageResource
public void setUserImageResource(AbstractStreamResource resource)
Sets the image for the message sender's avatar.Setting the image as a resource with this method overrides the image URL set with
setUserImage(String)
.- Parameters:
resource
- the image resource, ornull
to remove the resource- See Also:
setUserImage(String)
-
-