Package ptolemy.moml

Class MoMLUndoEntry

  • All Implemented Interfaces:
    UndoAction, ChangeListener

    public class MoMLUndoEntry
    extends java.lang.Object
    implements UndoAction, ChangeListener
    This is an undo action on the undo/redo stack. The undo/redo stack is stored in an instance of UndoInfoAttribute associated with the top-level of a model. If undo/redo is enabled, a MoMLParser will create entries automatically and put them on the stack whenever it parses MoML. So the easiest mechanism to perform undoable actions is to specify those actions in MoML and issue a MoMLChangeRequest to execute them. An alternative, however, is to create an instance of this class with no MoML, using the single argument constructor, and to override execute() to directly perform the undo.
    Since:
    Ptolemy II 2.1
    Version:
    $Id$
    Author:
    Neil Smyth and Edward A. Lee
    See Also:
    MoMLParser, UndoStackAttribute, MoMLChangeRequest
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Constructor Summary

      Constructors 
      Constructor Description
      MoMLUndoEntry​(NamedObj context, java.lang.String undoMoML)
      Create an undo entry comprised of the specified MoML code.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void changeExecuted​(ChangeRequest change)
      Do nothing.
      void changeFailed​(ChangeRequest change, java.lang.Exception exception)
      Record the exception so that execute() can throw it.
      void execute()
      Parse the MoML specified in the constructor call in the context specified in the constructor call using the parser associated with the context (as determined by ParserAttribute.getParser()).
      java.lang.String toString()
      Return the MoML of the undo action.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • MoMLUndoEntry

        public MoMLUndoEntry​(NamedObj context,
                             java.lang.String undoMoML)
        Create an undo entry comprised of the specified MoML code.
        Parameters:
        context - The context in which to execute the undo.
        undoMoML - The MoML specification of the undo action.
    • Method Detail

      • changeExecuted

        public void changeExecuted​(ChangeRequest change)
        Do nothing. This method is called when a change is successfully executed.
        Specified by:
        changeExecuted in interface ChangeListener
        Parameters:
        change - The change that was successfully executed.
      • changeFailed

        public void changeFailed​(ChangeRequest change,
                                 java.lang.Exception exception)
        Record the exception so that execute() can throw it.
        Specified by:
        changeFailed in interface ChangeListener
        Parameters:
        change - The change that failed.
        exception - The exception that occurred.
        See Also:
        execute()
      • execute

        public void execute()
                     throws java.lang.Exception
        Parse the MoML specified in the constructor call in the context specified in the constructor call using the parser associated with the context (as determined by ParserAttribute.getParser()).
        Specified by:
        execute in interface UndoAction
        Throws:
        java.lang.Exception - If something goes wrong.
        See Also:
        ParserAttribute.getParser(NamedObj)
      • toString

        public java.lang.String toString()
        Return the MoML of the undo action.
        Overrides:
        toString in class java.lang.Object
        Returns:
        MoML for the undo action.