### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.runtime.diagram.ui Index: src/org/eclipse/gmf/runtime/diagram/ui/commands/DeferredCreateConnectionViewAndElementCommand.java =================================================================== RCS file: /cvsroot/technology/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/commands/DeferredCreateConnectionViewAndElementCommand.java,v retrieving revision 1.5 diff -u -r1.5 DeferredCreateConnectionViewAndElementCommand.java --- src/org/eclipse/gmf/runtime/diagram/ui/commands/DeferredCreateConnectionViewAndElementCommand.java 28 Feb 2006 02:30:51 -0000 1.5 +++ src/org/eclipse/gmf/runtime/diagram/ui/commands/DeferredCreateConnectionViewAndElementCommand.java 22 Aug 2006 20:31:55 -0000 @@ -161,7 +161,7 @@ } public boolean canRedo() { - return command != null && command.canExecute(); + return CommandUtilities.canRedo(command); } /** Index: src/org/eclipse/gmf/runtime/diagram/ui/commands/CommandUtilities.java =================================================================== RCS file: src/org/eclipse/gmf/runtime/diagram/ui/commands/CommandUtilities.java diff -N src/org/eclipse/gmf/runtime/diagram/ui/commands/CommandUtilities.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/runtime/diagram/ui/commands/CommandUtilities.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,70 @@ +/****************************************************************************** + * Copyright (c) 2006, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ****************************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.commands; + +import java.util.Iterator; + +import org.eclipse.core.commands.operations.IUndoableOperation; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.CompoundCommand; + +/** + * Class containing commands utility methods. + * + * @author aboyko + * + */ +public class CommandUtilities { + + /** + * This utility function determines whether the command is redoable. + * Since GEF commands API doesn't support for canRedo method, this + * utility will help to travel through the contents of GEF wrapper + * commands and determine redoability of the GEF command based on + * the redoability of the commands it contains. + * + * @param command The command to be examined + * @return true if the passed command is redoable + */ + public static boolean canRedo(Command command) + { + if (command == null) + return false; + + if (command instanceof IUndoableOperation) + { + return ((IUndoableOperation) command).canRedo(); + } + else if (command instanceof CompoundCommand) + { + for ( Iterator iter = ((CompoundCommand)command).getCommands().iterator(); iter.hasNext(); ) + { + try + { + if (!canRedo((Command)iter.next())) + return false; + } + catch (ClassCastException e) + { + return false; + } + } + return true; + } + else if (command instanceof ICommandProxy) + { + return ((ICommandProxy)command).getICommand().canRedo(); + } + return command.canExecute(); + } + +}