| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 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 implementation |
| //------------------------------------------------------------------------------ |
| package org.eclipse.epf.library.edit.process.command; |
| |
| import java.util.Collection; |
| import java.util.Collections; |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.epf.uma.DeliveryProcess; |
| import org.eclipse.epf.uma.MethodConfiguration; |
| import org.eclipse.epf.uma.ProcessComponent; |
| import org.eclipse.epf.uma.ProcessPackage; |
| import org.eclipse.epf.uma.UmaFactory; |
| |
| /** |
| * Physically copies a process with all of its direct or inherited structural features and references. |
| * Add the newly created process to the specified process package. |
| * |
| * This class extends the ActivityDeepCopyCommand to reuse most of it's functionality. |
| * |
| * @author Jinhua Xi |
| * @since 1.0 |
| */ |
| public class ProcessDeepCopyCommand extends ActivityDeepCopyCommand { |
| |
| private ProcessPackage targetPackage; |
| private ProcessComponent tempPc; |
| private String newProcessName; |
| |
| public ProcessDeepCopyCommand(org.eclipse.epf.uma.Process process, String newProcessName, CopyHelper copyHelper, MethodConfiguration config, ProcessPackage targetPackage, IProgressMonitor monitor) { |
| |
| super(process, copyHelper, config, null, monitor); |
| |
| this.newProcessName = newProcessName; |
| this.targetPackage = targetPackage; |
| createtargetProcess(); |
| } |
| |
| private void createtargetProcess() { |
| // create a placeholder for the new process |
| // since the content processor needs to know the taret process in order to fix the urls |
| |
| tempPc = UmaFactory.eINSTANCE.createProcessComponent(); |
| targetPackage.getChildPackages().add(tempPc); |
| |
| if ( super.activity instanceof DeliveryProcess ) { |
| targetProcess = UmaFactory.eINSTANCE.createDeliveryProcess(); |
| } else { |
| targetProcess = UmaFactory.eINSTANCE.createCapabilityPattern(); |
| } |
| targetProcess.setName(newProcessName); |
| targetProcess.setPresentationName(newProcessName); |
| tempPc.setName(newProcessName); |
| |
| tempPc.setProcess(targetProcess); |
| } |
| /* (non-Javadoc) |
| * @see org.eclipse.emf.edit.command.CopyCommand#execute() |
| */ |
| public void execute() { |
| super.execute(); |
| } |
| |
| protected void fixProcessComponent() { |
| // replace the place holder with the actual copied process |
| if (pkgCopy instanceof ProcessComponent ) { |
| pkgCopy.setName(newProcessName); |
| org.eclipse.epf.uma.Process proc = ((ProcessComponent)pkgCopy).getProcess(); |
| proc.setName(newProcessName); |
| proc.setPresentationName(newProcessName); |
| |
| EcoreUtil.replace(tempPc, pkgCopy); |
| } |
| } |
| |
| /* |
| * returns a Collection containing the new process |
| * |
| * @see org.eclipse.emf.common.command.CompoundCommand#getResult() |
| */ |
| public Collection getResult() { |
| if(pkgCopy != null && pkgCopy instanceof ProcessComponent) { |
| return Collections.singletonList( ((ProcessComponent)pkgCopy).getProcess()); |
| } |
| return Collections.EMPTY_LIST; |
| } |
| } |