Class SS_ContextAction

java.lang.Object
javax.swing.AbstractAction
org.jjazz.ss_editor.api.SS_ContextAction
All Implemented Interfaces:
ActionListener, Serializable, Cloneable, EventListener, Action, SS_ContextActionListener, org.openide.util.ContextAwareAction

public abstract class SS_ContextAction extends AbstractAction implements SS_ContextActionListener, org.openide.util.ContextAwareAction
A base class for SS_Editor context aware actions.

To be used by actions associated to static menus, buttons or keyboard shortcuts, which act on the selection (chord symbols, bars, etc.), and whose enabled state depends on this selection. If your action is only used in a transient popupmenu (created by Utilities.actionsToPopup()) with no keyboard shorcut, you might prefer to use a simple AbstractAction+ContextAwareAction (see SetParentSectionColor.java for example).

If your action is used in a transient popup menu (created by Utilities.actionsToPopup()) and needs to listen to a shared service, use a WeakListener or make your action a singleton (see Paste.java for example).

See Also:
  • Field Details

  • Constructor Details

    • SS_ContextAction

      public SS_ContextAction()
      Create an action which listens to all possible ListeningTargets in the global context.
      See Also:
      • configureAction()
  • Method Details

    • getContext

      public org.openide.util.Lookup getContext()
    • getActionName

      public String getActionName()
      Convenience method to get the Action.NAME value or "not set".
      Returns:
    • isEnabled

      public boolean isEnabled()
      Overridden to defer initialization as late as possible.

      Specified by:
      isEnabled in interface Action
      Overrides:
      isEnabled in class AbstractAction
      Returns:
    • actionPerformed

      public void actionPerformed(ActionEvent ae)
      Specified by:
      actionPerformed in interface ActionListener
    • selectionChange

      public abstract void selectionChange(SS_Selection selection)
      Called when selection in the provided context has changed.

      Typically used to update the enabled state.

      Specified by:
      selectionChange in interface SS_ContextActionListener
      Parameters:
      selection -
      See Also:
    • createContextAwareInstance

      public Action createContextAwareInstance(org.openide.util.Lookup lkp)
      Specified by:
      createContextAwareInstance in interface org.openide.util.ContextAwareAction