public final class CommandProcessor extends java.lang.Object implements Observer
CommandProcessor
singleton class is responsible for
managing the execution of the IDE commands and managing the undo stack.
In general, all controller implementations should use the IDE command
processor to execute the commands that controller handles. For example,
the Navigator
controller uses the
IdeCommandProcessor
) to handle its commands.
Since Command implementations may involve Swing interaction, all operations
upon CommandProcessor must be made using the event thread.
NEW BEHAVAIOR:
Support for invoking single commands or batch commands that interrupt a
transaction in progress has been added. NOTE: Since the API doesn't
currently return some sort of transaction object, transactions are assumed
to be on the same thread (a future version of CommandProcessor will
correct this). The current version assumes any request that is received
while a transaction is active that is not on the current transactions
thread will be blocked until the current transaction is completed, at which
point it will proceed (previous behavior was to generate exception
feedback and set the undo stack size to 0).
If a command in a transaction throws an exception, then the transaction
is aborted. Additionally if a transaction is interrupted the interrupting command
will wait for 60 seconds and then abort the transaction. Since transaction
aren't typically expected to be interrupted this shouldn't affect existing
behaviour. All transactions should be in try/finally blocks with the endTrans()
in the finally statement.Command
,
Controller
,
Ide
Modifier and Type | Class and Description |
---|---|
static class |
CommandProcessor.InfiniteLoopException |
Modifier and Type | Method and Description |
---|---|
void |
abortTrans()
Abort a multi Command batch operation, calling undo on any Command
instances already invoked as part of the current batch operation.
|
void |
beginTrans(java.lang.String label)
Begin a multi Command batch operation.
|
boolean |
canRedo(Context context)
Check if the last Command associated with the Node of the given Context
can be redone.
|
boolean |
canUndo(Context context)
Check if the last Command associated with the Node of the given Context
can be undone.
|
static Command |
createCommand(java.lang.String cmd,
Context context)
Deprecated.
use createCommandFromMeta(MetaClass,Context)
|
static Command |
createCommandFromAction(IdeAction action,
Context context)
Creates a command for the action
May return null if the action is not found or the action does not contain
a MetaClass for the command.
|
static Command |
createCommandFromAction(int actionId,
Context context)
Creates a command for the action looked up by the specified actionId
May return null if the action is not found or the action does not contain
a MetaClass for the command.
|
static Command |
createCommandFromAction(java.lang.String commandString,
Context context)
Creates a command for the action looked up by the specified command string
May return null if the action is not found or the action does not contain
a MetaClass for the command.
|
static Command |
createCommandFromClass(java.lang.Class clazz,
Context context) |
static Command |
createCommandFromMeta(MetaClass commandMeta,
Context context) |
void |
endTrans()
Commit a multi Command batch operation.
|
void |
flush(Node node)
Flush the undo stack associated with the specified
Node . |
void |
flush(Node[] objects)
Flush the undo stack of all the specified
objects . |
void |
flush(java.lang.Object object)
Flush the undo stack associated with the specified
Node . |
void |
flush(java.lang.Object[] objects)
Flush the undo stack of all the specified
objects . |
Command |
getCommand(Context context) |
static CommandProcessor |
getInstance()
This is a singleton class.
|
java.lang.String |
getRedoLabel(Context context)
Get the name of the last redoable Command associated with the Node of
the given Context.
|
java.lang.String |
getUndoLabel(Context context)
Get the name of the last undoable Command associated with the Node of
the given Context.
|
int |
invoke(Command cmd)
Executes the actions associated with a specific command.
|
java.util.concurrent.Future<java.lang.Integer> |
invokeAsync(Command cmd)
Deprecated.
- will be removing this shortly, the CommandProcessor should only be called from a Controller, to achieve asynch commands
use an AsynchronousController
|
java.util.concurrent.Future<java.lang.Integer> |
invokeAsync(Command cmd,
boolean runOnEventDispatchThread)
Deprecated.
- will be removing this shortly, the CommandProcessor should only be called from a Controller, to achieve asynch commands
use an AsynchronousController
|
boolean |
isTransactionActive() |
int |
redo(Context context)
Redo the last Command associated with the Node of the given Context.
|
int |
undo(Context context)
Undo the last Command associated with the Node of the given Context.
|
void |
update(java.lang.Object observed,
UpdateMessage change)
Respond to applicable UpdateMessages.
|
public static CommandProcessor getInstance()
getInstance
method creates the instance
if it has not yet been created.CommandProcessor
public final java.util.concurrent.Future<java.lang.Integer> invokeAsync(Command cmd, boolean runOnEventDispatchThread) throws java.lang.IllegalStateException, java.lang.Exception
cmd
- runOnEventDispatchThread
- java.lang.Exception
java.lang.IllegalStateException
public final java.util.concurrent.Future<java.lang.Integer> invokeAsync(Command cmd) throws java.lang.Exception
cmd
- java.lang.Exception
public final int invoke(Command cmd) throws java.lang.Exception
Controller
uses this method to tell the
CommandProcessor
that a command should be executed.cmd
- the command to execute.java.lang.Exception
public final int undo(Context context) throws java.lang.Exception
context
- a Context describing a Node, else null.java.lang.Exception
public final int redo(Context context) throws java.lang.Exception
context
- a Context describing a Node, else null.java.lang.Exception
public boolean canUndo(Context context)
context
- a Context describing a Node, else null.true
if the last applicable Command can be undone.public java.lang.String getUndoLabel(Context context)
context
- a Context describing a Node, else null.public boolean canRedo(Context context)
context
- a Context describing a Node, else null.true
if the last applicable Command can be redone.public java.lang.String getRedoLabel(Context context)
context
- a Context describing a Node, else null.public void flush(java.lang.Object object)
Node
.public void flush(Node node)
Node
.public void flush(java.lang.Object[] objects)
objects
.public void flush(Node[] objects)
objects
.public void beginTrans(java.lang.String label)
label
- summary label for use in undo/redo menu item.public void endTrans()
public void abortTrans()
public boolean isTransactionActive()
public void update(java.lang.Object observed, UpdateMessage change)
@Deprecated public static Command createCommand(java.lang.String cmd, Context context)
data
specified is maintained by the newly created command. Returns null
if command instance cannot be created.
This method is deprecated for it assumes that the classloader of the class passed in is known.
In a multiple classloader environment it is not known, so it will have to be passed is as a param.cmd
- the class name of the command,
i.e., oracle.jdeveloper.cmd.CutCommandcontext
- the context to be associated with the command. This object
is stored within the command an can be accessed later.public static Command createCommandFromMeta(MetaClass commandMeta, Context context)
public static Command createCommandFromAction(int actionId, Context context)
actionId
- context
- public static Command createCommandFromAction(java.lang.String commandString, Context context)
commandString
- context
- public static Command createCommandFromAction(IdeAction action, Context context)
action
- context
-