public class CommandManager extends Object implements ICommandManager
ICommand.runWith(IChange...) to have undo/redo and macros.
call doIt(ICommand...) for each command that should be executed and perhaps un-done through undo().
only if at least one undo() was called, a redo() is possible.
Example, creating, deleting a bean and changing its attributes through reflection.
@Override
public void runWith(IChange... changes) {
for (int i = 0; i < changes.length; i++) {
if (changes[i].getItem() != null) {
//while the context can change on item=null, we have to do it inside the loop
Class<?> type = getContext().getClass();
BeanClass<Serializable> b = (BeanClass<Serializable>) BeanClass.getBeanClass(type);
b.setValue(getContext(), (String) changes[i].getItem(), changes[i].getNew());
} else {
setContext((Serializable) changes[i].getNew());
}
}
}
Macros are available through MacroRecorder. Call getRecorder()
MacroRecorder.record(String, ICommand...) with an id (no commands) to start the recording. If recording
should be finished, call the stop() method and the play(CONTEXT) method to do a replay on the given context object.| Constructor and Description |
|---|
CommandManager()
constructor
|
CommandManager(int capacity)
constructor
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRedo()
canRedo
|
boolean |
canUndo()
canUndo
|
boolean |
doIt(ICommand<?>... cmd)
doIt
|
MacroRecorder |
getRecorder()
getRecorder
|
ICommand<?> |
redo()
redo a command that was un-done.
|
ICommand<?> |
undo()
undo a command that was done by
#doIt(ICommand). |
public CommandManager()
public CommandManager(int capacity)
capacity - public boolean doIt(ICommand<?>... cmd)
ICommandManagerdoIt in interface ICommandManagercmd - command to executepublic ICommand<?> undo()
ICommandManager#doIt(ICommand).undo in interface ICommandManagerpublic ICommand<?> redo()
ICommandManagerredo in interface ICommandManagerpublic boolean canUndo()
ICommandManagercanUndo in interface ICommandManagerpublic boolean canRedo()
ICommandManagercanRedo in interface ICommandManagerpublic MacroRecorder getRecorder()
Copyright © 2012–2021. All rights reserved.