Class ChatAssistant<T extends Message>
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.HtmlComponent
com.vaadin.flow.component.HtmlContainer
com.vaadin.flow.component.html.Div
com.flowingcode.vaadin.addons.chatassistant.ChatAssistant<T>
- 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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
HasText.WhiteSpace -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Popoverprotected final VerticalLayoutprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected static final intprotected final Buttonprotected SvgIconprotected final Divprotected final Divprotected final Divprotected final Divprotected final Divprotected final Divprotected final Divprotected final Divprotected final Divprotected final Divprotected final Div -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ChatAssistant(boolean markdownEnabled) Creates a ChatAssistant with no messages.ChatAssistant(List<T> messages, boolean markdownEnabled) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddComponentRefreshedListener(String uniqueFlag, String executable, Serializable... parameters) Adds a component refresh listener that prevents stacking up duplicate listeners on the client side.protected voidapplyGenericResizerStyle(Div resizer, String direction) Applies common styles to the resizer elements based on the specified direction.voidClears the text shown over the message input to indicate that someone is typing.voidclose()Closes the chat window.Returns the current component configured as the footer of the chat window.Returns the current component configured as the header of the chat window.intReturn the number of unread messages displayed in the chat assistant.Returns the current text shown over the message input to indicate that someone is typing.protected voidprotected voidinitializeContent(boolean markdownEnabled) protected voidprotected voidbooleanDeprecated.booleanisOpened()Returns true if the chat window is opened, false otherwise.protected voidonAttach(AttachEvent attachEvent) protected voidonClick()Receives click events from the client side to toggle the chat window's opened state.voidopen()Opens the chat window.voidScrolls to the last element of the list.voidscrollToIndex(int position) Scrolls to the given position.voidScrolls to the first element.voidsendMessage(T message) Sends a message programmatically to the component.voidsetAvatarProvider(SerializableSupplier<Avatar> avatarProvider) Deprecated, for removal: This API element is subject to removal in a future version.usesetFabIcon(Component)insteadvoidsetDataProvider(DataProvider<T, ?> dataProvider) voidsetFabIcon(Component icon) Sets the icon for the floating action button.voidsetFabIcon(Component icon, int size) Sets the icon for the floating action button.voidsetFooterComponent(Component component) Allows changing the footer of the chat window.voidsetHeaderComponent(Component component) Allows changing the header of the chat window.voidsetMessagesRenderer(Renderer<T> renderer) Allows changing the renderer used to display messages in the chat window.voidsetMinimized(boolean minimized) Deprecated.usesetOpened(boolean)insteadvoidsetOpened(boolean opened) Sets the opened state of the chat window.Sets the SubmitListener that will be notified when the user submits a message on the underlying messageInput.voidsetUnreadMessages(int unreadMessages) Sets the number of unread messages to be displayed in the chat assistant.voidsetWhoIsTyping(String whoIsTyping) Uses the provided string as the text shown over the message input to indicate that someone is typing.voidsetWindowHeight(String height) Sets the chat window default height.voidsetWindowMaxHeight(String maxHeight) Sets the chat window maximum height.voidsetWindowMaxWidth(String maxWidth) Sets the chat window maximum width.voidsetWindowMinHeight(String minHeight) Sets the chat window minimum height.voidsetWindowMinWidth(String minWidth) Sets the chat window minimum width.voidsetWindowWidth(String width) Sets the chat window default width.voidupdateMessage(T message) Updates a previously entered message.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAllMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasOrderedComponents
getChildren, getComponentAt, getComponentCount, indexOf, replaceMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasText
getText, getWhiteSpace, setText, setWhiteSpace
-
Field Details
-
fabIcon
-
fab
-
unreadBadge
-
fabWrapper
-
chatWindow
-
overlay
-
container
-
resizerTop
-
resizerBottom
-
resizerTopRight
-
resizerBottomRight
-
resizerRight
-
resizerLeft
-
resizerBottomLeft
-
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
-
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
-
onClick
Receives click events from the client side to toggle the chat window's opened state. -
applyGenericResizerStyle
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 instanceexecutable- the JavaScript action to execute when the component is refreshed,parameters- parameters for the executable
-
setFabIcon
Sets the icon for the floating action button.
The icon's size is automatically adjusted to fit within the FAB. -
setFabIcon
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
Sets the chat window minimum width. Applies when resizing. -
setWindowMinHeight
Sets the chat window minimum height. Applies when resizing. -
setWindowMaxWidth
Sets the chat window maximum width. Applies when resizing. -
setWindowMaxHeight
Sets the chat window maximum height. Applies when resizing. -
setWindowHeight
Sets the chat window default height. Applies when resizing. -
setWindowWidth
Sets the chat window default width. Applies when resizing. -
initializeHeader
protected void initializeHeader() -
initializeContent
protected void initializeContent(boolean markdownEnabled) -
initializeChatWindow
protected void initializeChatWindow() -
setDataProvider
-
setWhoIsTyping
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
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
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
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
Updates a previously entered message.- Parameters:
message- the message to be updated
-
setMinimized
Deprecated.usesetOpened(boolean)insteadShows or hides chat window.- Parameters:
minimized- true for hiding the chat window and false for displaying it
-
isMinimized
Deprecated.useisOpened()insteadReturns the visibility of the chat window.- Returns:
- true if the chat window is minimized false otherwise
-
setHeaderComponent
Allows changing the header of the chat window.- Parameters:
component- to be used as a replacement for the header
-
getHeaderComponent
Returns the current component configured as the header 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
Allows changing the renderer used to display messages in the chat window.- Parameters:
renderer- the renderer to use for renderingMessageobjects, 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.usesetFabIcon(Component)insteadSets 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
-
isOpened()instead