blob: b007571e4d0567adfe4dbf082c626006631db660 [file] [log] [blame]
/**
*
*/
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);
}
}
}
}
}