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 voidaddThemeNames(String... themeNames)Adds one or more theme names to this message.StringgetText()Gets the text content of the message.InstantgetTime()Gets the time of sending the message.StringgetUserAbbreviation()Gets the abbreviation of the message sender.IntegergetUserColorIndex()Gets the color index of the message sender.StringgetUserImage()Gets the URL to the message sender's image.com.vaadin.flow.server.AbstractStreamResourcegetUserImageResource()Gets the image resource of the message sender's avatar.StringgetUserName()Gets the user name of the message sender.booleanhasThemeName(String themeName)Checks if the message has the given theme name.voidremoveThemeNames(String... themeNames)Removes one or more theme names from this message.voidsetText(String text)Sets the text content of the message.voidsetTime(Instant time)Sets the time of sending the message.voidsetUserAbbreviation(String userAbbreviation)Sets the abbreviation of the message sender.voidsetUserColorIndex(Integer userColorIndex)Sets the color index of the message sender.voidsetUserImage(String userImage)Sets the URL to the message sender's image.voidsetUserImageResource(com.vaadin.flow.server.AbstractStreamResource resource)Sets the image for the message sender's avatar.voidsetUserName(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
nullif 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, ornullto remove the content
-
getTime
public Instant getTime()
Gets the time of sending the message.- Returns:
- the time of the message, or
nullif 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, ornullto remove the time
-
getUserName
public String getUserName()
Gets the user name of the message sender.- Returns:
- the message sender's user name, or
nullif 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, ornullto remove the user name
-
getUserAbbreviation
public String getUserAbbreviation()
Gets the abbreviation of the message sender.- Returns:
- the message sender's abbreviation, or
nullif 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, ornullto 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
nullif 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, ornullto remove the image- See Also:
setUserImageResource(AbstractStreamResource)
-
getUserColorIndex
public Integer getUserColorIndex()
Gets the color index of the message sender.- Returns:
- the color index, or
nullif 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-Nto the border.- Parameters:
userColorIndex- the color index to set, ornullto 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:
trueif the message has the given theme name,falseotherwise
-
getUserImageResource
public com.vaadin.flow.server.AbstractStreamResource getUserImageResource()
Gets the image resource of the message sender's avatar.- Returns:
- the image resource value, or
nullif the image has not been set, or if the image is set with a URL by usingsetUserImage(String)
-
setUserImageResource
public void setUserImageResource(com.vaadin.flow.server.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, ornullto remove the resource- See Also:
setUserImage(String)
-
-