Programmatic Execution

Commands can be executed programmatically simply by invoking the no-arg execute() method as follows:

   ActionCommand command = ...;

   command.execute();

This will invoke the command with an empty parameter map. This results in methods such as getInvoker() and getInvokerWindow() returning null.

Specifying Execution Parameters

If your code relies on certain parameters being correctly configured you'll need to populate the parameter map prior to each execution. The following demonstrates setting the invoker parameter:

   command.putParameter(ActionCommand.PARAMETER_INVOKER, invoker);
   command.execute();

In this above case the command checks if the invoker is a swing component and if it is it automatically configures the invoker window parameter. You can also configure the invoker window parameter manually as follows:

   command.putParameter(ActionCommand.PARAMETER_INVOKER_WINDOW, window);
   command.execute();

Invoking One Command From Another

When invoking one command from another you can simply pass an entire parameter map to the execute method as follows:

   ActionCommand commandOne = ...
   ActionCommand commandTwo = ...

   commandTwo.execute(commandOne.getParameters());

In this case commandTwo will inherit all the parameters of commandOne including the invoker and invoker window.