Class ChatAssistant
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
- All Implemented Interfaces:
AttachNotifier,ClickNotifier<Div>,DetachNotifier,HasComponents,HasElement,HasEnabled,HasOrderedComponents,HasSize,HasStyle,HasText,Serializable
@NpmPackage(value="wc-chatbot",
version="0.2.0")
@JsModule("wc-chatbot/dist/wc-chatbot.js")
@CssImport("./styles/chat-assistant-styles.css")
@Tag("chat-bot")
public class ChatAssistant
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 -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ChatAssistant(boolean markdownEnabled) Creates a ChatAssistant with no messages.ChatAssistant(List<Message> messages, boolean markdownEnabled) Creates a ChatAssistant with the given list of messages. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the text shown over the message input to indicate that someone is typing.Returns the current component configured as the footer of the chat window.Returns the current component configured as the header of the chat window.Returns the current text shown over the message input to indicate that someone is typing.booleanReturns the visibility of the chat window.protected voidonAttach(AttachEvent attachEvent) voidScrolls to the last element of the list.voidscrollToIndex(int position) Scrolls to the given position.voidScrolls to the first element.voidsendMessage(Message message) Sends a message programmatically to the component.voidsetDataProvider(DataProvider<Message, ?> dataProvider) Sets the data provider of the internal VirtualList.voidsetFooterComponent(Component component) Allows changing the footer of the chat window.voidsetHeaderComponent(Component component) Allows changing the header of the chat window.voidsetMinimized(boolean minimized) Shows or hides chat window.Sets the SubmitListener that will be notified when the user submits a message on the underlying messageInput.voidsetWhoIsTyping(String whoIsTyping) Uses the provided string as the text shown over the message input to indicate that someone is typing.voidupdateMessage(Message 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
-
Constructor Details
-
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
-
ChatAssistant
Creates a ChatAssistant with the given list of messages.- Parameters:
messages- the list of messagesmarkdownEnabled- flag to enable or disable markdown support
-
-
Method Details
-
setDataProvider
Sets the data provider of the internal VirtualList.- Parameters:
dataProvider- the data provider to be used
-
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
-
onAttach
-
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
public void setMinimized(boolean minimized) Shows or hides chat window.- Parameters:
minimized- true for hiding the chat window and false for displaying it
-
isMinimized
public boolean isMinimized()Returns 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.- Returns:
- component used 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.
-