Class CollaborationAvatarGroup

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, HasStyle, HasTheme, HasOverlayClassName, Serializable

public class CollaborationAvatarGroup extends Composite<AvatarGroup> implements HasSize, HasStyle, HasTheme, HasOverlayClassName
Extension of the AvatarGroup component which integrates with the CollaborationEngine. It updates the avatars in real time based on the other attached avatar groups connected to the same topic.
Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • CollaborationAvatarGroup

      public CollaborationAvatarGroup(UserInfo localUser, String topicId)
      Creates a new collaboration avatar group component with the provided local user and topic id.

      The provided user information is used in the local user's avatar which is displayed to the other users.

      Whenever another collaboration avatar group with the same topic id is attached to another user's UI, this avatar group is updated to include an avatar with that user's information.

      If a null topic id is provided, the component won't display any avatars, until connecting to a non-null topic with setTopic(String).

      Parameters:
      localUser - the information of the local user
      topicId - the id of the topic to connect to, or null to not connect the component to any topic
      Since:
      1.0
  • Method Details

    • setTopic

      public void setTopic(String topicId)
      Sets the topic to use with this component. The connection to the previous topic (if any) and existing avatars are removed. Connection to the new topic is opened and avatars of collaborating users in the new topic are populated to this component.

      If the topic id is null, no avatars will be displayed.

      Parameters:
      topicId - the topic id to use, or null to not use any topic
      Since:
      1.0
    • getMaxItemsVisible

      public Integer getMaxItemsVisible()
      Gets the maximum number of avatars to display, or null if no max has been set.
      Returns:
      the max number of avatars
      Since:
      1.0
      See Also:
    • setMaxItemsVisible

      public void setMaxItemsVisible(Integer max)
      Sets the the maximum number of avatars to display.

      By default, all the avatars are displayed. When max is set, the overflowing avatars are grouped into one avatar.

      Parameters:
      max - the max number of avatars, or null to remove the max
      Since:
      1.0
      See Also:
    • addThemeVariants

      public void addThemeVariants(AvatarGroupVariant... variants)
      Adds theme variants to the avatar group component.
      Parameters:
      variants - theme variants to add
      Since:
      1.0
      See Also:
      • AvatarGroup#addThemeVariants(AvatarGroupVariant...)
    • removeThemeVariants

      public void removeThemeVariants(AvatarGroupVariant... variants)
      Removes theme variants from the avatar group component.
      Parameters:
      variants - theme variants to remove
      Since:
      1.0
      See Also:
      • AvatarGroup#removeThemeVariants(AvatarGroupVariant...)
    • getI18n

      public AvatarGroup.AvatarGroupI18n getI18n()
      Gets the internationalization object previously set for this component.

      Note: updating the object content that is gotten from this method will not update the lang on the component if not set back using setI18n(AvatarGroupI18n)

      Returns:
      the i18n object. It will be null, if the i18n properties haven't been set.
      Since:
      1.0
    • setI18n

      public void setI18n(AvatarGroup.AvatarGroupI18n i18n)
      Sets the internationalization properties for this component.
      Parameters:
      i18n - the internationalized properties, not null
      Since:
      1.0
    • setImageProvider

      public void setImageProvider(CollaborationAvatarGroup.ImageProvider imageProvider)
      Sets an image provider callback for dynamically loading avatar images for a given user. The image can be loaded on-demand from a database or using any other source of IO streams.

      If no image callback is defined, then the image URL defined by UserInfo.getImage() is directly passed to the browser. This means that avatar images need to be available as static files or served dynamically from a custom servlet. This is the default.

      Usage example:

       collaborationAvatarGroup.setImageProvider(userInfo -> {
           StreamResource streamResource = new StreamResource(
                   "avatar_" + userInfo.getId(), () -> {
                       User userEntity = userRepository
                               .findById(userInfo.getId());
                       byte[] profilePicture = userEntity.getProfilePicture();
                       return new ByteArrayInputStream(profilePicture);
                   });
           streamResource.setContentType("image/png");
           return streamResource;
       });
       
      Parameters:
      imageProvider - the image provider to use, or null to use image URLs directly from the user info object
      Since:
      1.0
    • getImageProvider

      public CollaborationAvatarGroup.ImageProvider getImageProvider()
      Gets the currently used image provider callback.
      Returns:
      the current image provider callback, or null if no callback is set
      Since:
      1.0
      See Also:
    • isOwnAvatarVisible

      public boolean isOwnAvatarVisible()
      Gets whether the user's own avatar is displayed in the avatar group or not.
      Returns:
      true if the user's own avatar is included in the group, false if not
      Since:
      1.0
      See Also:
    • setOwnAvatarVisible

      public void setOwnAvatarVisible(boolean ownAvatarVisible)
      Sets whether to display user's own avatar in the avatar group or not. The default value is true.

      To display user's own avatar separately from other users, you can set this to false, create a separate Avatar component and place it anywhere you like in your view.

      Parameters:
      ownAvatarVisible - true to include user's own avatar, false to not include it
      Since:
      1.0
    • createOwnAvatar

      public Avatar createOwnAvatar()
      Creates an instance of the user's own Avatar in this avatar group.
      Returns:
      an instance of the user's own avatar