|
Eclipse GEF 3.8.1.201208200205 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.gef.commands.CommandStack
public class CommandStack
An implementation of a command stack. A stack manages the executing, undoing,
and redoing of Commands
. Executed commands are pushed onto a
a stack for undoing later. Commands which are undone are pushed onto a redo
stack. Whenever a new command is executed, the Redo stack is flushed.
A CommandStack contains a dirty property. This property can be used to
determine when persisting changes is required. The stack is dirty whenever
the last executed or redone command is different than the command that was at
the top of the undo stack when markSaveLocation()
was last called.
Initially, the undo stack is empty, and not dirty.
Field Summary | |
---|---|
protected java.util.List |
listeners
Deprecated. This field should not be referenced, use notifyListeners() |
static int |
POST_EXECUTE
Constant indicating notification after a command has been executed (value is 8). |
static int |
POST_MASK
A bit-mask indicating notification after a command has done something. |
static int |
POST_REDO
Constant indicating notification after a command has been redone (value is 16). |
static int |
POST_UNDO
Constant indicating notification after a command has been undone (value is 32). |
static int |
PRE_EXECUTE
Constant indicating notification prior to executing a command (value is 1). |
static int |
PRE_MASK
A bit-mask indicating notification before a command makes a change. |
static int |
PRE_REDO
Constant indicating notification prior to redoing a command (value is 2). |
static int |
PRE_UNDO
Constant indicating notification prior to undoing a command (value is 4). |
Constructor Summary | |
---|---|
CommandStack()
Constructs a new command stack. |
Method Summary | |
---|---|
void |
addCommandStackEventListener(CommandStackEventListener listener)
Appends the listener to the list of command stack listeners. |
void |
addCommandStackListener(CommandStackListener listener)
Appends the listener to the list of command stack listeners. |
boolean |
canRedo()
|
boolean |
canUndo()
|
void |
dispose()
This will dispose() all the commands in both the undo and
redo stack. |
void |
execute(Command command)
Executes the specified Command if possible. |
void |
flush()
Flushes the entire stack and resets the save location to zero. |
java.lang.Object[] |
getCommands()
|
Command |
getRedoCommand()
Peeks at the top of the redo stack. |
Command |
getUndoCommand()
Peeks at the top of the undo stack. |
int |
getUndoLimit()
Returns the undo limit. |
boolean |
isDirty()
Returns true if the stack is dirty. |
void |
markSaveLocation()
Marks the last executed or redone Command as the point at which the changes were saved. |
protected void |
notifyListeners()
Deprecated. |
protected void |
notifyListeners(Command command,
int state)
Notifies command stack event listeners that the command stack has changed to the specified state. |
void |
redo()
Calls redo on the Command at the top of the redo stack, and pushes that Command onto the undo stack. |
void |
removeCommandStackEventListener(CommandStackEventListener listener)
Removes the first occurrence of the specified listener. |
void |
removeCommandStackListener(CommandStackListener listener)
Removes the first occurrence of the specified listener. |
void |
setUndoLimit(int undoLimit)
Sets the undo limit. |
void |
undo()
Undoes the most recently executed (or redone) Command. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int POST_EXECUTE
public static final int POST_REDO
public static final int POST_UNDO
public static final int POST_MASK
Usage
if ((commandStackEvent.getDetail() & CommandStack.POST_MASK) != 0) { // Do something, like: stopBatchingChanges(); }
public static final int PRE_EXECUTE
public static final int PRE_REDO
public static final int PRE_UNDO
public static final int PRE_MASK
Usage
if ((commandStackEvent.getDetail() & CommandStack.PRE_MASK) != 0) { // Do something, like: startBatchingChanges(); }
protected java.util.List listeners
notifyListeners()
CommandStackListener
s.
Constructor Detail |
---|
public CommandStack()
false
.
Method Detail |
---|
public void addCommandStackEventListener(CommandStackEventListener listener)
listener
- the event listenerpublic void addCommandStackListener(CommandStackListener listener)
listener
- the listenerpublic boolean canRedo()
true
if it is appropriate to call redo()
.public boolean canUndo()
true
if undo()
can be calledpublic void dispose()
dispose()
all the commands in both the undo and
redo stack. Both stacks will be empty afterwards.
public void execute(Command command)
PRE_EXECUTE
will be fired to
event listeners. Similarly, after attempting to execute the command, an
event for POST_EXECUTE
will be fired. If the execution of the
command completely normally, stack listeners will receive
stackChanged
notification.
If the command is null
or cannot be executed, nothing
happens.
command
- the Command to executeCommandStackEventListener
public void flush()
public java.lang.Object[] getCommands()
public Command getRedoCommand()
Command
has a
label describing it.
null
public Command getUndoCommand()
Command
has a
label describing it.
null
public int getUndoLimit()
-1
is used to indicate no
limit.
public boolean isDirty()
markSaveLocation()
was last called.
true
if the stack is dirtypublic void markSaveLocation()
isDirty()
will be based on
this checkpoint.
protected void notifyListeners()
CommandStackListener
s.
protected void notifyListeners(Command command, int state)
command
- the commandstate
- the current stack statepublic void redo()
canUndo()
returns true
.
public void removeCommandStackEventListener(CommandStackEventListener listener)
listener
- the listenerpublic void removeCommandStackListener(CommandStackListener listener)
listener
- the listenerpublic void setUndoLimit(int undoLimit)
-1
is used to indicate no
limit.
undoLimit
- the undo limitpublic void undo()
canUndo()
returns true
.
|
Eclipse GEF 3.8.1.201208200205 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |