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. 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 null and the feature is an attribute.

Setting a feature that is a bi-directional 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 can be undone.

A set command is an OverrideableCommand.


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 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  java.lang.Object value
          This is the value of 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.
 
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.
 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.
 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.
 java.lang.Object getValue()
          This returns the value of to be set.
protected  boolean prepare()
          Called at most once in AbstractOverrideableCommand.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

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.

value

protected java.lang.Object value
This is the value of to be set.

oldValue

protected java.lang.Object oldValue
This is the old value of the feature which must be restored during undo.

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

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.

getValue

public java.lang.Object getValue()
This returns the value of 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
Following copied from class: org.eclipse.emf.common.command.AbstractCommand
Returns:
whether the command is executable.

doExecute

public void doExecute()
Description copied from interface: OverrideableCommand
This is overrideable command's implementation of execute.
Overrides:
doExecute in class AbstractOverrideableCommand

doCanUndo

public boolean doCanUndo()
Description copied from interface: OverrideableCommand
This is overrideable command's implementation of canUndo.
Overrides:
doCanUndo in class AbstractOverrideableCommand

doUndo

public void doUndo()
Description copied from interface: OverrideableCommand
This is overrideable command's implementation of undo.
Overrides:
doUndo in class AbstractOverrideableCommand

doRedo

public void doRedo()
Description copied from interface: OverrideableCommand
This is overrideable command's implementation of redo.
Overrides:
doRedo in class AbstractOverrideableCommand

doGetResult

public java.util.Collection doGetResult()
Description copied from interface: OverrideableCommand
This is overrideable command's implementation of getResult.
Overrides:
doGetResult in class AbstractOverrideableCommand

doGetAffectedObjects

public java.util.Collection doGetAffectedObjects()
Description copied from interface: OverrideableCommand
This is overrideable command's implementation of getAffectedObjects.
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
Following copied from class: org.eclipse.emf.common.command.AbstractCommand
Returns:
string representation.

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