Package io.jmix.ui.action
Class BaseAction
java.lang.Object
io.jmix.ui.action.AbstractAction
io.jmix.ui.action.BaseAction
- All Implemented Interfaces:
Action,Action.HasPrimaryState,Action.SecuredAction
- Direct Known Subclasses:
AbstractLookupAction,DateIntervalAction,DialogAction,EditorScreenShowEntityInfoAction,EntityOpenAction,FilterAction,ListAction,ReportExecutionBrowser.DownloadDocumentAction,SubstituteUserAction,ValueClearAction,ValuesSelectAction
Action that can change its enabled and visible properties depending on the user permissions and current context.
The BaseAction is visible if the following conditions are met:
- setVisible(false) method was not called;
- there is no "hide" UI permission for this action.
The action is enabled if the following conditions are met:
- setEnabled(false) method was not called;
- there are no "hide" and "read-only" UI permissions for this action;
- isPermitted() method returns true;
- isApplicable() method returns true;
- all
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);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface which is invoked by the action to determine its enabled state.Nested classes/interfaces inherited from interface io.jmix.ui.action.Action
Action.ActionPerformedEvent, Action.AdjustWhenScreenReadOnly, Action.ExecutableAction, Action.HasPrimaryState, Action.HasSecurityConstraint, Action.HasTarget, Action.MainTabSheetAction, Action.ScreenOpeningAction, Action.SecuredAction, Action.Status -
Field Summary
Fields inherited from class io.jmix.ui.action.AbstractAction
caption, description, enabled, eventHub, icon, id, owners, primary, shortcut, visibleFields inherited from interface io.jmix.ui.action.Action
PROP_CAPTION, PROP_DESCRIPTION, PROP_ENABLED, PROP_ICON, PROP_SHORTCUT, PROP_VISIBLE -
Constructor Summary
ConstructorsModifierConstructorDescriptionBaseAction(String id) protectedBaseAction(String id, String shortcut) -
Method Summary
Modifier and TypeMethodDescriptionvoidactionPerform(Component component) Invoked by owning component to execute the action.voidaddEnabledRule(BaseAction.EnabledRule enabledRule) Add new enabled rule for the action.protected booleanCallback method which is invoked by the action to determine its enabled state.protected booleanbooleanprotected booleanCallback method which is invoked by the action to determine its enabled state.booleanvoidRefresh internal state of the action to initialize enabled, visible, caption, icon, etc.voidremoveEnabledRule(BaseAction.EnabledRule enabledRule) Remove enabled rule.voidsetEnabled(boolean enabled) voidsetEnabledByUiPermissions(boolean enabledByUiPermissions) protected voidsetEnabledInternal(boolean enabled) voidsetVisible(boolean visible) voidsetVisibleByUiPermissions(boolean visibleByUiPermissions) protected voidsetVisibleInternal(boolean visible) withCaption(String caption) Set caption using fluent API method.withDescription(String description) Set description using fluent API method.withHandler(Consumer<Action.ActionPerformedEvent> handler) Set action performed event handler using fluent API method.Set icon using fluent API method.withPrimary(boolean primary) Set whether this action is primary using fluent API method.withShortcut(String shortcut) Set shortcut using fluent API method.Methods inherited from class io.jmix.ui.action.AbstractAction
addOwner, addPropertyChangeListener, firePropertyChange, getCaption, getDescription, getEventHub, getIcon, getId, getOwner, getOwners, getShortcutCombination, hasSubscriptions, isEnabled, isPrimary, isVisible, removeOwner, removePropertyChangeListener, setCaption, setDescription, setIcon, setPrimary, setShortcut, setShortcutCombinationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jmix.ui.action.Action
addOwner, addPropertyChangeListener, getCaption, getDescription, getIcon, getId, getOwner, getOwners, getShortcutCombination, isEnabled, isVisible, removeOwner, removePropertyChangeListener, setCaption, setDescription, setIcon, setShortcut, setShortcutCombination
-
Constructor Details
-
BaseAction
-
BaseAction
-
-
Method Details
-
isPermitted
protected boolean isPermitted()Callback method which is invoked by the action to determine its enabled state.- Returns:
- true if the action is enabled for the current user
-
isApplicable
protected boolean isApplicable()Callback method which is invoked by the action to determine its enabled state.- Returns:
- true if the action is enabled for the current context, e.g. there is a selected row in a table
-
isEnabledByRule
protected boolean isEnabledByRule() -
setVisible
public void setVisible(boolean visible) - Specified by:
setVisiblein interfaceAction- Overrides:
setVisiblein classAbstractAction
-
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabledin interfaceAction- Overrides:
setEnabledin classAbstractAction
-
setVisibleInternal
protected void setVisibleInternal(boolean visible) -
setEnabledInternal
protected void setEnabledInternal(boolean enabled) -
refreshState
public void refreshState()Description copied from interface:ActionRefresh internal state of the action to initialize enabled, visible, caption, 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.
- Specified by:
refreshStatein interfaceAction- Overrides:
refreshStatein classAbstractAction
-
isEnabledByUiPermissions
public boolean isEnabledByUiPermissions()- Specified by:
isEnabledByUiPermissionsin interfaceAction.SecuredAction
-
setEnabledByUiPermissions
public void setEnabledByUiPermissions(boolean enabledByUiPermissions) - Specified by:
setEnabledByUiPermissionsin interfaceAction.SecuredAction
-
isVisibleByUiPermissions
public boolean isVisibleByUiPermissions()- Specified by:
isVisibleByUiPermissionsin interfaceAction.SecuredAction
-
setVisibleByUiPermissions
public void setVisibleByUiPermissions(boolean visibleByUiPermissions) - Specified by:
setVisibleByUiPermissionsin interfaceAction.SecuredAction
-
addEnabledRule
Add new enabled rule for the action.- Parameters:
enabledRule- boolean rule for the action enabled state
-
removeEnabledRule
Remove enabled rule.- Parameters:
enabledRule- boolean rule for the action enabled state
-
actionPerform
Description copied from interface:ActionInvoked by owning component to execute the action.- Specified by:
actionPerformin interfaceAction- Parameters:
component- invoking component
-
addActionPerformedListener
-
withCaption
Set caption using fluent API method.- Parameters:
caption- caption- Returns:
- current instance of action
-
withDescription
Set description using fluent API method.- Parameters:
description- description- Returns:
- current instance of action
-
withIcon
Set icon using fluent API method.- Parameters:
icon- icon- Returns:
- current instance of action
-
withShortcut
Set shortcut using fluent API method.- Parameters:
shortcut- shortcut- Returns:
- current instance of action
-
withHandler
Set action performed event handler using fluent API method. Can be used instead of subclassing BaseAction class.- Parameters:
handler- action performed handler- Returns:
- current instance of action
-
withPrimary
Set whether this action is primary using fluent API method. Can be used instead of subclassing BaseAction class.- Parameters:
primary- primary- Returns:
- current instance of action
-