Class ProgressCompoundCommand

  • All Implemented Interfaces:
    org.eclipse.emf.common.command.Command

    public class ProgressCompoundCommand
    extends org.eclipse.emf.common.command.CompoundCommand
    Extension of the CompoundCommand which reports progress.
    Since:
    1.11
    Author:
    Johannes Faltermeier
    • Nested Class Summary

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

        org.eclipse.emf.common.command.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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void append​(org.eclipse.emf.common.command.Command command)
      Adds a command to this compound command's list of commands.
      boolean appendAndExecute​(org.eclipse.emf.common.command.Command command)
      Checks if the command can execute; if so, it is executed, appended to the list, and true is returned, if not, it is just disposed and false is returned.
      boolean appendIfCanExecute​(org.eclipse.emf.common.command.Command command)
      Adds a command to this compound command's the list of commands and returns true, if command.canExecute() returns true; otherwise, it simply calls command.dispose() and returns false.
      boolean canUndo()
      Returns false if any of the commands return false for Command.canUndo().
      void dispose()
      Calls Command.dispose() for each command in the list.
      void execute()
      Calls Command.execute() for each command in the list.
      java.util.Collection<?> getAffectedObjects()
      Determines the affected objects by composing the affected objects of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
      java.util.List<org.eclipse.emf.common.command.Command> getCommandList()
      Returns an unmodifiable view of the commands in the list.
      java.lang.String getDescription()
      Determines the description by composing the descriptions of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
      java.lang.String getLabel()
      Determines the label by composing the labels of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
      protected java.util.Collection<?> getMergedAffectedObjectsCollection()
      Returns the merged collection of all command affected objects.
      protected java.util.Collection<?> getMergedResultCollection()
      Returns the merged collection of all command results.
      java.util.Collection<?> getResult()
      Determines the result by composing the results of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
      int getResultIndex()
      Returns the index of the command whose result and affected objects are forwarded.
      boolean isEmpty()
      Returns whether there are commands in the list.
      protected boolean prepare()
      Returns whether all the commands can execute so that AbstractCommand.isExecutable can be cached.
      void redo()
      Calls Command.redo() for each command in the list.
      java.lang.String toString()  
      void undo()
      Calls Command.undo() for each command in the list, in reverse order.
      org.eclipse.emf.common.command.Command unwrap()
      Returns one of three things: UnexecutableCommand.INSTANCE, if there are no commands, the one command, if there is exactly one command, or this, if there are multiple commands; this command is dispose()d in the first two cases.
      • 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

      • ProgressCompoundCommand

        public ProgressCompoundCommand​(int resultIndex,
                                       IProgressMonitorProvider monitor)
        Creates an empty instance with the given result index.
        Parameters:
        resultIndex - the CompoundCommand.resultIndex.
        monitor - the progress monitor
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns whether there are commands in the list.
        Overrides:
        isEmpty in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        whether there are commands in the list.
      • getCommandList

        public java.util.List<org.eclipse.emf.common.command.Command> getCommandList()
        Returns an unmodifiable view of the commands in the list.
        Overrides:
        getCommandList in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        an unmodifiable view of the commands in the list.
      • getResultIndex

        public int getResultIndex()
        Returns the index of the command whose result and affected objects are forwarded. Negative values have special meaning, as defined by the static constants.
        Overrides:
        getResultIndex in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the index of the command whose result and affected objects are forwarded.
        See Also:
        CompoundCommand.LAST_COMMAND_ALL, CompoundCommand.MERGE_COMMAND_ALL
      • prepare

        protected boolean prepare()
        Returns whether all the commands can execute so that AbstractCommand.isExecutable can be cached. An empty command list causes false to be returned.
        Overrides:
        prepare in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        whether all the commands can execute.
      • execute

        public void execute()
        Calls Command.execute() for each command in the list.
        Specified by:
        execute in interface org.eclipse.emf.common.command.Command
        Overrides:
        execute in class org.eclipse.emf.common.command.CompoundCommand
      • canUndo

        public boolean canUndo()
        Returns false if any of the commands return false for Command.canUndo().
        Specified by:
        canUndo in interface org.eclipse.emf.common.command.Command
        Overrides:
        canUndo in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        false if any of the commands return false for canUndo.
      • undo

        public void undo()
        Calls Command.undo() for each command in the list, in reverse order.
        Specified by:
        undo in interface org.eclipse.emf.common.command.Command
        Overrides:
        undo in class org.eclipse.emf.common.command.CompoundCommand
      • redo

        public void redo()
        Calls Command.redo() for each command in the list.
        Specified by:
        redo in interface org.eclipse.emf.common.command.Command
        Overrides:
        redo in class org.eclipse.emf.common.command.CompoundCommand
      • getResult

        public java.util.Collection<?> getResult()
        Determines the result by composing the results of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
        Specified by:
        getResult in interface org.eclipse.emf.common.command.Command
        Overrides:
        getResult in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the result.
      • getMergedResultCollection

        protected java.util.Collection<?> getMergedResultCollection()
        Returns the merged collection of all command results.
        Overrides:
        getMergedResultCollection in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the merged collection of all command results.
      • getAffectedObjects

        public java.util.Collection<?> getAffectedObjects()
        Determines the affected objects by composing the affected objects of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
        Specified by:
        getAffectedObjects in interface org.eclipse.emf.common.command.Command
        Overrides:
        getAffectedObjects in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the affected objects.
      • getMergedAffectedObjectsCollection

        protected java.util.Collection<?> getMergedAffectedObjectsCollection()
        Returns the merged collection of all command affected objects.
        Overrides:
        getMergedAffectedObjectsCollection in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the merged collection of all command affected objects.
      • getLabel

        public java.lang.String getLabel()
        Determines the label by composing the labels of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
        Specified by:
        getLabel in interface org.eclipse.emf.common.command.Command
        Overrides:
        getLabel in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the label.
      • getDescription

        public java.lang.String getDescription()
        Determines the description by composing the descriptions of the commands in the list; this is affected by the setting of CompoundCommand.resultIndex.
        Specified by:
        getDescription in interface org.eclipse.emf.common.command.Command
        Overrides:
        getDescription in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the description.
      • append

        public void append​(org.eclipse.emf.common.command.Command command)
        Adds a command to this compound command's list of commands.
        Overrides:
        append in class org.eclipse.emf.common.command.CompoundCommand
        Parameters:
        command - the command to append.
      • appendAndExecute

        public boolean appendAndExecute​(org.eclipse.emf.common.command.Command command)
        Checks if the command can execute; if so, it is executed, appended to the list, and true is returned, if not, it is just disposed and false is returned. A typical use for this is to execute commands created during the execution of another command, e.g.,
           class MyCommand extends CommandBase
           {
             protected Command subcommand;
        
             //...
        
             public void execute()
             {
               // ...
               Compound subcommands = new CompoundCommand();
               subcommands.appendAndExecute(new AddCommand(...));
               if (condition) subcommands.appendAndExecute(new AddCommand(...));
               subcommand = subcommands.unwrap();
             }
        
             public void undo()
             {
               // ...
               subcommand.undo();
             }
        
             public void redo()
             {
               // ...
               subcommand.redo();
             }
        
             public void dispose()
             {
               // ...
               if (subcommand != null)
              {
                 subcommand.dispose();
               }
             }
           }
         
        Another use is in an execute override of compound command itself:
           class MyCommand extends CompoundCommand
           {
             public void execute()
             {
               // ...
               appendAndExecute(new AddCommand(...));
               if (condition) appendAndExecute(new AddCommand(...));
             }
           }
         
        Note that appending commands will modify what getResult and getAffectedObjects return, so you may want to set the resultIndex flag.
        Overrides:
        appendAndExecute in class org.eclipse.emf.common.command.CompoundCommand
        Parameters:
        command - the command.
        Returns:
        whether the command was successfully executed and appended.
      • appendIfCanExecute

        public boolean appendIfCanExecute​(org.eclipse.emf.common.command.Command command)
        Adds a command to this compound command's the list of commands and returns true, if command.canExecute() returns true; otherwise, it simply calls command.dispose() and returns false.
        Overrides:
        appendIfCanExecute in class org.eclipse.emf.common.command.CompoundCommand
        Parameters:
        command - the command.
        Returns:
        whether the command was executed and appended.
      • dispose

        public void dispose()
        Calls Command.dispose() for each command in the list.
        Specified by:
        dispose in interface org.eclipse.emf.common.command.Command
        Overrides:
        dispose in class org.eclipse.emf.common.command.CompoundCommand
      • unwrap

        public org.eclipse.emf.common.command.Command unwrap()
        Returns one of three things: UnexecutableCommand.INSTANCE, if there are no commands, the one command, if there is exactly one command, or this, if there are multiple commands; this command is dispose()d in the first two cases. You should only unwrap a compound command if you created it for that purpose, e.g.,
         CompoundCommand subcommands = new CompoundCommand();
         subcommands.append(x);
         if (condition)
                subcommands.append(y);
         Command result = subcommands.unwrap();
         
        is a good way to create an efficient accumulated result.
        Overrides:
        unwrap in class org.eclipse.emf.common.command.CompoundCommand
        Returns:
        the unwrapped command.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class org.eclipse.emf.common.command.CompoundCommand