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

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

All Implemented Interfaces:
  Command, OverrideableCommand

    public class SetCommand

extends AbstractOverrideableCommand

The set command logically acts upon an owner object to set a particular feature to a specified value or to unset a feature. 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 a value to be set to a single-valued feature of an owner, i.e., it is equivalent of the call

       ((EObject)object).eSet((EStructuralFeature)feature, value);

or to

       ((EObject)object).eUnset((EStructuralFeature)feature);

if the value is `UNSET_VALUE`.

Setting a feature that is a bidirectional reference with a multiplicity-many reverse or with a multiplicity-1 reverse that is already set (on value), is not undoable. In this case, the SetCommand static create function will not return an instance of this class, but instead will return a compound command (e.g., a `RemoveCommand` followed by an `AddCommand` for the other end of the relation) which could not be undone.

The exception to the above is when an empty list is being set to empty or unset. Such commands are undoable and represent the only way to toggle whether the feature is set.

When setting a containment (or container) feature, we always assume that the object that will be contained is not already in a container, but take no action in this class to ensure this is the case.

A set command is an `OverrideableCommand`.

Nested Class Summary
`protected static class` `SetCommand.PessimisticStrictCompoundCommand`

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

Field Summary
`protected boolean` `canUndo` This specified whether or not this command can be undone.
`protected static java.lang.String` `DESCRIPTION` This caches the description.
`protected static EcorePackage` `ecorePackage`
`protected EStructuralFeature` `feature` This is the feature of the owner object upon the command will act.
`protected int` `index` This is the position at which the object will be set.
`protected static java.lang.String` `LABEL` This caches the label.
`protected java.lang.Object` `oldValue` This is the old value of the feature which must be restored during undo.
`protected EObject` `owner` This is the owner object upon which the command will act.
`protected EList<java.lang.Object>` `ownerList` If non-null, this is the list in which the command will set a value.
`static java.lang.Object` `UNSET_VALUE` Specify this as the value in order to unset a feature.
`protected java.lang.Object` `value` This is the value to be set.

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
`SetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value)` This constructs a primitive command to set the owner's feature to the specified value.
`SetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value, int index)` This constructs a primitive command to set the owner's feature to the specified value at the given index.

Method Summary
`static Command` `create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.lang.Object value)` This creates a command to set the owner's feature to the specified value.
`static Command` `create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.lang.Object value, int index)` This creates a command to set the owner's feature to the specified value at the specified index.
`boolean` `doCanUndo()` This is overrideable command's implementation of canUndo.
`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.
`EStructuralFeature` `getFeature()` This returns the feature of the owner object upon the command will act.
`int` `getIndex()` This returns the position at which the objects will be added.
`java.lang.Object` `getOldValue()` This returns the old value of the feature which must be restored during undo.
`EObject` `getOwner()` This returns the owner object upon which the command will act.
`EList<java.lang.Object>` `getOwnerList()` If the command will set a single value in a list, this returns the list in which it will set; null otherwise.
`java.lang.Object` `getValue()` This returns the value to be set.
`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, doDispose, doGetChildrenToCopy, doGetDescription, doGetLabel, execute, getAffectedObjects, getChildrenToCopy, getDescription, getDomain, getLabel, getOverride, getOwnerList, getResult, redo, setOverride, undo`

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

### UNSET_VALUE

    public static final java.lang.Object UNSET_VALUE

  Specify this as the value in order to unset a feature. Note that this value can be specified for a multiplicity-1 feature or for a multiplicity-many feature with no index given. Unsetting a single value within a list is not possible.

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

### feature

    protected EStructuralFeature feature

  This is the feature of the owner object upon the command will act.

### ownerList

    protected EList<java.lang.Object> ownerList

  If non-null, this is the list in which the command will set a value. If null, feature is single-valued or no index was specified.

### value

    protected java.lang.Object value

  This is the value to be set.

### oldValue

    protected java.lang.Object oldValue

  This is the old value of the feature which must be restored during undo.

### index

    protected int index

  This is the position at which the object will be set.

### canUndo

    protected boolean canUndo

  This specified whether or not this command can be undone.

### ecorePackage

    protected static final EcorePackage ecorePackage

Constructor Detail

### SetCommand

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

  This constructs a primitive command to set the owner's feature to the specified value.

### SetCommand

    public SetCommand(EditingDomain domain,
                      EObject owner,
                      EStructuralFeature feature,
                      java.lang.Object value,
                      int index)

  This constructs a primitive command to set the owner's feature to the specified value at the given index.

Method Detail

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object owner,
                                 java.lang.Object feature,
                                 java.lang.Object value)

  This creates a command to set the owner's feature to the specified value.

### create

    public static Command create(EditingDomain domain,
                                 java.lang.Object owner,
                                 java.lang.Object feature,
                                 java.lang.Object value,
                                 int index)

  This creates a command to set the owner's feature to the specified value at the specified index.

### getOwner

    public EObject getOwner()

  This returns the owner object upon which the command will act.

### getFeature

    public EStructuralFeature getFeature()

  This returns the feature of the owner object upon the command will act.

### getOwnerList

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

  If the command will set a single value in a list, this returns the list in which it will set; null otherwise.

### getIndex

    public int getIndex()

  This returns the position at which the objects will be added.

### getValue

    public java.lang.Object getValue()

  This returns the value to be set.

### getOldValue

    public java.lang.Object getOldValue()

  This returns the old value of the feature which must be restored during undo.

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

### doCanUndo

    public boolean doCanUndo()

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

  Specified by:
    `doCanUndo` in interface `OverrideableCommand`
  Overrides:
    `doCanUndo` 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.