Class ChatAssistant<T extends Message>

All Implemented Interfaces:
AttachNotifier, ClickNotifier<Div>, DetachNotifier, HasComponents, HasElement, HasEnabled, HasOrderedComponents, HasSize, HasStyle, HasText, Serializable

@JsModule("./fc-chat-assistant-movement.js") @JsModule("./fc-chat-assistant-resize.js") @CssImport("./styles/fc-chat-assistant-style.css") @Tag("animated-fab") public class ChatAssistant<T extends Message> extends Div
Component that allows to create a floating chat button that will open a chat window that can be used to provide a chat assistant feature.
Author:
mmlopez
See Also:
  • Field Details

    • fabIcon

      protected SvgIcon fabIcon
    • fab

      protected final Button fab
    • unreadBadge

      protected final Div unreadBadge
    • fabWrapper

      protected final Div fabWrapper
    • chatWindow

      protected final Popover chatWindow
    • overlay

      protected final Div overlay
    • container

      protected final VerticalLayout container
    • resizerTop

      protected final Div resizerTop
    • resizerBottom

      protected final Div resizerBottom
    • resizerTopRight

      protected final Div resizerTopRight
    • resizerBottomRight

      protected final Div resizerBottomRight
    • resizerRight

      protected final Div resizerRight
    • resizerLeft

      protected final Div resizerLeft
    • resizerBottomLeft

      protected final Div resizerBottomLeft
    • resizerTopLeft

      protected final Div resizerTopLeft
    • DEFAULT_FAB_SIZE

      protected static final int DEFAULT_FAB_SIZE
      See Also:
    • DEFAULT_FAB_ICON_SIZE

      protected static final int DEFAULT_FAB_ICON_SIZE
      See Also:
    • DEFAULT_FAB_MARGIN

      protected static final int DEFAULT_FAB_MARGIN
      See Also:
    • DEFAULT_RESIZER_SIZE

      protected static final int DEFAULT_RESIZER_SIZE
      See Also:
    • DEFAULT_MAX_RESIZER_SIZE

      protected static final int DEFAULT_MAX_RESIZER_SIZE
      See Also:
    • DEFAULT_DRAG_SENSITIVITY

      protected static final int DEFAULT_DRAG_SENSITIVITY
      See Also:
  • Constructor Details

    • ChatAssistant

      public ChatAssistant(List<T> messages, boolean markdownEnabled)
    • ChatAssistant

      public ChatAssistant()
      Default constructor. Creates a ChatAssistant with no messages.
    • ChatAssistant

      public ChatAssistant(boolean markdownEnabled)
      Creates a ChatAssistant with no messages.
      Parameters:
      markdownEnabled - flag to enable or disable markdown support
  • Method Details

    • onAttach

      protected void onAttach(AttachEvent attachEvent)
      Overrides:
      onAttach in class Component
    • onClick

      @ClientCallable protected void onClick()
      Receives click events from the client side to toggle the chat window's opened state.
    • applyGenericResizerStyle

      protected void applyGenericResizerStyle(Div resizer, String direction)
      Applies common styles to the resizer elements based on the specified direction.
    • addComponentRefreshedListener

      protected void addComponentRefreshedListener(String uniqueFlag, String executable, Serializable... parameters)
      Adds a component refresh listener that prevents stacking up duplicate listeners on the client side. Uses a unique flag to track if the listener has already been added for this component instance, ensuring the callback only executes once per component refresh cycle.
      Parameters:
      uniqueFlag - a unique identifier for the component instance
      executable - the JavaScript action to execute when the component is refreshed,
      parameters - parameters for the executable
    • setFabIcon

      public void setFabIcon(Component icon)
      Sets the icon for the floating action button.
      The icon's size is automatically adjusted to fit within the FAB.
    • setFabIcon

      public void setFabIcon(Component icon, int size)
      Sets the icon for the floating action button. Allows customizing the icon's size.
    • setOpened

      public void setOpened(boolean opened)
      Sets the opened state of the chat window. If true, opens the window; if false, closes it.
    • open

      public void open()
      Opens the chat window.
    • close

      public void close()
      Closes the chat window.
    • isOpened

      public boolean isOpened()
      Returns true if the chat window is opened, false otherwise.
    • setWindowMinWidth

      public void setWindowMinWidth(String minWidth)
      Sets the chat window minimum width. Applies when resizing.
    • setWindowMinHeight

      public void setWindowMinHeight(String minHeight)
      Sets the chat window minimum height. Applies when resizing.
    • setWindowMaxWidth

      public void setWindowMaxWidth(String maxWidth)
      Sets the chat window maximum width. Applies when resizing.
    • setWindowMaxHeight

      public void setWindowMaxHeight(String maxHeight)
      Sets the chat window maximum height. Applies when resizing.
    • setWindowHeight

      public void setWindowHeight(String height)
      Sets the chat window default height. Applies when resizing.
    • setWindowWidth

      public void setWindowWidth(String width)
      Sets the chat window default width. Applies when resizing.
    • initializeHeader

      protected void initializeHeader()
    • initializeFooter

      protected void initializeFooter()
    • initializeContent

      protected void initializeContent(boolean markdownEnabled)
    • initializeChatWindow

      protected void initializeChatWindow()
    • setDataProvider

      public void setDataProvider(DataProvider<T,?> dataProvider)
    • setWhoIsTyping

      public void setWhoIsTyping(String whoIsTyping)
      Uses the provided string as the text shown over the message input to indicate that someone is typing.
      Parameters:
      whoIsTyping - string to be shown as an indication of someone typing
    • getWhoIsTyping

      public String getWhoIsTyping()
      Returns the current text shown over the message input to indicate that someone is typing.
      Returns:
      the current text or null if not configured
    • clearWhoIsTyping

      public void clearWhoIsTyping()
      Clears the text shown over the message input to indicate that someone is typing.
    • setSubmitListener

      public Registration setSubmitListener(ComponentEventListener<MessageInput.SubmitEvent> listener)
      Sets the SubmitListener that will be notified when the user submits a message on the underlying messageInput.
      Parameters:
      listener - the listener that will be notified when the SubmitEvent is fired
      Returns:
      registration for removal of the listener
    • sendMessage

      public void sendMessage(T message)
      Sends a message programmatically to the component. Should not be used when a custom DataProvider is used. Instead, just refresh the custom DataProvider.
      Parameters:
      message - the message to be sent programmatically
    • updateMessage

      public void updateMessage(T message)
      Updates a previously entered message.
      Parameters:
      message - the message to be updated
    • setMinimized

      @Deprecated(since="5.0.0") public void setMinimized(boolean minimized)
      Deprecated.
      use setOpened(boolean) instead
      Shows or hides chat window.
      Parameters:
      minimized - true for hiding the chat window and false for displaying it
    • isMinimized

      @Deprecated(since="5.0.0") public boolean isMinimized()
      Deprecated.
      use isOpened() instead
      Returns the visibility of the chat window.
      Returns:
      true if the chat window is minimized false otherwise
    • setHeaderComponent

      public void setHeaderComponent(Component component)
      Allows changing the header of the chat window.
      Parameters:
      component - to be used as a replacement for the header
    • getHeaderComponent

      public Component getHeaderComponent()
      Returns the current component configured as the header of the chat window.
    • setFooterComponent

      public void setFooterComponent(Component component)
      Allows changing the footer of the chat window.
      Parameters:
      component - to be used as a replacement for the footer, it cannot be null
    • getFooterComponent

      public Component getFooterComponent()
      Returns the current component configured as the footer of the chat window.
      Returns:
      component used as the footer of the chat window
    • scrollToIndex

      public void scrollToIndex(int position)
      Scrolls to the given position. Scrolls so that the element is shown at the start of the visible area whenever possible.

      If the index parameter exceeds current item set size the grid will scroll to the end.

      Parameters:
      position - zero based index of the item to scroll to in the current view.
    • scrollToStart

      public void scrollToStart()
      Scrolls to the first element.
    • scrollToEnd

      public void scrollToEnd()
      Scrolls to the last element of the list.
    • setMessagesRenderer

      public void setMessagesRenderer(Renderer<T> renderer)
      Allows changing the renderer used to display messages in the chat window.
      Parameters:
      renderer - the renderer to use for rendering Message objects, it cannot be null
    • setAvatarProvider

      @Deprecated(since="5.0.0", forRemoval=true) public void setAvatarProvider(SerializableSupplier<Avatar> avatarProvider)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the avatar provider that will be used to create the avatar
      Parameters:
      avatarProvider - the avatar provider that will be used to create the avatar
    • getUnreadMessages

      public int getUnreadMessages()
      Return the number of unread messages displayed in the chat assistant.
      Returns:
      the number of unread messages
    • setUnreadMessages

      public void setUnreadMessages(int unreadMessages)
      Sets the number of unread messages to be displayed in the chat assistant.
      Parameters:
      unreadMessages - the number of unread messages to set