public class SetCommand extends AbstractOverrideableCommand
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
.
Modifier and Type | Class and Description |
---|---|
protected static class |
SetCommand.PessimisticStrictCompoundCommand |
AbstractCommand.NonDirtying
Modifier and Type | Field and Description |
---|---|
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.
|
protected Command |
removeCommand
This is any remove commands needed to clear this many valued list or to update the opposite properly.
|
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.
|
domain, overrideCommand
description, isExecutable, isPrepared, label
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
canExecute, canUndo, dispose, doCanExecute, doDispose, doGetChildrenToCopy, doGetDescription, doGetLabel, execute, getAffectedObjects, getChildrenToCopy, getDescription, getDomain, getLabel, getOverride, getOwnerList, getResult, redo, setOverride, undo, updateEMap
chain, setDescription, setLabel
public static final java.lang.Object UNSET_VALUE
protected static final java.lang.String LABEL
protected static final java.lang.String DESCRIPTION
protected EObject owner
protected EStructuralFeature feature
protected EList<java.lang.Object> ownerList
protected java.lang.Object value
protected java.lang.Object oldValue
protected int index
protected boolean canUndo
protected Command removeCommand
protected static final EcorePackage ecorePackage
public SetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value)
public SetCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object value, int index)
public static Command create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.lang.Object value)
public static Command create(EditingDomain domain, java.lang.Object owner, java.lang.Object feature, java.lang.Object value, int index)
public EObject getOwner()
public EStructuralFeature getFeature()
public EList<java.lang.Object> getOwnerList()
public int getIndex()
public java.lang.Object getValue()
public java.lang.Object getOldValue()
protected boolean prepare()
AbstractCommand
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.prepare
in class AbstractCommand
public void doExecute()
OverrideableCommand
doExecute
in interface OverrideableCommand
doExecute
in class AbstractOverrideableCommand
public boolean doCanUndo()
OverrideableCommand
doCanUndo
in interface OverrideableCommand
doCanUndo
in class AbstractOverrideableCommand
public void doUndo()
OverrideableCommand
doUndo
in interface OverrideableCommand
doUndo
in class AbstractOverrideableCommand
public void doRedo()
OverrideableCommand
doRedo
in interface OverrideableCommand
doRedo
in class AbstractOverrideableCommand
public java.util.Collection<?> doGetResult()
OverrideableCommand
doGetResult
in interface OverrideableCommand
doGetResult
in class AbstractOverrideableCommand
public java.util.Collection<?> doGetAffectedObjects()
OverrideableCommand
doGetAffectedObjects
in interface OverrideableCommand
doGetAffectedObjects
in class AbstractOverrideableCommand
public java.lang.String toString()
toString
in class AbstractOverrideableCommand