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

    java.lang.Object
      org.eclipse.emf.common.command.AbstractCommand
          org.eclipse.emf.edit.command.AbstractOverrideableCommand
              org.eclipse.emf.edit.command.ReplaceCommand

All Implemented Interfaces:
  Command, OverrideableCommand

    public class ReplaceCommand

extends AbstractOverrideableCommand

The replace command logically acts upon an owner object that has a collection-type feature in which an object can be replaced by a collection of other objects. The static create methods delegate command creation to `EditingDomain.createCommand`, which may or may not result in the actual creation of an instance of this class.

The implementation of this class is low-level and EMF specific; it allows an object from a many-valued feature of an owner to be replaced by a collection of other objects. i.e., it is equivalent of the call

       int index = ((EList)((EObject)owner).eGet((EStructuralFeature)feature)).indexOf(value);
       ((EList)((EObject)owner).eGet((EStructuralFeature)feature)).remove(value);
       ((EList)((EObject)owner).eGet((EStructuralFeature)feature)).addAll(index, (Collection)collection);

It can also be used as an equivalent to the call

       int index = ((EList)extent).indexOf(value);
       ((EList)extent).remove(value);
       ((EList)extent).addAll(index, (Collection)collection);

which is how root objects are replaced in the contents of a resource. Like all the low level commands in this package, the replace command is undoable.

A replace command is an `OverrideableCommand`.

Nested Class Summary

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

Field Summary
`protected java.util.Collection<?>` `affectedObjects` The is the value returned by `Command.getAffectedObjects()`.
`protected java.util.Collection<?>` `collection` This is the collection of replacements.
`protected static java.lang.String` `DESCRIPTION` This caches the description.
`protected EStructuralFeature` `feature` This is the feature of the owner object upon the command will act.
`protected int` `index` This is the index at which to reinsert the replaced object during an undo so as to achieve the original list order.
`protected static java.lang.String` `LABEL` This caches the label.
`protected EObject` `owner` This is the owner object upon which the command will act.
`protected EList<java.lang.Object>` `ownerList` This is the list from which the command will replace.
`protected java.lang.Object` `value` This is value that is being replaced.

Fields inherited from class org.eclipse.emf.edit.command.AbstractOverrideableCommand
`domain, overrideCommand`

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

Constructor Summary
`ReplaceCommand(EditingDomain domain, EList<?> list, java.lang.Object value, java.util.Collection<?> collection)` This constructs a primitive command to replace a particular value in the specified extent with the given collection of replacements.
`ReplaceCommand(EditingDomain domain, EList<?> list, java.lang.Object value, java.lang.Object replacement)` This constructs a primitive command to replace a particular value in the specified extent with the given replacement.
`ReplaceCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value, java.util.Collection<?> collection)` This constructs a primitive command to replace a particular value in the specified feature of the owner with the specified collection of replacements.
`ReplaceCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value, java.lang.Object replacement)` This constructs a primitive command to replace a particular value in the specified feature of the owner with the specified replacement.

Method Summary
`static Command` `create(EditingDomain domain, java.lang.Object value, java.util.Collection<?> collection)` This creates a command to replace an object with a collection of replacements.
`static Command` `create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.lang.Object value, java.util.Collection<?> collection)` This creates a command to replace a particular value in the specified feature of the owner with a collection replacements objects.
`void` `doExecute()` This is overrideable command's implementation of execute.
`java.util.Collection<?>` `doGetAffectedObjects()` This is overrideable command's implementation of getAffectedObjects.
`java.util.Collection<?>` `doGetResult()` This is overrideable command's implementation of getResult.
`void` `doRedo()` This is overrideable command's implementation of redo.
`void` `doUndo()` This is overrideable command's implementation of undo.
`java.util.Collection<?>` `getCollection()` This returns the collection of replacement objects.
`EStructuralFeature` `getFeature()` This returns the feature of the owner object upon the command will act.
`int` `getIndex()` This returns the index at which to reinsert the replace objects during an undo so as to achieve the original list order.
`EObject` `getOwner()` This returns the owner object upon which the command will act.
`EList<java.lang.Object>` `getOwnerList()` This returns the list in which the command will replace.
`java.lang.Object` `getValue()` This returns the value being replaced.
`protected boolean` `prepare()` Called at most once in `AbstractCommand.canExecute()` to give the command an opportunity to ready itself for execution.
`java.lang.String` `toString()` This gives an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of `field:value` pairs.

Methods inherited from class org.eclipse.emf.edit.command.AbstractOverrideableCommand
`canExecute, canUndo, dispose, doCanExecute, doCanUndo, doDispose, doGetChildrenToCopy, doGetDescription, doGetLabel, execute, getAffectedObjects, getChildrenToCopy, getDescription, getDomain, getLabel, getOverride, getOwnerList, getResult, redo, setOverride, undo, updateEMap`

