1 11 package org.eclipse.pde.internal.ui.refactoring; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.resources.IFile; 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IAdaptable; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.jdt.core.IJavaElement; 22 import org.eclipse.jdt.core.IJavaProject; 23 import org.eclipse.jdt.core.IPackageFragment; 24 import org.eclipse.ltk.core.refactoring.Change; 25 import org.eclipse.ltk.core.refactoring.CompositeChange; 26 import org.eclipse.pde.internal.core.ICoreConstants; 27 import org.eclipse.pde.internal.ui.PDEUIMessages; 28 29 public class ManifestPackageMoveParticipant extends PDEMoveParticipant { 30 31 protected boolean initialize(Object element) { 32 if (element instanceof IPackageFragment) { 33 IPackageFragment fragment = (IPackageFragment)element; 34 IJavaProject javaProject = (IJavaProject)fragment.getAncestor(IJavaElement.JAVA_PROJECT); 35 IProject project = javaProject.getProject(); 36 if (project.exists(ICoreConstants.MANIFEST_PATH)) { 37 fProject = javaProject.getProject(); 38 fElements = new HashMap (); 39 fElements.put(fragment, getNewName(getArguments().getDestination(), element)); 40 return true; 41 } 42 } 43 return false; 44 } 45 46 public String getName() { 47 return PDEUIMessages.ManifestPackageRenameParticipant_packageRename; 48 } 49 50 protected void addChange(CompositeChange result, IProgressMonitor pm) throws CoreException { 51 IFile file = fProject.getFile("META-INF/MANIFEST.MF"); if (file.exists()) { 53 IProject destProject = getDestinationProject(); 54 if (destProject != null && !fProject.equals(destProject)) { 55 MoveFromChange change = BundleManifestChange.createMovePackageChange(file, 56 fElements.keySet().toArray(), 57 pm); 58 if (change != null) { 59 result.add(change); 60 IFile dest = destProject.getFile("META-INF/MANIFEST.MF"); if (dest.exists()) { 62 Change second = BundleManifestChange.createMoveToPackageChange( 63 dest, 64 change, 65 pm); 66 if (second != null) 67 result.add(second); 68 } 69 } 70 } 71 } 72 } 73 74 private IProject getDestinationProject() { 75 Object dest = getArguments().getDestination(); 76 if (dest instanceof IAdaptable) { 77 IResource resource = (IResource)((IAdaptable)dest).getAdapter(IResource.class); 78 if (resource != null) 79 return resource.getProject(); 80 } 81 return null; 82 } 83 84 protected boolean isInterestingForExtensions() { 85 return false; 86 } 87 88 } 89 | Popular Tags |