1 package org.eclipse.pde.internal.ui.refactoring; 2 3 import java.util.HashMap ; 4 5 import org.eclipse.core.resources.IContainer; 6 import org.eclipse.core.resources.IFile; 7 import org.eclipse.core.resources.IProject; 8 import org.eclipse.core.resources.IResource; 9 import org.eclipse.core.runtime.CoreException; 10 import org.eclipse.core.runtime.IProgressMonitor; 11 import org.eclipse.ltk.core.refactoring.Change; 12 import org.eclipse.ltk.core.refactoring.CompositeChange; 13 23 import org.eclipse.pde.internal.core.WorkspaceModelManager; 24 25 public abstract class ResourceMoveParticipant extends PDEMoveParticipant { 26 27 protected boolean isInterestingForExtensions() { 28 return true; 29 } 30 31 protected boolean initialize(Object element) { 32 if (element instanceof IResource) { 33 IProject project = ((IResource) element).getProject(); 34 if (WorkspaceModelManager.isPluginProject(project)) { 35 fProject = project; 36 fElements = new HashMap (); 37 fElements.put(element, getNewName(getArguments().getDestination(), element)); 38 return true; 39 } 40 } 41 return false; 42 } 43 44 protected void addChange(CompositeChange result, String filename, IProgressMonitor pm) 45 throws CoreException { 46 IFile file = fProject.getFile(filename); 47 if (file.exists()) { 48 Change change = PluginManifestChange.createRenameChange(file, 49 fElements.keySet().toArray(), 50 getNewNames(), 51 getTextChange(file), 52 pm); 53 if (change != null) 54 result.add(change); 55 } 56 } 57 58 protected String getNewName(Object destination, Object element) { 59 if (destination instanceof IContainer && element instanceof IResource) { 60 StringBuffer buffer = new StringBuffer (); 61 buffer.append(((IContainer)destination).getProjectRelativePath().toString()); 62 if (buffer.length() > 0) 63 buffer.append('/'); 64 return buffer.append(((IResource)element).getName()).toString(); 65 } 66 return super.getNewName(destination, element); 67 } 68 69 protected void addChange(CompositeChange result, IProgressMonitor pm) 70 throws CoreException { 71 IFile file = fProject.getFile("build.properties"); if (file.exists()) { 73 Change change = BuildPropertiesChange.createRenameChange( 74 file, 75 fElements.keySet().toArray(), 76 getNewNames(), 77 pm); 78 if (change != null) 79 result.add(change); 80 } 81 } 82 83 } 84 | Popular Tags |