public class CommandManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
CommandManager.State
An enumeration of command manager states.
|
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_FLUSH_COUNT
The default flush count.
|
protected static int |
DEFAULT_FLUSH_THRESHOLD
The default flush threshold.
|
protected static java.lang.String |
EMPTY_STRING
The empty string.
|
protected int |
flushCount
The number of commands to flush from the undo stack.
|
protected int |
flushThreshold
The maximum size of the undo stack.
|
static java.lang.String |
REDO_LABEL_PREFIX
The prefix for Redo labels.
|
protected static java.lang.String |
SPACE
A string containing only a space character.
|
static java.lang.String |
UNDO_LABEL_PREFIX
The prefix for Undo labels.
|
Constructor and Description |
---|
CommandManager()
Constructs a new command manager.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addCommand(ICommand command)
Adds the specified command to the list of commands managed by this
command manager.
|
void |
addCommandManagerChangeListener(ICommandManagerChangeListener listener)
Adds the specified listener to the list of command manager change
listeners for this command manager.
|
boolean |
canRedo()
Retrieves a Boolean indicating whether a command can be redone.
|
boolean |
canUndo()
Retrieves a Boolean indicating whether a command can be undone.
|
void |
clear()
Clears this command manager by emptying its list of commands.
|
protected void |
clearRedoCommands()
Clears the redo stack.
|
void |
clearSilent()
Clears this command manager by emptying its list of commands WITHOUT
broadcasting CommandManagerChangeEvent.
|
protected void |
clearUndoCommands()
Clears the undo stack.
|
CommandResult |
execute(ICommand command)
Executes the specified command.
|
CommandResult |
execute(ICommand command,
org.eclipse.core.runtime.IProgressMonitor progressMonitor)
Executes the specified command.
|
protected void |
fireCommandManagerChange(CommandManagerChangeEvent event)
Notifies the listeners for this command manager that the specified event
has occurred.
|
protected void |
flush()
Removes
flushCount commands from the undo stack. |
void |
flush(ICommand command)
Removes commands on the command stack down to, and including, the given
command
|
protected void |
flushCommands(ICommand command)
Removes commands on the command stack down to, and including, the given
command
|
protected java.util.List |
getCommands()
Retrieves the value of the
commands instance variable. |
java.util.List |
getCommandsAsList()
Retrieves a read-only list of the commands
|
static CommandManager |
getDefault()
Retrieves the default command manager.
|
int |
getFlushCount()
Retrieves the value of the
flushCount instance variable. |
int |
getFlushThreshold()
Retrieves the value of the
flushThreshold instance
variable. |
protected java.util.List |
getListeners()
Retrieves the value of the
listeners instance variable. |
java.lang.String |
getRedoLabel()
Retrieves a label for the command that can be redone.
|
CommandManager.State |
getState()
Retrieves the value of the
state instance variable. |
protected int |
getUndoIndex()
Retrieves the value of the
undoIndex instance variable. |
java.lang.String |
getUndoLabel()
Retrieves a label for the command that can be undone.
|
CommandResult |
redo()
Redoes the command on the top of the redo stack.
|
void |
redo(ICommand command)
Redoes the every command up to, and including, the given command
|
void |
removeCommandManagerChangeListener(ICommandManagerChangeListener listener)
Removes the specified listener from the list of command manager change
listeners for this command manager.
|
void |
setFlushCount(int flushCount)
Sets the
flushCount instance variable to the specified
value. |
void |
setFlushThreshold(int flushThreshold)
Sets the
flushThreshold instance variable to the specified
value. |
protected void |
setState(CommandManager.State state)
Sets the
state instance variable to the specified value. |
protected void |
setUndoIndex(int undoIndex)
Sets the
undoIndex instance variable to the specified
value. |
CommandResult |
undo()
Undoes the command on the top of the undo stack.
|
void |
undo(ICommand command)
Undoes the every command down to, and including, the given command
|
protected static int DEFAULT_FLUSH_THRESHOLD
protected static int DEFAULT_FLUSH_COUNT
protected static final java.lang.String EMPTY_STRING
public static final java.lang.String REDO_LABEL_PREFIX
protected static final java.lang.String SPACE
public static final java.lang.String UNDO_LABEL_PREFIX
protected int flushThreshold
protected int flushCount
public static CommandManager getDefault()
protected final java.util.List getCommands()
commands
instance variable.commands
instance variable.public final java.util.List getCommandsAsList()
protected final java.util.List getListeners()
listeners
instance variable.listeners
instance variable.public final CommandManager.State getState()
state
instance variable.state
instance variable.protected final void setState(CommandManager.State state)
state
instance variable to the specified value.state
- The new value for the state
instance variable.protected final int getUndoIndex()
undoIndex
instance variable.undoIndex
instance variable.protected final void setUndoIndex(int undoIndex)
undoIndex
instance variable to the specified
value.undoIndex
- The new value for the undoIndex
instance
variable.public final int getFlushThreshold()
flushThreshold
instance
variable.flushThreshold
instance variable.public final void setFlushThreshold(int flushThreshold)
flushThreshold
instance variable to the specified
value.flushThreshold
- The new value for the flushThreshold
instance
variable.public final int getFlushCount()
flushCount
instance variable.flushCount
instance variable.public final void setFlushCount(int flushCount)
flushCount
instance variable to the specified
value.flushCount
- The new value for the flushCount
instance
instance variable.public void addCommandManagerChangeListener(ICommandManagerChangeListener listener)
listener
- The listener to be added.public void removeCommandManagerChangeListener(ICommandManagerChangeListener listener)
listener
- The listener to be removed.protected void fireCommandManagerChange(CommandManagerChangeEvent event)
event
- The command manager change event to be fired.protected void addCommand(ICommand command)
command
- The command to be added.protected void clearRedoCommands()
protected void clearUndoCommands()
protected void flushCommands(ICommand command)
command
- the command to flush down topublic final void clear()
public final void clearSilent()
public final void flush(ICommand command)
command
- the command to flush down toprotected void flush()
flushCount
commands from the undo stack.public boolean canRedo()
true
is a command can be redone;
false
otherwise.public boolean canUndo()
true
is a command can be undone;
false
otherwise.public java.lang.String getRedoLabel()
public java.lang.String getUndoLabel()
public CommandResult execute(ICommand command)
NullProgressMonitor
is used so
that commands which wish to report progress can do so without considering
whether or not a progress monitor was supplied. The
NullProgressMonitor
implements the IProgressMonitor
interface with an implementation that does nothing.command
- The command to be executed.java.lang.UnsupportedOperationException
- If the command cannot be executed.public CommandResult execute(ICommand command, org.eclipse.core.runtime.IProgressMonitor progressMonitor)
The progressMonitor
must not be null
. To
execute a command without a progress monitor, use
execute(ICommand)
.
command
- The command to be executed.progressMonitor
- The object that monitors the progress of this command
execution.java.lang.UnsupportedOperationException
- If the command cannot be executed.public CommandResult redo()
java.lang.UnsupportedOperationException
- If a command cannot be redone.public CommandResult undo()
java.lang.UnsupportedOperationException
- If a command cannot be undone.public void undo(ICommand command)
command
- the command to undo topublic void redo(ICommand command)
command
- the command to redo to