Methods inherited from class org.eclipse.emf.common.command.AbstractCommand
`chain, setDescription, setLabel`

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

Methods inherited from interface org.eclipse.emf.common.command.Command
`chain`

Field Detail

### LABEL

    protected static final java.lang.String LABEL

  This caches the label.

### DESCRIPTION

    protected static final java.lang.String DESCRIPTION

  This caches the description.

### owner

    protected EObject owner

  This is the owner object upon which the command will act. It could be null, in the case that we are dealing with an `EList`.

### feature

    protected EStructuralFeature feature

  This is the feature of the owner object upon the command will act. It could be null, in the case that we are dealing with an `EList`.

### ownerList

    protected EList<java.lang.Object> ownerList

  This is the list from which the command will replace.

### value

    protected java.lang.Object value

  This is value that is being replaced.

### collection

    protected java.util.Collection<?> collection

  This is the collection of replacements.

### index

    protected int index

  This is the index at which to reinsert the replaced object during an undo so as to achieve the original list order.

### affectedObjects

    protected java.util.Collection<?> affectedObjects

  The is the value returned by `Command.getAffectedObjects()`. The affected objects are different after an execute than after an undo, so we record it.

Constructor Detail

### ReplaceCommand

    public ReplaceCommand(EditingDomain domain,
                          EObject owner,
                          EStructuralFeature feature,
                          java.lang.Object value,
                          java.lang.Object replacement)

  This constructs a primitive command to replace a particular value in the specified feature of the owner with the specified replacement.

### ReplaceCommand

    public ReplaceCommand(EditingDomain domain,
                          EObject owner,
                          EStructuralFeature feature,
                          java.lang.Object value,
                          java.util.Collection<?> collection)

  This constructs a primitive command to replace a particular value in the specified feature of the owner with the specified collection of replacements.

### ReplaceCommand

    public ReplaceCommand(EditingDomain domain,
                          EList<?> list,
                          java.lang.Object value,
                          java.lang.Object replacement)

  This constructs a primitive command to replace a particular value in the specified extent with the given replacement.

### ReplaceCommand

    public ReplaceCommand(EditingDomain domain,
                          EList<?> list,
                          java.lang.Object value,
                          java.util.Collection<?> collection)

  This constructs a primitive command to replace a particular value in the specified extent with the given collection of replacements.

Method Detail

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object value,
                                 java.util.Collection<?> collection)

  This creates a command to replace an object with a collection of replacements.

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object owner,
                                 java.lang.Object feature,
                                 java.lang.Object value,
                                 java.util.Collection<?> collection)

  This creates a command to replace a particular value in the specified feature of the owner with a collection replacements objects.

### getOwner

    public EObject getOwner()

  This returns the owner object upon which the command will act. It could be null, in the case that we are dealing with an `EList`.

### getFeature

    public EStructuralFeature getFeature()

  This returns the feature of the owner object upon the command will act. It could be null, in the case that we are dealing with an `EList`.

### getOwnerList

    public EList<java.lang.Object> getOwnerList()

  This returns the list in which the command will replace.

### getValue

    public java.lang.Object getValue()

  This returns the value being replaced.

### getCollection

    public java.util.Collection<?> getCollection()

  This returns the collection of replacement objects.

### getIndex

    public int getIndex()

  This returns the index at which to reinsert the replace objects during an undo so as to achieve the original list order.

### 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.

### doExecute

    public void doExecute()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of execute.

  Specified by:
    `doExecute` in interface `OverrideableCommand`
  Specified by:
    `doExecute` in class `AbstractOverrideableCommand`

### doUndo

    public void doUndo()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of undo.

  Specified by:
    `doUndo` in interface `OverrideableCommand`
  Specified by:
    `doUndo` in class `AbstractOverrideableCommand`

### doRedo

    public void doRedo()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of redo.

  Specified by:
    `doRedo` in interface `OverrideableCommand`
  Specified by:
    `doRedo` in class `AbstractOverrideableCommand`

### doGetResult

    public java.util.Collection<?> doGetResult()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of getResult.

  Specified by:
    `doGetResult` in interface `OverrideableCommand`
  Overrides:
    `doGetResult` in class `AbstractOverrideableCommand`

### doGetAffectedObjects

    public java.util.Collection<?> doGetAffectedObjects()

  Description copied from interface: `OverrideableCommand`
  This is overrideable command's implementation of getAffectedObjects.

  Specified by:
    `doGetAffectedObjects` in interface `OverrideableCommand`
  Overrides:
    `doGetAffectedObjects` in class `AbstractOverrideableCommand`

### toString

    public java.lang.String toString()

  This gives an abbreviated name using this object's own class' name, without package qualification, followed by a space separated list of `field:value` pairs.

  Overrides:
    `toString` in class `AbstractOverrideableCommand`
  Returns:
    string representation.

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