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

    java.lang.Object
      org.eclipse.emf.common.command.AbstractCommand
          org.eclipse.emf.common.command.CompoundCommand
              org.eclipse.emf.common.command.StrictCompoundCommand
                  org.eclipse.emf.edit.command.CopyCommand

All Implemented Interfaces:
  Command

    public class CopyCommand

extends StrictCompoundCommand

The copy command logically acts upon an owner object or collection or owner objects and copies the tree structured implied by the MOF containment hierarchy. The static create methods delegate command creation to `EditingDomain.createCommand`.

The copy implementation is, at each level, delegated to `CreateCopyCommand` and `InitializeCopyCommand` which can be overridden to control the copy's object creation and initialization respectively.

Nested Class Summary
`static class` `CopyCommand.Helper` This helper class is used to keep track of copied objects and their associated copies.

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

Field Summary
`protected CopyCommand.Helper` `copyHelper` This is a map of objects to their copies
`protected static java.lang.String` `DESCRIPTION` This caches the description.
`protected EditingDomain` `domain` This keeps track of the domain in which this command is created.
`protected static java.lang.String` `LABEL` This caches the label.
`protected boolean` `optimize` This controls whether or not to optimize the canExecute (prepare)
`protected EObject` `owner` This keeps track of the owner in the command parameter from the constructor.

Fields inherited from class org.eclipse.emf.common.command.StrictCompoundCommand
`isPessimistic, isUndoable, rightMostExecutedCommandIndex`

Fields inherited from class org.eclipse.emf.common.command.CompoundCommand
`commandList, LAST_COMMAND_ALL, MERGE_COMMAND_ALL, resultIndex`

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

Constructor Summary
`CopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper copyHelper)` This creates and instance in the given domain and for the given owner
`CopyCommand(EditingDomain domain, EObject owner, CopyCommand.Helper copyHelper, boolean optimize)` This creates and instance in the given domain and for the given owner

Method Summary
`protected void` `addCreateCopyCommands(CompoundCommand compoundCommand, EObject object)`
`boolean` `canExecute()` Calls `AbstractCommand.prepare()`, caches the result in `AbstractCommand.isExecutable`, and sets `AbstractCommand.isPrepared` to `true`; from then on, it will yield the value of isExecutable.
`static Command` `create(EditingDomain domain, java.util.Collection<?> collection)` This creates a command that copies the given collection of objects.
`static Command` `create(EditingDomain domain, java.lang.Object owner)` This creates a command that copies the given object.
`void` `execute()` Calls `Command.execute()` for each command in the list, but makes sure to call redo for any commands that were previously executed to compute canExecute.
`protected boolean` `prepare()` Returns `false` if any command on the list returns `false` for `Command.canExecute()`, or if some command before the last one can't be undone and hence we can't test all the commands for executability.
`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.common.command.StrictCompoundCommand
`appendAndExecute, redo, undo`

Methods inherited from class org.eclipse.emf.common.command.CompoundCommand
`append, appendIfCanExecute, canUndo, dispose, getAffectedObjects, getCommandList, getDescription, getLabel, getMergedAffectedObjectsCollection, getMergedResultCollection, getResult, getResultIndex, isEmpty, unwrap`

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`

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.

### domain

    protected EditingDomain domain

  This keeps track of the domain in which this command is created.

### owner

    protected EObject owner

  This keeps track of the owner in the command parameter from the constructor.

### copyHelper

    protected CopyCommand.Helper copyHelper

  This is a map of objects to their copies

### optimize

    protected boolean optimize

  This controls whether or not to optimize the canExecute (prepare)

Constructor Detail

### CopyCommand

    public CopyCommand(EditingDomain domain,
                       EObject owner,
                       CopyCommand.Helper copyHelper)

  This creates and instance in the given domain and for the given owner

### CopyCommand

    public CopyCommand(EditingDomain domain,
                       EObject owner,
                       CopyCommand.Helper copyHelper,
                       boolean optimize)

  This creates and instance in the given domain and for the given owner

Method Detail

### create

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

  This creates a command that copies the given object.

### create

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

  This creates a command that copies the given collection of objects. If the collection contains more than one object, then a compound command will be created containing individual copy commands for each object.

### prepare

    protected boolean prepare()

  Description copied from class: `StrictCompoundCommand`
  Returns `false` if any command on the list returns `false` for `Command.canExecute()`, or if some command before the last one can't be undone and hence we can't test all the commands for executability.

  Overrides:
    `prepare` in class `StrictCompoundCommand`
  Returns:
    whether the command can execute.

### canExecute

    public boolean canExecute()

  Description copied from class: `AbstractCommand`
  Calls `AbstractCommand.prepare()`, caches the result in `AbstractCommand.isExecutable`, and sets `AbstractCommand.isPrepared` to `true`; from then on, it will yield the value of isExecutable.

  Specified by:
    `canExecute` in interface `Command`
  Overrides:
    `canExecute` in class `AbstractCommand`
  Returns:
    whether the command can execute.

### execute

    public void execute()

  Description copied from class: `StrictCompoundCommand`
  Calls `Command.execute()` for each command in the list, but makes sure to call redo for any commands that were previously executed to compute canExecute. In the case that `StrictCompoundCommand.isPessimistic` is false, only the last command will be executed since the others will have been executed but not undone during `StrictCompoundCommand.prepare()`.

  Specified by:
    `execute` in interface `Command`
  Overrides:
    `execute` in class `StrictCompoundCommand`

### addCreateCopyCommands

    protected void addCreateCopyCommands(CompoundCommand compoundCommand,
                                         EObject object)

### 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 `StrictCompoundCommand`
  Returns:
    string representation.

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