| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 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 implementation |
| //------------------------------------------------------------------------------ |
| /** |
| * |
| */ |
| package org.eclipse.epf.diagramming.base.commands; |
| |
| import org.eclipse.epf.diagram.core.bridge.BridgeHelper; |
| import org.eclipse.epf.library.ILibraryManager; |
| import org.eclipse.epf.library.LibraryService; |
| import org.eclipse.epf.uma.DescribableElement; |
| import org.eclipse.epf.uma.MethodElement; |
| import org.eclipse.gef.commands.Command; |
| import org.eclipse.uml2.uml.ActivityNode; |
| import org.eclipse.uml2.uml.NamedElement; |
| |
| /** |
| * |
| * @author Shashidhar Kannoori |
| */ |
| public class EditNameCommand extends Command { |
| |
| public static final String label = "EditNameCommand"; |
| private NamedElement object; |
| private String newValue; |
| private String oldName, oldPresentationName; |
| private String elementGuid; |
| |
| public EditNameCommand(NamedElement object, String newValue) { |
| super(label); |
| this.object = object; |
| this.newValue = newValue; |
| } |
| |
| public boolean canExecute() { |
| return super.canExecute(); |
| } |
| |
| public void execute() { |
| MethodElement element = BridgeHelper.getMethodElement((ActivityNode)object); |
| |
| // set Name |
| this.oldName = element.getName(); |
| element.setName(newValue); |
| elementGuid = element.getGuid(); |
| |
| // setPresentationName |
| if(element instanceof DescribableElement){ |
| this.oldPresentationName = ((DescribableElement)element).getPresentationName(); |
| ((DescribableElement)element).setPresentationName(newValue); |
| } |
| |
| } |
| |
| public void redo() { |
| execute(); |
| } |
| public void undo() { |
| ILibraryManager manager = LibraryService.getInstance() |
| .getCurrentLibraryManager(); |
| if(manager != null){ |
| MethodElement element = manager.getMethodElement(elementGuid); |
| if(element != null){ |
| element.setName(this.oldName); |
| if(element instanceof DescribableElement){ |
| ((DescribableElement)element).setPresentationName(this.oldPresentationName); |
| } |
| } |
| } |
| } |
| } |