org.eclipse.emf.edit.command
Class CreateChildCommand

java.lang.Object
  extended by org.eclipse.emf.common.command.AbstractCommand
      extended by org.eclipse.emf.common.command.CommandWrapper
          extended by org.eclipse.emf.edit.command.CreateChildCommand
All Implemented Interfaces:
Command, CommandActionDelegate

public class CreateChildCommand
extends CommandWrapper
implements CommandActionDelegate

This command wraps an AddCommand or SetCommand to provide the higher-level operation of "creating" an appropriate child object and adding it to a owner object. In fact, all of the possible child objects are created by the owner's item provider before this command is created, and specified in the newChildDescriptor argument to create() -- they must be, so that the user can specify which he actually wishes to create. As a result, this command essentially just creates and executes the appropriate lower-level EMF command, and delegates matters of appearance (text, icon, result) to the appropriate item provider, so that it may be handled correctly for the given model.

Note that this command makes no assumptions about the relationship between the owner, to which the new child will be added, and the selected object. This allows the command to be reused for sibling creation. As a result, the selection be explicitly specified, so that it can be restored when the command is undone.


Nested Class Summary
static interface CreateChildCommand.Helper
          This is the helper interface to which CreateChildCommand functionality is delegated.
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand
AbstractCommand.NonDirtying
 
Field Summary
protected  java.util.Collection<?> affectedObjects
          This is the value to be returned by getAffectedObjects().
protected  java.lang.Object child
          This is the child object to be added.
protected  EditingDomain domain
          This is the editing domain in which this command operates.
protected  EStructuralFeature feature
          This is the feature of the owner to which the child will be added.
protected  CreateChildCommand.Helper helper
          This is the helper object, usually the item provider for owner, to which parts of this command's functionality are delegated.
protected  int index
          This is the index for the new object's position under the feature.
protected static int NO_INDEX
          Deprecated. As of EMF 2.0, use CommandParameter.NO_INDEX, whose value is equal to this, instead.
protected  EObject owner
          This is the object to which the child will be added.
protected  java.util.Collection<?> selection
          This is the collection of objects that were selected when this command was created.
 
Fields inherited from class org.eclipse.emf.common.command.CommandWrapper
command
 
Fields inherited from class org.eclipse.emf.common.command.AbstractCommand
description, isExecutable, isPrepared, label
 
Constructor Summary
CreateChildCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object child, java.util.Collection<?> selection)
          This constructor initializes an instance that adds the specified child object to the feature of the owner object.
CreateChildCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object child, java.util.Collection<?> selection, CreateChildCommand.Helper helper)
          This constructor initializes an instance, as above, but the command delegates functionality to the specified Helper.
CreateChildCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object child, int index, java.util.Collection<?> selection)
          This constructor initializes an instance that adds the specified child object to the owner object, at the specified index of its feature feature, if it is multi-valued.
CreateChildCommand(EditingDomain domain, EObject owner, EStructuralFeature feature, java.lang.Object child, int index, java.util.Collection<?> selection, CreateChildCommand.Helper helper)
          This constructor initializes an instance, as above, but the command delegates functionality to the specified Helper.
 
Method Summary
static Command create(EditingDomain domain, java.lang.Object owner, java.lang.Object newChildDescriptor, java.util.Collection<?> selection)
          This returns a command created by the editing domain to add the child described by newChildDescriptor to the given object.
protected  Command createCommand()
          This creates the wrapped AddCommand or SetCommand that adds the child object to the model.
 void execute()
          This executes the wrapped command and sets the affected objects to the collection returned by helper.getCreateChildResult().
 java.util.Collection<?> getAffectedObjects()
          This returns the affected objects.
 java.lang.String getDescription()
          This returns the description by delegating to helper.getCreateChildDescription().
 java.lang.Object getImage()
          This returns the icon by delegating to helper.getCreateChildImage().
 java.util.Collection<?> getResult()
          This returns the result of this command by delegating to helper.getCreateChildResult().
 java.lang.String getText()
          This returns the label by delegating to helper.getCreateChildText().
 java.lang.String getToolTipText()
          This returns the tool tip text by delegating to helper.getCreateChildToolTipText().
 void redo()
          This redoes the wrapped command and sets the affected objects to the collection returned by helper.getCreateChildResult().
 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.
 void undo()
          This undoes the wrapped command and sets the affected objects to the original selection.
 
Methods inherited from class org.eclipse.emf.common.command.CommandWrapper
canUndo, dispose, getCommand, getLabel, prepare
 
Methods inherited from class org.eclipse.emf.common.command.AbstractCommand
canExecute, 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.edit.command.CommandActionDelegate
canExecute
 

Field Detail

NO_INDEX

@Deprecated
protected static final int NO_INDEX
Deprecated. As of EMF 2.0, use CommandParameter.NO_INDEX, whose value is equal to this, instead.
This value is used to indicate that an optional positional index indicator is unspecified.

See Also:
Constant Field Values

domain

protected EditingDomain domain
This is the editing domain in which this command operates.


owner

