Skip navigation links
oracle.ide.controller
Class Command
java.lang.Object
oracle.ide.controller.Command
- Direct Known Subclasses:
- AboutCommand, AddContentCommand, CloseNodeCommand, CommitChangeSetCommand, CopyFileListCommand, DeleteTNodeCommand, EditChangeSetCommand, ExistingChangeSetCommand, ExitCommand, IdeSettingsCommand, LogWindowCommand, MakeDefaultChangeSetCommand, NewChangeSetCommand, NewWorkspaceCommand, NotImplementedCommand, OpenCommand, OpenCommand, OpenEditorCommand, OpenWizardCommand, PreferencesCommand, PropertiesCommand, PropertySetCommand, PropertySetCommand, RemoveChangeSetCommand, RemoveFileCommand, RemoveFromChangeSetCommand, RestartMergeCommand, RevertNodeCommand, SaveAllCommand, SaveAsCommand, SaveCommand, SaveMergeCommand, SetCommentsCommand, SetScopeCommand, TextBufferCommand, ToggleChangeSetsCommand, ToggleCommentsCommand, UndoableEditCommand, UndoWrapperCommand, UnsetDefaultChangeSetCommand, VCSCheckOutNodeCmd, VCSCommand, VersionTreeCompareCommand, ViewChangeListCommand
-
public abstract class Command
- extends java.lang.Object
The 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.
- See Also:
CommandProcessor
Field Summary |
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. |
Constructor Summary |
protected |
Command(int cmdId)
Constructor. |
protected |
Command(int cmdId, int type)
Constructor. |
protected |
Command(int cmdId, int type, java.lang.String name)
Constructor. |
Method Summary |
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 |
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 |
int |
undo()
Called by the CommandProcessor to undo a command. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NORMAL
public static final int NORMAL
- Indicates a command that affects a single Node and can be undone. Commands that cause the creation or deletion of a Node, yet still wish to be undoable, must use the MULTI_NODE type, even when creating or deleting only a single Node.
- See Also:
- Constant Field Values
NO_CHANGE
public static final int NO_CHANGE
- Indicates a command that doesn't affect a model and thus requires no undo.
- See Also:
- Constant Field Values
NO_UNDO
public static final int NO_UNDO
- Indicates a command that affects one or more Nodes and can't be undone. This type prevents the undo of any previously performed undoable commands for each of the affected Nodes.
- See Also:
- Constant Field Values
MULTI_NODE
public static final int MULTI_NODE
- Indicates a command that affects multiple Nodes and can be undone. Undoable commands that create or delete a Node must return this type, even if only creating or deleting a single Node.
- See Also:
- Constant Field Values
OK
public static final int OK
- Command execution OK status
- See Also:
- Constant Field Values
CANCEL
public static final int CANCEL
- Command execution CANCEL status
- See Also:
- Constant Field Values
EXECUTING
public static final int EXECUTING
- Command execution EXECUTING status. Indicates the command is currently executing.
- See Also:
- Constant Field Values
type
protected int type
- Keeps the command type. Default value is NO_CHANGE.
context
protected Context context
Command
protected Command(int cmdId)
- Constructor.
- Parameters:
cmdId
- the command ID as retrieved from Ide.findOrCreateCmdId(..).
Command
protected Command(int cmdId,
int type)
- Constructor.
- Parameters:
cmdId
- the command ID as retrieved from Ide.findOrCreateCmdId(..).
type
- the command type. Possible values are NORMAL
, NO_CHANGE
, NO_UNDO
, MULTI_NODE
.
Command
protected Command(int cmdId,
int type,
java.lang.String name)
- Constructor.
- Parameters:
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.
doit
public abstract int doit()
throws java.lang.Exception
- Executes the actions associated with a specific command. When a command executes successfully, implementations should return OK, otherwise, return CANCEL or any other non-zero value.
-
- Throws:
java.lang.Exception
undo
public int undo()
throws java.lang.Exception
- Called by the CommandProcessor to undo a command. Does nothing in this implemenation. Commands that can be undone should provide the behavior here to undo whatever actions were carried out when the
doit
method was called When a command executes successfully, implementations should return OK, otherwise, return CANCEL or any other non-zero value.
-
- Throws:
java.lang.Exception
getName
public java.lang.String getName()
- Gets the name of the command to display as the action to undo
getId
public int getId()
- Gets the command identifier
getType
public int getType()
- Gets the command type. The default value is NO_CHANGE
isGlobal
public boolean isGlobal()
- Determine whether or not the instance should be treated as global with respect to any undo/redo mechanics. A global Command may be undone/redone from any View regardless of the Context held by that View. Tbis is valuable for destructive or creationary Command implementations which leave no possible Context from which to undo or redo the operation (e.g. Deleting a Node by definition prevents any View from being able to offer that Node as part of its Context for the purposes of undo. Similarly, creating a Documnt by definition prevents any View from being able to offer that Node as part of its Context for the purposes of redo once undone). It is also usefull for non Editor type View implementations (e.g. a Navigator) which wish to support undo, but which display multiple Nodes and do not want to force the user to select a specific Node before being able to undo/redo an operation on that Node. A non global Command may only be undone from a View whose Context includes the target Node as its Node or as contained in its list of affected Nodes; as would be the case from any Editor type View. This latter example is the normal case and thus the default value for this method is false. Careful consideration should be given before returning a value of true from this method. The implication is that the previous global operation cannot be undone until the current global operation is undone. So, a simple editing change from an Editor is best left non global since it is easily undone from within the Editor and need not block the undo of a file deletion operation which could not be undone by any other means other than through global support. Typically, file manipulations or operations initiated from non Editor type Views are best suited for the global value.
enableConfirmation
public boolean enableConfirmation()
- Confirmation of undo and redo is standard for a global Command (which includes multi commands). However there are cases where it's unnecessary, a command can override this when they do not want a confirmation dialog to appear for a redo/undo. Returning false will disables a confirmation from taking place Note that isGlobal() is used to determine if an undo/redo should be prompt for confirmation. This is confusing which is why this has been named enableConfirmation. The default value maintains the existing behaviour. The name enableConfirmation indicate it only acts on something that would have confirmation, i.e. you can't use this to force a confirmation, only to block if confirmation is indicated by the value of isGlobal().
-
- Returns:
- boolean
getData
public java.lang.Object getData()
- Gets the stored command specific data
setData
public void setData(java.lang.Object data)
- Sets command specific data
getContext
public Context getContext()
- Gets the command's context.
setContext
public void setContext(Context context)
- Sets context associated with command.
getAffectedNodes
public Node[] getAffectedNodes()
- This method should return an array of Nodes affected by the execution of this command. The array should not include the primary Node on which this command is operating (as returned from getContext().getNode()), but rather should only include other Nodes additionally affected as a side effect of executing this command. If there is no primary Node, then all Nodes affected should be returned in the array. The CommandProcessor uses the return value when deciding how to treat the undo stack of the affected Nodes. Commands of type NO_CHANGE should return null.
-
- Returns:
- the Nodes affected by this command, otherwise, null.
Skip navigation links
Copyright © 1997, 2012, Oracle. All rights reserved.