1 11 12 package org.eclipse.jdt.internal.corext.refactoring.changes; 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 17 import org.eclipse.core.resources.IFolder; 18 19 import org.eclipse.jdt.core.IPackageFragment; 20 import org.eclipse.jdt.core.IPackageFragmentRoot; 21 22 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages; 23 import org.eclipse.jdt.internal.corext.refactoring.base.JDTChange; 24 import org.eclipse.ltk.core.refactoring.Change; 25 import org.eclipse.ltk.core.refactoring.NullChange; 26 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 27 28 public class CreatePackageChange extends JDTChange { 29 30 private IPackageFragment fPackageFragment; 31 32 public CreatePackageChange(IPackageFragment pack) { 33 fPackageFragment= pack; 34 } 35 36 public RefactoringStatus isValid(IProgressMonitor pm) { 37 return new RefactoringStatus(); 42 } 43 44 public Change perform(IProgressMonitor pm) throws CoreException { 45 try { 46 pm.beginTask(RefactoringCoreMessages.CreatePackageChange_Creating_package, 1); 47 48 if (fPackageFragment.exists()) { 49 return new NullChange(); 50 } else { 51 IPackageFragmentRoot root= (IPackageFragmentRoot) fPackageFragment.getParent(); 52 root.createPackageFragment(fPackageFragment.getElementName(), false, pm); 53 54 return new DeleteFolderChange((IFolder) fPackageFragment.getResource(), true); 55 } 56 } finally { 57 pm.done(); 58 } 59 } 60 61 public String getName() { 62 return RefactoringCoreMessages.CreatePackageChange_Create_package; 63 } 64 65 public Object getModifiedElement() { 66 return fPackageFragment; 67 } 68 } 69 | Popular Tags |