Class MessageListItem
- All Implemented Interfaces:
Serializable
MessageList.- Author:
- Vaadin Ltd.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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, String userName) Creates a message list item with the provided text content and user name.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
Modifier and TypeMethodDescriptionvoidaddClassNames(String... classNames) Adds one or more class names to this item.voidaddThemeNames(String... themeNames) Adds one or more theme names to this message.voidappendText(String text) Appends the provided text to the message's text content.getText()Gets the text content of the message.getTime()Gets the time of sending the message.Gets the abbreviation of the message sender.Gets the color index of the message sender.Gets the URL to the message sender's image.Gets the image resource of the message sender's avatar.Gets the user name of the message sender.booleanhasClassName(String className) Checks if the message has the given class name.booleanhasThemeName(String themeName) Checks if the message has the given theme name.voidremoveClassNames(String... classNames) Removes one or more class names from this item.voidremoveThemeNames(String... themeNames) Removes one or more theme names from this message.voidSets the text content of the message.voidSets 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.voidsetUserImageHandler(DownloadHandler downloadHandler) Sets the image for the message sender's avatar.voidsetUserImageResource(AbstractStreamResource resource) Deprecated, for removal: This API element is subject to removal in a future version.voidsetUserName(String userName) Sets the user name of the message sender.
-
Constructor Details
-
MessageListItem
public MessageListItem()Creates an empty message list item. Use the setter methods to configure what will be displayed in the message. -
MessageListItem
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:
-
MessageListItem
Creates a message list item with the provided text content and user name.The text will be rendered as plain text in the message body. The 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 messageuserName- the user name of the message sender- See Also:
-
MessageListItem
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:
-
MessageListItem
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:
-
-
Method Details
-
getText
Gets the text content of the message.- Returns:
- the message's text content, or
nullif none is set
-
setText
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
-
appendText
Appends the provided text to the message's text content.- Parameters:
text- the text to append to the message's text content
-
getTime
Gets the time of sending the message.- Returns:
- the time of the message, or
nullif none is set
-
setTime
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
Gets the user name of the message sender.- Returns:
- the message sender's user name, or
nullif none is set
-
setUserName
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
Gets the abbreviation of the message sender.- Returns:
- the message sender's abbreviation, or
nullif none is set
-
setUserAbbreviation
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
Gets the URL to the message sender's image.If the image is set as a stream resource with
setUserImageHandler(DownloadHandler), 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
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
setUserImageHandler(DownloadHandler)- Parameters:
userImage- the URL to the message sender's image, ornullto remove the image- See Also:
-
getUserColorIndex
Gets the color index of the message sender.- Returns:
- the color index, or
nullif none is set
-
setUserColorIndex
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
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
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
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
-
addClassNames
Adds one or more class names to this item. Multiple class names can be specified by using multiple parameters.- Parameters:
classNames- the class name or class names to be added to the item
-
removeClassNames
Removes one or more class names from this item. Multiple class names can be specified by using multiple parameters.- Parameters:
classNames- the class name or class names to be removed from the item
-
hasClassName
Checks if the message has the given class name.- Parameters:
className- the class name to check for- Returns:
trueif the message has the given class name,falseotherwise
-
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)
-
setUserImageHandler
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).Sets the
Content-Dispositionheader toinlinefor pre-defined download handlers, created by factory methods inDownloadHandler, as well as for otherAbstractDownloadHandlerimplementations.- Parameters:
downloadHandler- download handler for the image resource, ornullto remove the resource- See Also:
-
setUserImageResource
@Deprecated(since="24.8", forRemoval=true) public void setUserImageResource(AbstractStreamResource resource) Deprecated, for removal: This API element is subject to removal in a future version.UsesetUserImageHandler(DownloadHandler)insteadSets 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:
-
setUserImageHandler(DownloadHandler)instead