public class BaseAction extends AbstractAction implements Action.SecuredAction
The BaseAction is visible if the following conditions are met:
The action is enabled if the following conditions are met:
BaseAction.EnabledRules (if any) return true. Descendants may override isPermitted() and isApplicable() methods to define conditions in which
action will be enabled.
Also, you can use fluent API to create instances of BaseAction and assign handlers to them:
Action action = new BaseAction("printAll")
.withCaption("Print all")
.withIcon(JmixIcon.PRINT.source())
.withHandler(event -> {
// action logic here
});
docsTable.addAction(action);
| Modifier and Type | Class and Description |
|---|---|
static interface |
BaseAction.EnabledRule
Callback interface which is invoked by the action to determine its enabled state.
|
Action.ActionPerformedEvent, Action.AdjustWhenScreenReadOnly, Action.ExecutableAction, Action.HasPrimaryState, Action.HasSecurityConstraint, Action.HasTarget, Action.MainTabSheetAction, Action.ScreenOpeningAction, Action.SecuredAction, Action.Statuscaption, description, enabled, eventHub, icon, id, owners, primary, shortcut, visiblePROP_CAPTION, PROP_DESCRIPTION, PROP_ENABLED, PROP_ICON, PROP_SHORTCUT, PROP_VISIBLE| Modifier | Constructor and Description |
|---|---|
|
BaseAction(java.lang.String id) |
protected |
BaseAction(java.lang.String id,
java.lang.String shortcut) |
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerform(Component component)
Invoked by owning component to execute the action.
|
io.jmix.core.common.event.Subscription |
addActionPerformedListener(java.util.function.Consumer<Action.ActionPerformedEvent> listener) |
void |
addEnabledRule(BaseAction.EnabledRule enabledRule)
Add new enabled rule for the action.
|
protected boolean |
isApplicable()
Callback method which is invoked by the action to determine its enabled state.
|
protected boolean |
isEnabledByRule() |
boolean |
isEnabledByUiPermissions() |
protected boolean |
isPermitted()
Callback method which is invoked by the action to determine its enabled state.
|
boolean |
isVisibleByUiPermissions() |
void |
refreshState()
Refresh internal state of the action to initialize enabled, visible, caption, icon, etc.
|
void |
removeEnabledRule(BaseAction.EnabledRule enabledRule)
Remove enabled rule.
|
void |
setEnabled(boolean enabled) |
void |
setEnabledByUiPermissions(boolean enabledByUiPermissions) |
protected void |
setEnabledInternal(boolean enabled) |
void |
setVisible(boolean visible) |
void |
setVisibleByUiPermissions(boolean visibleByUiPermissions) |
protected void |
setVisibleInternal(boolean visible) |
BaseAction |
withCaption(java.lang.String caption)
Set caption using fluent API method.
|
BaseAction |
withDescription(java.lang.String description)
Set description using fluent API method.
|
BaseAction |
withHandler(java.util.function.Consumer<Action.ActionPerformedEvent> handler)
Set action performed event handler using fluent API method.
|
BaseAction |
withIcon(java.lang.String icon)
Set icon using fluent API method.
|
BaseAction |
withPrimary(boolean primary)
Set whether this action is primary using fluent API method.
|
BaseAction |
withShortcut(java.lang.String shortcut)
Set shortcut using fluent API method.
|
addOwner, addPropertyChangeListener, firePropertyChange, getCaption, getDescription, getEventHub, getIcon, getId, getOwner, getOwners, getShortcutCombination, hasSubscriptions, isEnabled, isPrimary, isVisible, removeOwner, removePropertyChangeListener, setCaption, setDescription, setIcon, setPrimary, setShortcut, setShortcutCombinationclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddOwner, addPropertyChangeListener, getCaption, getDescription, getIcon, getId, getOwner, getOwners, getShortcutCombination, isEnabled, isVisible, removeOwner, removePropertyChangeListener, setCaption, setDescription, setIcon, setShortcut, setShortcutCombinationpublic BaseAction(java.lang.String id)
protected BaseAction(java.lang.String id,
@Nullable
java.lang.String shortcut)
protected boolean isPermitted()
protected boolean isApplicable()
protected boolean isEnabledByRule()
public void setVisible(boolean visible)
setVisible in interface ActionsetVisible in class AbstractActionpublic void setEnabled(boolean enabled)
setEnabled in interface ActionsetEnabled in class AbstractActionprotected void setVisibleInternal(boolean visible)
protected void setEnabledInternal(boolean enabled)
public void refreshState()
ActionFor 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.
refreshState in interface ActionrefreshState in class AbstractActionpublic boolean isEnabledByUiPermissions()
isEnabledByUiPermissions in interface Action.SecuredActionpublic void setEnabledByUiPermissions(boolean enabledByUiPermissions)
setEnabledByUiPermissions in interface Action.SecuredActionpublic boolean isVisibleByUiPermissions()
isVisibleByUiPermissions in interface Action.SecuredActionpublic void setVisibleByUiPermissions(boolean visibleByUiPermissions)
setVisibleByUiPermissions in interface Action.SecuredActionpublic void addEnabledRule(BaseAction.EnabledRule enabledRule)
enabledRule - boolean rule for the action enabled statepublic void removeEnabledRule(BaseAction.EnabledRule enabledRule)
enabledRule - boolean rule for the action enabled statepublic void actionPerform(Component component)
ActionactionPerform in interface Actioncomponent - invoking componentpublic io.jmix.core.common.event.Subscription addActionPerformedListener(java.util.function.Consumer<Action.ActionPerformedEvent> listener)
public BaseAction withCaption(@Nullable java.lang.String caption)
caption - captionpublic BaseAction withDescription(@Nullable java.lang.String description)
description - descriptionpublic BaseAction withIcon(@Nullable java.lang.String icon)
icon - iconpublic BaseAction withShortcut(@Nullable java.lang.String shortcut)
shortcut - shortcutpublic BaseAction withHandler(java.util.function.Consumer<Action.ActionPerformedEvent> handler)
handler - action performed handlerpublic BaseAction withPrimary(boolean primary)
primary - primary