|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.emf.common.command.AbstractCommand
public abstract class AbstractCommand
An abstract implementation of a basic command.
Each derived class Command.execute()
and Command.redo()
,
undo()
or implement canUndo()
to return false,
and prepare()
(this is the preferred approach) or can override canExecute()
directly.
It is very convenient to use prepare, as it is guaranteed to be called only once just before canExecute is to be tested. It can be implemented to create any additional commands that need to be executed, and the result it yields becomes the permanent cached return value for canExecute.
Nested Class Summary | |
---|---|
static interface |
AbstractCommand.NonDirtying
A marker interface implemented by commands that don't dirty the model. |
Field Summary | |
---|---|
protected java.lang.String |
description
Holds a short textual description of the command as returned by getDescription() and set by setDescription(java.lang.String) . |
protected boolean |
isExecutable
Keeps track of whether the command is executable. |
protected boolean |
isPrepared
Keeps track of whether prepare needs to be called. |
protected java.lang.String |
label
Holds the label of the command as returned by getLabel() and set by setLabel(java.lang.String) . |
Constructor Summary | |
---|---|
protected |
AbstractCommand()
Creates an empty instance. |
protected |
AbstractCommand(java.lang.String label)
Creates an instance with the given label. |
protected |
AbstractCommand(java.lang.String label,
java.lang.String description)
Creates and instance with the given label and description. |
Method Summary | |
---|---|
boolean |
canExecute()
Calls prepare() ,
caches the result in isExecutable ,
and sets isPrepared to true ;
from then on, it will yield the value of isExecutable. |
boolean |
canUndo()
Returns true because most command should be undoable. |
Command |
chain(Command command)
Creates a new compound command, containing this command and the given command, that delegates chain to CompoundCommand.append(org.eclipse.emf.common.command.Command) . |
void |
dispose()
Called to indicate that the command will never be used again. |
java.util.Collection<?> |
getAffectedObjects()
Returns an empty list. |
java.lang.String |
getDescription()
Returns a string suitable to help describe the effect of this command. |
java.lang.String |
getLabel()
Returns a string suitable to represent the label that identifies this command. |
java.util.Collection<?> |
getResult()
Returns an empty list. |
protected boolean |
prepare()
Called at most once in canExecute() to give the command an opportunity to ready itself for execution. |
void |
setDescription(java.lang.String description)
Sets the description after construction. |
void |
setLabel(java.lang.String label)
Sets the label after construction. |
java.lang.String |
toString()
Returns an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of field:value pairs. |
void |
undo()
Throws a runtime exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.eclipse.emf.common.command.Command |
---|
execute, redo |
Field Detail |
---|
protected boolean isPrepared
canExecute()
so that prepare()
is called exactly once to ready the command for execution.
protected boolean isExecutable
canExecute()
to the result of calling prepare()
.
protected java.lang.String description
getDescription()
and set by setDescription(java.lang.String)
.
protected java.lang.String label
getLabel()
and set by setLabel(java.lang.String)
.
Constructor Detail |
---|
protected AbstractCommand()
protected AbstractCommand(java.lang.String label)
label
- the label.protected AbstractCommand(java.lang.String label, java.lang.String description)
label
- the label.description
- the description.Method Detail |
---|
protected boolean prepare()
canExecute()
to give the command an opportunity to ready itself for execution.
The returned value is stored in canExecute()
.
In other words, you can override this method to initialize
and to yield a cached value for the all subsequent calls to canExecute.
public boolean canExecute()
prepare()
,
caches the result in isExecutable
,
and sets isPrepared
to true
;
from then on, it will yield the value of isExecutable.
canExecute
in interface Command
public boolean canUndo()
true
because most command should be undoable.
canUndo
in interface Command
true
.public void undo()
undo
in interface Command
java.lang.UnsupportedOperationException
- always.public java.util.Collection<?> getResult()
getResult
in interface Command
public java.util.Collection<?> getAffectedObjects()
getAffectedObjects
in interface Command
public java.lang.String getLabel()
Command
getLabel
in interface Command
public void setLabel(java.lang.String label)
label
- the new label.public java.lang.String getDescription()
Command
getDescription
in interface Command
public void setDescription(java.lang.String description)
description
- the new description.public Command chain(Command command)
CompoundCommand.append(org.eclipse.emf.common.command.Command)
.
chain
in interface Command
command
- the command to chain with this one.
public void dispose()
Command
dispose
in interface Command
public java.lang.String toString()
toString
in class java.lang.Object
|
Copyright 2001-2006 IBM Corporation and others. All Rights Reserved. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |