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
,AbstractScreenAction
,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.EnabledRule
s (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
Modifier and TypeClassDescriptionstatic interface
Callback 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.OperationResultAction, Action.ScreenAction<S extends Screen>, 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, visible
Fields inherited from interface io.jmix.ui.action.Action
PROP_CAPTION, PROP_DESCRIPTION, PROP_ENABLED, PROP_ICON, PROP_SHORTCUT, PROP_VISIBLE
-
Constructor Summary
ModifierConstructorDescriptionBaseAction
(String id) protected
BaseAction
(String id, String shortcut) -
Method Summary
Modifier and TypeMethodDescriptionvoid
actionPerform
(Component component) Invoked by owning component to execute the action.void
addEnabledRule
(BaseAction.EnabledRule enabledRule) Add new enabled rule for the action.protected boolean
Callback method which is invoked by the action to determine its enabled state.protected boolean
boolean
protected boolean
Callback method which is invoked by the action to determine its enabled state.boolean
void
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) 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, setShortcutCombination
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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:
setVisible
in interfaceAction
- Overrides:
setVisible
in classAbstractAction
-
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabled
in interfaceAction
- Overrides:
setEnabled
in classAbstractAction
-
setVisibleInternal
protected void setVisibleInternal(boolean visible) -
setEnabledInternal
protected void setEnabledInternal(boolean enabled) -
refreshState
public void refreshState()Description copied from interface:Action
Refresh 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:
refreshState
in interfaceAction
- Overrides:
refreshState
in classAbstractAction
-
isEnabledByUiPermissions
public boolean isEnabledByUiPermissions()- Specified by:
isEnabledByUiPermissions
in interfaceAction.SecuredAction
-
setEnabledByUiPermissions
public void setEnabledByUiPermissions(boolean enabledByUiPermissions) - Specified by:
setEnabledByUiPermissions
in interfaceAction.SecuredAction
-
isVisibleByUiPermissions
public boolean isVisibleByUiPermissions()- Specified by:
isVisibleByUiPermissions
in interfaceAction.SecuredAction
-
setVisibleByUiPermissions
public void setVisibleByUiPermissions(boolean visibleByUiPermissions) - Specified by:
setVisibleByUiPermissions
in 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:Action
Invoked by owning component to execute the action.- Specified by:
actionPerform
in 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
-