1 11 package org.eclipse.jdt.core.refactoring.descriptors; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResource; 17 18 import org.eclipse.ltk.core.refactoring.RefactoringContribution; 19 import org.eclipse.ltk.core.refactoring.RefactoringCore; 20 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 21 22 import org.eclipse.jdt.core.refactoring.IJavaRefactorings; 23 24 import org.eclipse.jdt.internal.core.refactoring.descriptors.DescriptorMessages; 25 26 41 public final class RenameResourceDescriptor extends JavaRefactoringDescriptor { 42 43 44 private String fName= null; 45 46 47 private IResource fResource= null; 48 49 52 public RenameResourceDescriptor() { 53 super(IJavaRefactorings.RENAME_RESOURCE); 54 } 55 56 59 protected void populateArgumentMap() { 60 super.populateArgumentMap(); 61 fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_INPUT, resourceToHandle(getProject(), fResource)); 62 fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_NAME, fName); 63 } 64 65 71 public void setNewName(final String name) { 72 Assert.isNotNull(name); 73 Assert.isLegal(!"".equals(name), "Name must not be empty"); fName= name; 75 } 76 77 93 public void setProject(final String project) { 94 super.setProject(project); 95 } 96 97 107 public void setResource(final IResource resource) { 108 Assert.isNotNull(resource); 109 fResource= resource; 110 } 111 112 115 public RefactoringStatus validateDescriptor() { 116 RefactoringStatus status= super.validateDescriptor(); 117 if (fResource == null) 118 status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_no_resource)); 119 if (fName == null || "".equals(fName)) status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_no_new_name)); 121 if (fResource instanceof IProject && getProject() != null) 122 status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_project_constraint)); 123 return status; 124 } 125 } | Popular Tags |