public abstract class Command
extends java.lang.Object
Command
interface defines the interface of all command
objects. This interface consists of a procedure, doit
, to
execute a command. Concrete Command subclasses implement the necessary
behavior to carry out a specific command.
This interface also provides additional methods necessary to implement
the undo service provided by the CommandProcessor
. For the
undo mechanism it is necessary to distinguish three types of commands:
NO_CHANGE
A command that require no undo.
NORMAL
A command that can be undone.
NO_UNDO
A command that cannot be undone, and which
prevents the undo of previously performed
normal commands.
MULTI_NODE
A command that can be undone, but that affects
multiple files.CommandProcessor
Modifier and Type | Field and Description |
---|---|
static int |
CANCEL
Command execution CANCEL status
|
protected Context |
context |
static int |
EXECUTING
Command execution EXECUTING status.
|
static int |
MULTI_NODE
Indicates a command that affects multiple Nodes and can be undone.
|
static int |
NO_CHANGE
Indicates a command that doesn't affect a model and thus requires no undo.
|
static int |
NO_UNDO
Indicates a command that affects one or more Nodes and can't be undone.
|
static int |
NORMAL
Indicates a command that affects a single Node and can be undone.
|
static int |
OK
Command execution OK status
|
protected int |
type
Keeps the command type.
|
Modifier | Constructor and Description |
---|---|
protected |
Command(int cmdId)
Constructor.
|
protected |
Command(int cmdId,
int type)
Constructor.
|
protected |
Command(int cmdId,
int type,
java.lang.String name)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
abstract int |
doit()
Executes the actions associated with a specific command.
|
boolean |
enableConfirmation()
Confirmation of undo and redo is standard for a global Command (which includes multi commands).
|
Node[] |
getAffectedNodes()
This method should return an array of Nodes affected by the execution
of this command.
|
Context |
getContext()
Gets the command's context.
|
java.lang.Object |
getData()
Gets the stored command specific data
|
int |
getId()
Gets the command identifier
|
java.lang.String |
getName()
Gets the name of the command to display as the action to undo
|
protected org.netbeans.api.progress.ProgressHandle |
getProgressHandle()
Convenience method to the progressHanel from AsychronousController.TaskInfo, if the controller that created this
even created a ProgressHandle.
|
int |
getType()
Gets the command type.
|
boolean |
isGlobal()
Determine whether or not the instance should be treated as global with
respect to any undo/redo mechanics.
|
void |
setContext(Context context)
Sets context associated with command.
|
void |
setData(java.lang.Object data)
Sets command specific data
|
void |
setTaskInfo(AsynchronousController.TaskInfo taskInfo)
Should only be called from an AsynchronousController.
|
int |
undo()
Called by the CommandProcessor to undo a command.
|
public static final int NORMAL
public static final int NO_CHANGE
public static final int NO_UNDO
public static final int MULTI_NODE
public static final int OK
public static final int CANCEL
public static final int EXECUTING
protected int type
protected Context context
protected Command(int cmdId)
cmdId
- the command ID as retrieved from Ide.findOrCreateCmdId(..).protected Command(int cmdId, int type)
cmdId
- the command ID as retrieved from Ide.findOrCreateCmdId(..).type
- the command type. Possible values are
NORMAL
, NO_CHANGE
, NO_UNDO
, MULTI_NODE
.protected Command(int cmdId, int type, java.lang.String name)
cmdId
- the command ID as retrieved from Ide.findOrCreateCmdId(..).type
- the command type. Possible values are
NORMAL
, NO_CHANGE
, NO_UNDO
, MULTI_NODE
.name
- the command name. This name will be displayed along side
the Undo and Redo menu items and should not be null.public abstract int doit() throws java.lang.Exception
java.lang.Exception
public int undo() throws java.lang.Exception
doit
method was called
When a command executes successfully, implementations should
return OK, otherwise, return CANCEL or any other non-zero value.java.lang.Exception
public java.lang.String getName()
public int getId()
public int getType()
public boolean isGlobal()
public boolean enableConfirmation()
public java.lang.Object getData()
public void setData(java.lang.Object data)
public Context getContext()
public void setContext(Context context)
public Node[] getAffectedNodes()
public final void setTaskInfo(AsynchronousController.TaskInfo taskInfo)
taskInfo
- protected final org.netbeans.api.progress.ProgressHandle getProgressHandle()