Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

javax.ide.command
Class Command  view Command download Command.java

java.lang.Object
  extended byjavax.ide.command.Command
All Implemented Interfaces:
javax.ide.Identifiable

public abstract class Command
extends java.lang.Object
implements javax.ide.Identifiable

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:

Commands are executed using the CommandProcessor. As NORMAL commands are executed, they are recorded by the command processor. This allows the command processor to perform undo and redo operations.


Field Summary
private  Context _context
           
private  int _type
           
static int CANCEL
          Command execution CANCEL status
static int NO_CHANGE
          Indicates a command that requires no undo.
static int NO_UNDO
          Indicates a command that cannot be undone, and which prevents the undo of previously performed normal commands.
static int NORMAL
          Indicates a command that can be undone.
static int OK
          Command execution OK status
 
Constructor Summary
protected Command()
           
protected Command(int type)
           
 
Method Summary
abstract  int doit()
          Executes the actions associated with a specific command.
 javax.ide.model.Document[] getAffectedDocuments()
          In general, the command processor manages undo stacks on a per javax.ide.model.Document basis.
protected  Context getContext()
          Gets the ide current Context.
abstract  java.lang.String getName()
          Gets the name of the command to display as the action to undo
 int getType()
          Gets the command type
 void setContext(Context context)
          Sets Context associated with command
abstract  int undo()
          Called by the CommandProcessor to undo a command When a command executes successfully, implementations should return OK, otherwise, return CANCEL or any other non-zero value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ide.Identifiable
getID
 

Field Detail

_context

private Context _context

_type

private final int _type

NORMAL

public static final int NORMAL
Indicates a command that can be undone.

See Also:
Constant Field Values

NO_CHANGE

public static final int NO_CHANGE
Indicates a command that requires no undo.

See Also:
Constant Field Values

NO_UNDO

public static final int NO_UNDO
Indicates a command that cannot be undone, and which prevents the undo of previously performed normal commands.

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
Constructor Detail

Command

protected Command()

Command

protected Command(int type)
Method Detail

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.


undo

public abstract int undo()
                  throws java.lang.Exception
Called by the CommandProcessor to undo a command When a command executes successfully, implementations should return OK, otherwise, return CANCEL or any other non-zero value.


getName

public abstract java.lang.String getName()
Gets the name of the command to display as the action to undo


getType

public final int getType()
Gets the command type


getContext

protected final Context getContext()
Gets the ide current Context.


setContext

public final void setContext(Context context)
Sets Context associated with command


getAffectedDocuments

public javax.ide.model.Document[] getAffectedDocuments()
In general, the command processor manages undo stacks on a per javax.ide.model.Document basis. When the execution of a command affects more than the target document, the other affected documents undo stacks must be be flushed in order to maintain document consistency. This method should be called by the command processor implementations after a command is executed to determine if that command affects other documents.

The CommandProcessor uses the return value to clear the undo stack of the affected documents.

For commands of the NORMAL and NO_UNDO type, this method should return an array of documents affected by the execution of this command. This array should not include the primary document on which this command is operating, it should only include other documents affected as a side effect of executing this command. The affected documents undo stack will be flushed.

Commands of type NO_CHANGE should return an empty array. The default implementation returns an empty array.