Class MacroCommand
public class MacroCommand extends Notifier implements ICommand
A base ICommand implementation that executes other ICommands.
A MacroCommand maintains an list of
ICommand Class references called SubCommands.
When execute is called, the MacroCommand
instantiates and calls execute on each of its SubCommands turn.
Each SubCommand will be passed a reference to the original
INotification that was passed to the MacroCommand's
execute method.
Unlike SimpleCommand, your subclass
should not override execute, but instead, should
override the initializeMacroCommand method,
calling addSubCommand once for each SubCommand
to be executed.
- See Also:
Controller,Notification,SimpleCommand
-
Field Summary
-
Constructor Summary
Constructors Constructor Description MacroCommand()Constructor. -
Method Summary
Modifier and Type Method Description protected voidaddSubCommand(java.util.function.Supplier<ICommand> factory)Add a SubCommand.voidexecute(INotification notification)Execute thisMacroCommand's SubCommands.protected voidinitializeMacroCommand()Initialize theMacroCommand.Methods inherited from class org.puremvc.java.patterns.observer.Notifier
sendNotification, sendNotification, sendNotificationMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.puremvc.java.interfaces.INotifier
sendNotification, sendNotification, sendNotification
-
Constructor Details
-
MacroCommand
public MacroCommand()Constructor.
You should not need to define a constructor, instead, override the
initializeMacroCommandmethod.If your subclass does define a constructor, be sure to call
super().
-
-
Method Details
-
initializeMacroCommand
protected void initializeMacroCommand()Initialize the
MacroCommand.In your subclass, override this method to initialize the
MacroCommand's SubCommand list withICommandclass references like this:// Initialize MyMacroCommand protected void initializeMacroCommand( ) { addSubCommand( () -> new com.me.myapp.controller.FirstCommand() ); addSubCommand( () -> new com.me.myapp.controller.SecondCommand() ); addSubCommand( () -> new com.me.myapp.controller.ThirdCommand() ); }Note that SubCommands may be any
ICommandimplementor,MacroCommands orSimpleCommandsare both acceptable. -
addSubCommand
Add a SubCommand.
The SubCommands will be called in First In/First Out (FIFO) order.
- Parameters:
factory- a reference to the factory of theICommand.
-
execute
Execute this
MacroCommand's SubCommands.The SubCommands will be called in First In/First Out (FIFO) order.
-