001/* A request to redo. 002 003 Copyright (c) 2000-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 */ 027package ptolemy.kernel.undo; 028 029import ptolemy.kernel.util.ChangeRequest; 030import ptolemy.kernel.util.InternalErrorException; 031import ptolemy.kernel.util.NamedObj; 032 033/////////////////////////////////////////////////////////////////// 034//// 035 036/** 037 A change request to redo. When executed, this change request will 038 identify the undo stack associated with the specified context, 039 and it will execute the top redo action on that stack, if there is 040 one. 041 <p> 042 @author Edward A. Lee and Neil Smyth 043 @version $Id$ 044 @since Ptolemy II 4.0 045 @Pt.ProposedRating Green (eal) 046 @Pt.AcceptedRating Green (hyzheng) 047 */ 048public class RedoChangeRequest extends ChangeRequest { 049 /** Construct a change request to be executed in the specified context. 050 * The redo stack associated with the specified context will be used. 051 * That stack is the one returned by UndoStackAttribute.getUndoInfo(). 052 * @see UndoStackAttribute 053 * @param originator The originator of the change request. 054 * @param context The context in which to execute the MoML. 055 */ 056 public RedoChangeRequest(Object originator, NamedObj context) { 057 super(originator, "Request to redo."); 058 _context = context; 059 } 060 061 /////////////////////////////////////////////////////////////////// 062 //// public methods //// 063 064 /** Return the context specified in the constructor, or null if none 065 * was specified. 066 * @return The context. 067 */ 068 public NamedObj getContext() { 069 return _context; 070 } 071 072 /////////////////////////////////////////////////////////////////// 073 //// protected methods //// 074 075 /** Execute the change by invoking redo on the undo stack of 076 * the context specified in the constructor. 077 * @exception Exception If an exception is thrown 078 * while evaluating the request. 079 */ 080 @Override 081 protected void _execute() throws Exception { 082 // Check to see whether there is a context... 083 if (_context == null) { 084 throw new InternalErrorException("Context is unexpectedly null."); 085 } 086 087 UndoStackAttribute undoStack = UndoStackAttribute.getUndoInfo(_context); 088 089 // The undo action may involve several subactions. 090 // These may queue further change requests. 091 // Collect these change requests without executing them 092 // until after the whole action is completed. 093 boolean previous = _context.isDeferringChangeRequests(); 094 095 try { 096 previous = _context.isDeferringChangeRequests(); 097 _context.setDeferringChangeRequests(true); 098 undoStack.redo(); 099 } finally { 100 _context.setDeferringChangeRequests(previous); 101 } 102 } 103 104 /////////////////////////////////////////////////////////////////// 105 //// private variables //// 106 // The context in which to execute the request. 107 private NamedObj _context; 108}