|
||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.emf.common.command.AbstractCommand
An abstract implementation of a basic command.
Each derived class Command.execute()
and Command.redo()
,
AbstractCommand.undo()
or implement AbstractCommand.canUndo()
to return false,
and AbstractCommand.prepare()
(this is the preferred approach) or can override AbstractCommand.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 AbstractCommand.getDescription() and set by AbstractCommand.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 AbstractCommand.getLabel() and set by AbstractCommand.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 AbstractCommand.prepare() ,
caches the result in AbstractCommand.isExecutable ,
and sets AbstractCommand.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 AbstractCommand.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
AbstractCommand.canExecute()
so that AbstractCommand.prepare()
is called exactly once to ready the command for execution.
protected boolean isExecutable
AbstractCommand.canExecute()
to the result of calling AbstractCommand.prepare()
.
protected java.lang.String description
AbstractCommand.getDescription()
and set by AbstractCommand.setDescription(java.lang.String)
.
protected java.lang.String label
AbstractCommand.getLabel()
and set by AbstractCommand.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()
AbstractCommand.canExecute()
to give the command an opportunity to ready itself for execution.
The returned value is stored in AbstractCommand.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()
AbstractCommand.prepare()
,
caches the result in AbstractCommand.isExecutable
,
and sets AbstractCommand.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()
|
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 |