protected EObject owner
This is the object to which the child will be added.


feature

protected EStructuralFeature feature
This is the feature of the owner to which the child will be added.


child

protected java.lang.Object child
This is the child object to be added.


index

protected int index
This is the index for the new object's position under the feature.


helper

protected CreateChildCommand.Helper helper
This is the helper object, usually the item provider for owner, to which parts of this command's functionality are delegated.


affectedObjects

protected java.util.Collection<?> affectedObjects
This is the value to be returned by getAffectedObjects(). The affected objects are different after an execute or redo from after an undo, so we record them.


selection

protected java.util.Collection<?> selection
This is the collection of objects that were selected when this command was created. After an undo, these are considered the affected objects.

Constructor Detail

CreateChildCommand

public CreateChildCommand(EditingDomain domain,
                          EObject owner,
                          EStructuralFeature feature,
                          java.lang.Object child,
                          java.util.Collection<?> selection)
This constructor initializes an instance that adds the specified child object to the feature of the owner object. If any of owner, feature, or child are null, createCommand() will return UnexecutableCommand.INSTANCE and, hence, AbstractCommand.canExecute() will return false. If non-null, selection is the collection of selected objects. An internal default Helper will provide generic implmentations for the delegated command methods.


CreateChildCommand

public CreateChildCommand(EditingDomain domain,
                          EObject owner,
                          EStructuralFeature feature,
                          java.lang.Object child,
                          java.util.Collection<?> selection,
                          CreateChildCommand.Helper helper)
This constructor initializes an instance, as above, but the command delegates functionality to the specified Helper. If helper is null, the internal default helper is used.


CreateChildCommand

public CreateChildCommand(EditingDomain domain,
                          EObject owner,
                          EStructuralFeature feature,
                          java.lang.Object child,
                          int index,
                          java.util.Collection<?> selection)
This constructor initializes an instance that adds the specified child object to the owner object, at the specified index of its feature feature, if it is multi-valued. If any of owner, feature, or child are null, createCommand() will return UnexecutableCommand.INSTANCE and, hence, AbstractCommand.canExecute() will return false. If non-null, selection is the collection of selected objects. The internal default helper is used by the command. If index is CommandParameter.NO_INDEX, this behaves just like the first constructor form.


CreateChildCommand

public CreateChildCommand(EditingDomain domain,
                          EObject owner,
                          EStructuralFeature feature,
                          java.lang.Object child,
                          int index,
                          java.util.Collection<?> selection,
                          CreateChildCommand.Helper helper)
This constructor initializes an instance, as above, but the command delegates functionality to the specified Helper. If helper is null, the internal default helper is used.

Method Detail

create

public static Command create(EditingDomain domain,
                             java.lang.Object owner,
                             java.lang.Object newChildDescriptor,
                             java.util.Collection<?> selection)
This returns a command created by the editing domain to add the child described by newChildDescriptor to the given object.


createCommand

protected Command createCommand()
This creates the wrapped AddCommand or SetCommand that adds the child object to the model. If the owner, feature, or child is null, or if the feature is single-valued and has already been set to an object, UnexecutableCommand.INSTANCE will be returned.

Overrides:
createCommand in class CommandWrapper
Returns:
the command being proxied.

execute

public void execute()
This executes the wrapped command and sets the affected objects to the collection returned by helper.getCreateChildResult().

Specified by:
execute in interface Command
Overrides:
execute in class CommandWrapper

undo

public void undo()
This undoes the wrapped command and sets the affected objects to the original selection.

Specified by:
undo in interface Command
Overrides:
undo in class CommandWrapper

redo

public void redo()
This redoes the wrapped command and sets the affected objects to the collection returned by helper.getCreateChildResult().

Specified by:
redo in interface Command
Overrides:
redo in class CommandWrapper

getAffectedObjects

public java.util.Collection<?> getAffectedObjects()
This returns the affected objects.

Specified by:
getAffectedObjects in interface Command
Overrides:
getAffectedObjects in class CommandWrapper
Returns:
the result.

getResult

public java.util.Collection<?> getResult()
This returns the result of this command by delegating to helper.getCreateChildResult().

Specified by:
getResult in interface Command
Overrides:
getResult in class CommandWrapper
Returns:
the result.

getText

public java.lang.String getText()
This returns the label by delegating to helper.getCreateChildText().

Specified by:
getText in interface CommandActionDelegate

getDescription

public java.lang.String getDescription()
This returns the description by delegating to helper.getCreateChildDescription().

Specified by:
getDescription in interface Command
Specified by:
getDescription in interface CommandActionDelegate
Overrides:
getDescription in class CommandWrapper
Returns:
the description.

getToolTipText

public java.lang.String getToolTipText()
This returns the tool tip text by delegating to helper.getCreateChildToolTipText().

Specified by:
getToolTipText in interface CommandActionDelegate

getImage

public java.lang.Object getImage()
This returns the icon by delegating to helper.getCreateChildImage().

Specified by:
getImage in interface CommandActionDelegate

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 CommandWrapper
Returns:
string representation.

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