001 /**
002 * <copyright>
003 *
004 * Copyright (c) 2002-2004 IBM Corporation and others.
005 * All rights reserved. This program and the accompanying materials
006 * are made available under the terms of the Eclipse Public License v1.0
007 * which accompanies this distribution, and is available at
008 * http://www.eclipse.org/legal/epl-v10.html
009 *
010 * Contributors:
011 * IBM - Initial API and implementation
012 *
013 * </copyright>
014 *
015 * $Id: CommandStack.java,v 1.2 2005/06/08 05:44:08 nickb Exp $
016 */
017 package org.eclipse.emf.common.command;
018
019
020
021 /**
022 * A simple and obvious interface for an undoable stack of commands with a listener.
023 * See {@link Command} for more details about the command methods that this implementation uses
024 * and {@link CommandStackListener} for details about the listener.
025 */
026 public interface CommandStack
027 {
028 /**
029 * Clears any redoable commands not yet redone, adds the command, and then executes the command.
030 * @param command the command to execute.
031 */
032 void execute(Command command);
033
034 /**
035 * Returns whether the top command on the stack can be undone.
036 * @return whether the top command on the stack can be undone.
037 */
038 boolean canUndo();
039
040 /**
041 * Moves the top of the stack down, undoing what was formerly the top command.
042 */
043 void undo();
044
045 /**
046 * Returns whether there are commands past the top of the stack that can be redone.
047 * @return whether there are commands past the top of the stack that can be redone.
048 */
049 boolean canRedo();
050
051 /**
052 * Returns the command that will be undone if {@link #undo} is called.
053 * @return the command that will be undone if {@link #undo} is called.
054 */
055 public Command getUndoCommand();
056
057 /**
058 * Returns the command that will be redone if {@link #redo} is called.
059 * @return the command that will be redone if {@link #redo} is called.
060 */
061 public Command getRedoCommand();
062
063 /**
064 * Returns the command most recently executed, undone, or redone.
065 * @return the command most recently executed, undone, or redone.
066 */
067 public Command getMostRecentCommand();
068
069 /**
070 * Moves the top of the stack up, redoing the new top command.
071 */
072 void redo();
073
074 /**
075 * Disposes all the commands in the stack.
076 */
077 void flush();
078
079 /**
080 * Adds a listener to the command stack, which will be notified whenever a command has been processed on the stack.
081 * @param listener the listener to add.
082 */
083 void addCommandStackListener(CommandStackListener listener);
084
085 /**
086 * Removes a listener from the command stack.
087 * @param listener the listener to remove.
088 */
089 void removeCommandStackListener(CommandStackListener listener);
090 }