de.cau.cs.kieler.core.model.util
Class PossiblyEmptyCompoundCommand

java.lang.Object
  extended by org.eclipse.emf.common.command.AbstractCommand
      extended by org.eclipse.emf.common.command.CompoundCommand
          extended by de.cau.cs.kieler.core.model.util.PossiblyEmptyCompoundCommand
All Implemented Interfaces:
Command

public class PossiblyEmptyCompoundCommand
extends CompoundCommand

A CompoundCommand that may be empty. Even when the list of commands stored within is empty, the prepare() method will return true and hence the command is marked as executable. Can be used to create an empty executable command.

Rating red

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.command.AbstractCommand
AbstractCommand.NonDirtying
 
Field Summary
 
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
PossiblyEmptyCompoundCommand()
           
 
Method Summary
protected  boolean prepare()
          Returns whether all the commands can execute so that AbstractCommand.isExecutable can be cached.
 Command unwrap()
          Return one of three commands: If the command list is empty, return null; if there is exactly one command in the list, return that command; otherwise return this PossiblyEmptyCompoundCommand.
 Command unwrapAll()
          Flatten all PossiblyEmptyCompoundCommands recursively.
 
Methods inherited from class org.eclipse.emf.common.command.CompoundCommand
append, appendAndExecute, appendIfCanExecute, canUndo, dispose, execute, getAffectedObjects, getCommandList, getDescription, getLabel, getMergedAffectedObjectsCollection, getMergedResultCollection, getResult, getResultIndex, isEmpty, redo, toString, undo
 
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
 

Constructor Detail

PossiblyEmptyCompoundCommand

public PossiblyEmptyCompoundCommand()
Method Detail

prepare

protected boolean prepare()
Returns whether all the commands can execute so that AbstractCommand.isExecutable can be cached. An empty command list causes true to be returned.

Overrides:
prepare in class CompoundCommand
Returns:
whether all the commands can execute.

unwrap

public Command unwrap()
Return one of three commands: If the command list is empty, return null; if there is exactly one command in the list, return that command; otherwise return this PossiblyEmptyCompoundCommand. Can be used to remove unnecessary hierarchy levels of commands.

Overrides:
unwrap in class CompoundCommand
Returns:
the resulting Command, maybe null

unwrapAll

public Command unwrapAll()
Flatten all PossiblyEmptyCompoundCommands recursively. Go recursively through all PossiblEmptyCompoundCommand children and unwrap them all. If a result is still a PossiblyEmptyCompoundCommand, all of its children are moved one level up and the compound command gets removed.

Returns:
Either a flat PossiblyEmptyCompoundCommand or one single other Command or maybe null.