Class 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

public class BaseAction extends AbstractAction implements Action.SecuredAction
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);
 
  • Constructor Details

    • BaseAction

      public BaseAction(String id)
    • BaseAction

      protected BaseAction(String id, @Nullable String shortcut)
  • 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 interface Action
      Overrides:
      setVisible in class AbstractAction
    • setEnabled

      public void setEnabled(boolean enabled)
      Specified by:
      setEnabled in interface Action
      Overrides:
      setEnabled in class AbstractAction
    • 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 interface Action
      Overrides:
      refreshState in class AbstractAction
    • isEnabledByUiPermissions

      public boolean isEnabledByUiPermissions()
      Specified by:
      isEnabledByUiPermissions in interface Action.SecuredAction
    • setEnabledByUiPermissions

      public void setEnabledByUiPermissions(boolean enabledByUiPermissions)
      Specified by:
      setEnabledByUiPermissions in interface Action.SecuredAction
    • isVisibleByUiPermissions

      public boolean isVisibleByUiPermissions()
      Specified by:
      isVisibleByUiPermissions in interface Action.SecuredAction
    • setVisibleByUiPermissions

      public void setVisibleByUiPermissions(boolean visibleByUiPermissions)
      Specified by:
      setVisibleByUiPermissions in interface Action.SecuredAction
    • addEnabledRule

      public void addEnabledRule(BaseAction.EnabledRule enabledRule)
      Add new enabled rule for the action.
      Parameters:
      enabledRule - boolean rule for the action enabled state
    • removeEnabledRule

      public void removeEnabledRule(BaseAction.EnabledRule enabledRule)
      Remove enabled rule.
      Parameters:
      enabledRule - boolean rule for the action enabled state
    • actionPerform

      public void actionPerform(Component component)
      Description copied from interface: Action
      Invoked by owning component to execute the action.
      Specified by:
      actionPerform in interface Action
      Parameters:
      component - invoking component
    • addActionPerformedListener

      public Subscription addActionPerformedListener(Consumer<Action.ActionPerformedEvent> listener)
    • withCaption

      public BaseAction withCaption(@Nullable String caption)
      Set caption using fluent API method.
      Parameters:
      caption - caption
      Returns:
      current instance of action
    • withDescription

      public BaseAction withDescription(@Nullable String description)
      Set description using fluent API method.
      Parameters:
      description - description
      Returns:
      current instance of action
    • withIcon

      public BaseAction withIcon(@Nullable String icon)
      Set icon using fluent API method.
      Parameters:
      icon - icon
      Returns:
      current instance of action
    • withShortcut

      public BaseAction withShortcut(@Nullable String shortcut)
      Set shortcut using fluent API method.
      Parameters:
      shortcut - shortcut
      Returns:
      current instance of action
    • withHandler

      public BaseAction withHandler(Consumer<Action.ActionPerformedEvent> handler)
      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

      public BaseAction withPrimary(boolean primary)
      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