Class CL_ContextActionSupport

java.lang.Object
org.jjazz.cl_editor.api.CL_ContextActionSupport
All Implemented Interfaces:
EventListener, ClsChangeListener

public class CL_ContextActionSupport extends Object implements ClsChangeListener
A helper class to write CL_Editor context aware actions.

Listen to changes in the lookup context:
- ChordLeadSheetItem and SelectedBar presence changes are notified to the registered CL_ContextActionListeners.
- If a ChordLeadSheet is present, listen to its changes and forward the ClsChangeEvents to the registered ClsChangeListeners.

CL_ContextActionSupport instances are cached per lookup context. Only weak listeners are used: declaratively registered actions might be transient actions (e.g. ContextAwareAction instances).

  • Method Details

    • getInstance

      public static CL_ContextActionSupport getInstance(org.openide.util.Lookup context)
      Get the instance associated to the specified context.
      Parameters:
      context -
      Returns:
    • getContext

      public final org.openide.util.Lookup getContext()
      Returns:
      the Lookup context
    • getSelection

      public final CL_Selection getSelection()
      Returns:
      The latest selection.
    • getActiveChordLeadSheet

      public final ChordLeadSheet getActiveChordLeadSheet()
      Returns:
      The ChordLeadSheet currently present in the lookup context. Can be null.
    • addWeakSelectionListener

      public void addWeakSelectionListener(CL_ContextActionListener listener)
      Add a weak reference to the specified listener.

      Listener will be notified of selection changes (bars or chord leadsheet items), unless listener is garbage-collected.

      Parameters:
      listener -
    • removeWeakSelectionListener

      public void removeWeakSelectionListener(CL_ContextActionListener listener)
      Remove the specified listener.

      Parameters:
      listener -
    • addWeakActiveClsChangeListener

      public void addWeakActiveClsChangeListener(ClsChangeListener listener)
      Add a weak reference to the specified listener.

      Listener will be notified of ClsChangeEvents from the active ChordLeadSheet, i.e the one present in the lookup context (unless listener is garbage-collected).

      Parameters:
      listener -
    • removeWeakActiveClsChangeListener

      public void removeWeakActiveClsChangeListener(ClsChangeListener listener)
      Remove the specified listener.

      Parameters:
      listener -
    • chordLeadSheetChanged

      public void chordLeadSheetChanged(ClsChangeEvent event) throws UnsupportedEditException
      Description copied from interface: ClsChangeListener
      Process the change.

      Note that this method might be called outside of the EDT.

      Specified by:
      chordLeadSheetChanged in interface ClsChangeListener
      Parameters:
      event -
      Throws:
      UnsupportedEditException - If a ClsVetoableChangeEvent is not authorized by a listener.