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 a MessageList.
Author:
Vaadin Ltd.
See Also:
  • 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

      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:
    • 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 message
      time - the time of sending the message
      userName - the user name of the message sender
      See Also:
    • 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 message
      time - the time of sending the message
      userName - the user name of the message sender
      userImage - the URL of the message sender's image
      See Also:
  • Method Details

    • 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, or null 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, or null 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} or setUserAbbreviation(String) abbreviation} is explicitly defined.

      Parameters:
      userName - the message sender's user name, or null 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 no setUserImage(String) image} is defined.
      Parameters:
      userAbbreviation - the message sender's abbreviation, or null 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, or null to remove the image
      See Also:
    • 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, or null 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 using setUserImage(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, or null to remove the resource
      See Also: