## org.eclipse.emf.edit.command
Class ChangeCommand

    java.lang.Object
      org.eclipse.emf.common.command.AbstractCommand
          org.eclipse.emf.edit.command.ChangeCommand

All Implemented Interfaces:
  Command

    public abstract class ChangeCommand

extends AbstractCommand

This command uses the Change Model facilities to enable a group of modifications to be executed as one single command. The undo operation reverts all the modifications made when the command was executed

In order to use this class, the `org.eclipse.emf.ecore.change` plugin has to be available in your Eclipse configuration.

Since:
  2.2.0

Nested Class Summary

Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand
`AbstractCommand.NonDirtying`

Field Summary
`protected ChangeDescription` `changeDescription`
`protected ChangeRecorder` `changeRecorder`
`protected Notifier` `notifier`
`protected java.util.Collection<Notifier>` `notifiers`

Fields inherited from class org.eclipse.emf.common.command.AbstractCommand
`description, isExecutable, isPrepared, label`

Constructor Summary
`protected` `ChangeCommand(ChangeRecorder changeRecorder)`
`` `ChangeCommand(ChangeRecorder changeRecorder, java.util.Collection<Notifier> notifiers)`
`` `ChangeCommand(ChangeRecorder changeRecorder, Notifier notifier)`
`` `ChangeCommand(java.util.Collection<Notifier> notifiers)`
`` `ChangeCommand(Notifier notifier)`

Method Summary
`boolean` `canUndo()` Returns `true` because most command should be undoable.
`protected ChangeRecorder` `createChangeRecorder()`
`void` `dispose()` Called to indicate that the command will never be used again.
`protected void` `disposeChangeRecorder(ChangeRecorder changeRecorder)` Disposes the `ChangeRecorder` created by `execute()`.
`protected abstract void` `doExecute()` Subclasses should override this to perform modifications to resources and objects.
`void` `execute()` Executes the command.
`protected ChangeDescription` `getChangeDescription()`
`ChangeRecorder` `getChangeRecorder()` Returns the `ChangeRecorder` specified in the constructor if any.
`protected boolean` `prepare()` Called at most once in `AbstractCommand.canExecute()` to give the command an opportunity to ready itself for execution.
`void` `redo()` Performs the command activity required to `redo` the effect after undoing the effect.
`protected void` `setChangeDescription(ChangeDescription changeDescription)`
`void` `undo()` Throws a runtime exception.

Methods inherited from class org.eclipse.emf.common.command.AbstractCommand
`canExecute, chain, getAffectedObjects, getDescription, getLabel, getResult, setDescription, setLabel, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### changeDescription

    protected ChangeDescription changeDescription

### notifier

    protected Notifier notifier

### notifiers

    protected java.util.Collection<Notifier> notifiers

### changeRecorder

    protected ChangeRecorder changeRecorder

Constructor Detail

### ChangeCommand

    protected ChangeCommand(ChangeRecorder changeRecorder)

### ChangeCommand

    public ChangeCommand(ChangeRecorder changeRecorder,
                         Notifier notifier)

### ChangeCommand

    public ChangeCommand(Notifier notifier)

### ChangeCommand

    public ChangeCommand(ChangeRecorder changeRecorder,
                         java.util.Collection<Notifier> notifiers)

### ChangeCommand

    public ChangeCommand(java.util.Collection<Notifier> notifiers)

Method Detail

### dispose

    public void dispose()

  Description copied from interface: `Command`
  Called to indicate that the command will never be used again. Calling any other method after this one has undefined results.

  Specified by:
    `dispose` in interface `Command`
  Overrides:
    `dispose` in class `AbstractCommand`

### getChangeRecorder

    public ChangeRecorder getChangeRecorder()

  Returns the `ChangeRecorder` specified in the constructor if any.

  Returns:
    `ChangeRecorder`

### createChangeRecorder

    protected ChangeRecorder createChangeRecorder()

### getChangeDescription

    protected ChangeDescription getChangeDescription()

### setChangeDescription

    protected void setChangeDescription(ChangeDescription changeDescription)

### prepare

    protected boolean prepare()

  Description copied from class: `AbstractCommand`
  Called at most once in `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.

  Overrides:
    `prepare` in class `AbstractCommand`
  Returns:
    whether the command is executable.

### canUndo

    public boolean canUndo()

  Description copied from class: `AbstractCommand`
  Returns `true` because most command should be undoable.

  Specified by:
    `canUndo` in interface `Command`
  Overrides:
    `canUndo` in class `AbstractCommand`
  Returns:
    `true`.

### execute

    public void execute()

  Executes the command. Subclasses are not expected to overwrite this method, and implement their changes on `doExecute()`.

### doExecute

    protected abstract void doExecute()

  Subclasses should override this to perform modifications to resources and objects. If no modification occurs, an `AbortExecutionException` may be thrown to avoid placing the command on the command stack.

### disposeChangeRecorder

    protected void disposeChangeRecorder(ChangeRecorder changeRecorder)

  Disposes the `ChangeRecorder` created by `execute()`. The default implementation doesn't dispose the change recorder if it was passed in through one of the constructor methods.

  Parameters:
    `changeRecorder` -

### undo

    public void undo()

  Description copied from class: `AbstractCommand`
  Throws a runtime exception.

  Specified by:
    `undo` in interface `Command`
  Overrides:
    `undo` in class `AbstractCommand`

### redo

    public void redo()

  Description copied from interface: `Command`
  Performs the command activity required to `redo` the effect after undoing the effect. The effect, if any, of calling `redo` before `undo` is called is undefined. Note that if you implement `redo` to call `execute` then any derived class will be restricted by that decision also.

Copyright 2001-2006 IBM Corporation and others. All Rights Reserved.