Class AiMessageAction<A extends AiMessageAction<A>>
- Type Parameters:
A- the concrete action type (self-type, for fluent setters)
- All Implemented Interfaces:
Action,HasShortcutCombination
- Direct Known Subclasses:
AiMessageCopyAction,AiMessageRegenerateAction
AiMessageList.
One instance is assigned to a role — AiMessageList.setUserActions(java.util.List<? extends io.jmix.aichat.action.AiMessageAction<?>>) /
AiMessageList.setAssistantActions(java.util.List<? extends io.jmix.aichat.action.AiMessageAction<?>>) — and reused for every message of that role, so
it holds no per-message state: the message reaches the handler through
AiMessageActionPerformedEvent instead, which carries both the rendered item and
the domain message it was rendered from. Business logic goes in
execute(AiMessageActionPerformedEvent); a listener registered with
addActionPerformedListener(java.util.function.Consumer<io.jmix.aichat.action.AiMessageActionPerformedEvent>) overrides it.
Only the members this component can render are supported. The action's icon (an
Icon, SvgIcon, FontIcon or Image), its
description — used as the button's tooltip and accessible name —
and its class names are pushed to the client; text,
enabled, visible, variant and the shortcut combination have no
client-side representation and their setters throw UnsupportedOperationException
rather than being silently ignored.
The class is concrete and fluent, so a general-purpose action needs no subclass:
new AiMessageAction<>("regenerate")
.withIcon(new Icon(VaadinIcon.REFRESH))
.withDescription("Regenerate")
.withHandler(event -> ...);
This is also what a view descriptor's action element without a type
produces. Subclass it to register an ActionType of your own —
AiMessageCopyAction is the built-in client-side copy.-
Field Summary
FieldsFields inherited from class io.jmix.flowui.kit.action.AbstractAction
description, enabled, eventBus, icon, id, shortcutCombination, text, variant, visibleFields inherited from interface io.jmix.flowui.kit.action.Action
PROP_DESCRIPTION, PROP_ENABLED, PROP_ICON, PROP_SHORTCUT_COMBINATION, PROP_TEXT, PROP_VARIANT, PROP_VISIBLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidactionPerform(com.vaadin.flow.component.Component component) Executes action logic.voidactionPerform(AiMessageList messageList, AiMessageListItem item) Performs the action on a message.com.vaadin.flow.shared.RegistrationAdds a listener to be notified when the action is performed.voidaddClassNames(String... classNames) Adds CSS class names to the action's button.protected voidBusiness logic of the action.CSS class names applied to the action's button on the client.protected voidHook for subclasses to set defaults (icon, description, class names).voidRefreshes internal state of the action to initialize enabled, visible, text, icon, etc.protected Aself()voidsetEnabled(boolean enabled) Sets the enabled property value of an action.voidsetShortcutCombination(@Nullable KeyCombination shortcutCombination) Sets object that stores information about keys, modifiers and additional settings that describe shortcut combinations.voidSets the text property value of an action.voidsetVariant(ActionVariant variant) Sets the variant property value of an action.voidsetVisible(boolean visible) Sets the visible property value of an action.protected UnsupportedOperationExceptionunsupported(String property) withClassNames(String... classNames) Adds CSS class names to the action's button.withDescription(@Nullable String description) Sets the description used as the button's tooltip and accessible name.withHandler(@Nullable Consumer<AiMessageActionPerformedEvent> handler) Adds a listener to be notified when the action is performed.withIcon(@Nullable com.vaadin.flow.component.Component icon) Sets the icon of the action's button.Methods inherited from class io.jmix.flowui.kit.action.AbstractAction
addPropertyChangeListener, firePropertyChange, getDescription, getEventBus, getIcon, getIconComponent, getId, getShortcutCombination, getText, getVariant, hasListener, isEnabled, isVisible, setDescription, setIcon, setIconComponent
-
Field Details
-
classNames
-
-
Constructor Details
-
AiMessageAction
Creates the action with the given id.- Parameters:
id- the action id
-
-
Method Details
-
initAction
protected void initAction()Hook for subclasses to set defaults (icon, description, class names). Empty by default.Called from the constructor, so it runs before the subclass's own field initializers: set state through the inherited setters, not through subclass fields.
-
getClassNames
CSS class names applied to the action's button on the client. Lets an action style itself — for example supply its icon through a CSS mask instead of an icon component.- Returns:
- the class names to apply (never
null; empty by default)
-
addClassNames
Adds CSS class names to the action's button. Additive on purpose: a declaredclassNamesmust not discard the class a built-in action type contributed ininitAction().- Parameters:
classNames- the class names to add, notnull
-
refreshState
public void refreshState()Description copied from interface:ActionRefreshes internal state of the action to initialize enabled, visible, text, icon, etc. properties depending on programmatically set values and user permissions set at runtime.For example, this method is called by visual components holding actions when they are bound to data. At this moment the action can find out what entity it is connected to and change its state according to the user permissions.
-
actionPerform
Performs the action on a message. Called by the host list when the action's button is clicked. FiresAiMessageActionPerformedEventwhen a listener is registered, and callsexecute(AiMessageActionPerformedEvent)otherwise.- Parameters:
messageList- the host message list, notnullitem- the rendered item the action was invoked on, notnull
-
execute
Business logic of the action. Empty by default.- Parameters:
event- the performed event, carrying the rendered item, the domain message it was rendered from, and the host list
-
addActionPerformedListener
public com.vaadin.flow.shared.Registration addActionPerformedListener(Consumer<AiMessageActionPerformedEvent> listener) Adds a listener to be notified when the action is performed.- Parameters:
listener- listener to add- Returns:
- a registration object for removing an event listener
-
withIcon
Sets the icon of the action's button.- Parameters:
icon- the icon to render: anIcon,SvgIcon,FontIconorImage, ornullto remove- Returns:
- this object
-
withDescription
Sets the description used as the button's tooltip and accessible name.- Parameters:
description- the description to set, ornullto remove- Returns:
- this object
-
withClassNames
Adds CSS class names to the action's button.- Parameters:
classNames- the class names to add- Returns:
- this object
-
withHandler
Adds a listener to be notified when the action is performed. Like every listener, it overridesexecute(AiMessageActionPerformedEvent).- Parameters:
handler- listener to add, ornullto remove all- Returns:
- this object
-
self
-
actionPerform
public void actionPerform(com.vaadin.flow.component.Component component) Description copied from interface:ActionExecutes action logic.- Parameters:
component-Componentthat triggered this action- Throws:
UnsupportedOperationException- always — a message action is meaningless without a target message, so it cannot be triggered by a component. UseactionPerform(AiMessageList, AiMessageListItem).
-
setText
Description copied from interface:ActionSets the text property value of an action. May be used by components to initialize their appearance.- Specified by:
setTextin interfaceAction- Overrides:
setTextin classAbstractAction- Parameters:
text- text to set ornullto remove- Throws:
UnsupportedOperationException- always — the action's button is icon-only.
-
setEnabled
public void setEnabled(boolean enabled) Description copied from interface:ActionSets the enabled property value of an action. May be used by components to initialize their appearance.- Specified by:
setEnabledin interfaceAction- Overrides:
setEnabledin classAbstractAction- Parameters:
enabled- whether the action is currently enabled- Throws:
UnsupportedOperationException- always — the client has no disabled action state.
-
setVisible
public void setVisible(boolean visible) Description copied from interface:ActionSets the visible property value of an action. May be used by components to initialize their appearance.- Specified by:
setVisiblein interfaceAction- Overrides:
setVisiblein classAbstractAction- Parameters:
visible- whether the action is currently visible- Throws:
UnsupportedOperationException- always — the client has no hidden action state.
-
setVariant
Description copied from interface:ActionSets the variant property value of an action. May be used by components to initialize their appearance.- Specified by:
setVariantin interfaceAction- Overrides:
setVariantin classAbstractAction- Parameters:
variant- variant to set- Throws:
UnsupportedOperationException- always — the action's button has no variants.
-
setShortcutCombination
Description copied from interface:HasShortcutCombinationSets object that stores information about keys, modifiers and additional settings that describe shortcut combinations.- Specified by:
setShortcutCombinationin interfaceHasShortcutCombination- Overrides:
setShortcutCombinationin classAbstractAction- Parameters:
shortcutCombination- key combination to set ornullto remove- Throws:
UnsupportedOperationException- always — a per-role action bar has no shortcut scope.
-
unsupported
-