1 11 12 package org.eclipse.ui.ide.undo; 13 14 import java.net.URI ; 15 16 import org.eclipse.core.filesystem.URIUtil; 17 import org.eclipse.core.resources.IProject; 18 import org.eclipse.core.resources.IProjectDescription; 19 import org.eclipse.core.resources.IResource; 20 import org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory; 21 import org.eclipse.core.runtime.Assert; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IAdaptable; 24 import org.eclipse.core.runtime.IProgressMonitor; 25 import org.eclipse.core.runtime.IStatus; 26 import org.eclipse.core.runtime.Platform; 27 import org.eclipse.core.runtime.Status; 28 import org.eclipse.ui.internal.ide.undo.UndoMessages; 29 30 41 public class MoveProjectOperation extends AbstractCopyOrMoveResourcesOperation { 42 43 private URI projectLocation; 44 45 56 public MoveProjectOperation(IProject project, URI location, String label) { 57 super(new IResource[] { project }, label); 58 Assert.isLegal(project != null); 59 if (URIUtil.toPath(location).equals(Platform.getLocation())) { 60 projectLocation = null; 61 } else { 62 projectLocation = location; 63 } 64 } 65 66 72 protected boolean updateResourceChangeDescriptionFactory( 73 IResourceChangeDescriptionFactory factory, int operation) { 74 return false; 77 } 78 79 82 private IProject getProject() { 83 return (IProject) resources[0]; 84 } 85 86 90 protected boolean isDestinationPathValid(IResource resource, int index) { 91 return true; 93 } 94 95 99 protected String getProposedName(IResource resource, int index) { 100 return getProject().getName(); 101 } 102 103 111 protected IStatus computeMoveOrCopyStatus() { 112 IStatus status = Status.OK_STATUS; 113 if (projectLocation != null) { 114 status = getWorkspace().validateProjectLocationURI(getProject(), 115 projectLocation); 116 } 117 if (status.isOK()) { 118 return super.computeMoveOrCopyStatus(); 119 } 120 return status; 121 } 122 123 131 protected void doExecute(IProgressMonitor monitor, IAdaptable uiInfo) 132 throws CoreException { 133 projectLocation = moveProject(getProject(), projectLocation, monitor); 134 setResourceDescriptions(new ResourceDescription[0]); 136 } 137 138 146 protected void doUndo(IProgressMonitor monitor, IAdaptable uiInfo) 147 throws CoreException { 148 doExecute(monitor, uiInfo); 149 } 150 151 154 URI moveProject(IProject project, URI locationURI, IProgressMonitor monitor) 155 throws CoreException { 156 monitor 157 .setTaskName(UndoMessages.AbstractCopyOrMoveResourcesOperation_moveProjectProgress); 158 159 IProjectDescription description = project.getDescription(); 160 URI newDestinationURI = description.getLocationURI(); 162 description.setLocationURI(locationURI); 164 165 project.move(description, IResource.FORCE | IResource.SHALLOW, monitor); 166 167 return newDestinationURI; 169 } 170 171 178 public IStatus computeUndoableStatus(IProgressMonitor monitor) { 179 IStatus status = super.computeUndoableStatus(monitor); 180 if (status.isOK()) { 181 status = computeMoveOrCopyStatus(); 182 } 183 return status; 184 } 185 } 186 | Popular Tags |