Delegating Commands

DelegatingCommands allow you to create a command whose actual implementation is late bound based on the current UI state. Typical examples include the print, cut, copy and paste operations since they are always in menus and on toolbars but their behaviour typically depends on the currently focused component. DelegatingCommands are also useful when you reguire a command to be accessed from a top level of a container hierarchy

Overview

The following gives an outline of how DelegatingCommands interact with DelegateMediator.

  1. Once bound, the DelegatingCommand searchs the container hierarchy for a DelegateMediator.
  2. The DelegateMediator tracks the currently focused component and scans the swing hierarchy for components that implement DelegateProvider.
  3. The mediator notifies the DelegatingCommand whenever the provider hierarchy changes.
  4. The DelegatingCommand updates to use the newly discovered delegates.

The following diagram illustrates:

Overview of Delegates
NOTE: You typically on need one DelegateMediator instance per frame since the DelegatingCommands will search the container hierarchy for the nearest instance.