1 11 package org.eclipse.pde.internal.core; 12 13 import org.eclipse.core.resources.IContainer; 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.IFileModificationValidator; 16 import org.eclipse.core.resources.IFolder; 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.team.IMoveDeleteHook; 21 import org.eclipse.core.resources.team.IResourceTree; 22 import org.eclipse.core.runtime.CoreException; 23 import org.eclipse.core.runtime.IProgressMonitor; 24 import org.eclipse.core.runtime.IStatus; 25 import org.eclipse.core.runtime.Status; 26 import org.eclipse.team.core.RepositoryProvider; 27 28 public class BinaryRepositoryProvider extends RepositoryProvider { 29 private IMoveDeleteHook moveDeleteHook; 30 private IFileModificationValidator fileModificationValidator; 31 32 public static final String EXTERNAL_PROJECT_VALUE = "external"; 34 class BinaryMoveDeleteHook implements IMoveDeleteHook { 35 38 public boolean deleteFile( 39 IResourceTree tree, 40 IFile file, 41 int updateFlags, 42 IProgressMonitor monitor) { 43 if (isBinaryResource(file, true)) 44 tree.failed(createProblemStatus()); 45 else 46 tree.standardDeleteFile(file, updateFlags, monitor); 47 return true; 48 } 49 50 53 public boolean deleteFolder( 54 IResourceTree tree, 55 IFolder folder, 56 int updateFlags, 57 IProgressMonitor monitor) { 58 if (isBinaryResource(folder, true)) 59 tree.failed(createProblemStatus()); 60 else 61 tree.standardDeleteFolder(folder, updateFlags, monitor); 62 return true; 63 } 64 65 68 public boolean deleteProject( 69 IResourceTree tree, 70 IProject project, 71 int updateFlags, 72 IProgressMonitor monitor) { 73 return false; 74 } 75 76 79 public boolean moveFile( 80 IResourceTree tree, 81 IFile source, 82 IFile destination, 83 int updateFlags, 84 IProgressMonitor monitor) { 85 if (isBinaryResource(source, false)) 86 tree.failed(createProblemStatus()); 87 else 88 tree.standardMoveFile(source, destination, updateFlags, monitor); 89 return true; 90 } 91 92 95 public boolean moveFolder( 96 IResourceTree tree, 97 IFolder source, 98 IFolder destination, 99 int updateFlags, 100 IProgressMonitor monitor) { 101 if (isBinaryResource(source, false)) 102 tree.failed(createProblemStatus()); 103 else 104 tree.standardMoveFolder(source, destination, updateFlags, monitor); 105 return true; 106 } 107 108 111 public boolean moveProject( 112 IResourceTree tree, 113 IProject source, 114 IProjectDescription description, 115 int updateFlags, 116 IProgressMonitor monitor) { 117 return false; 118 } 119 } 120 121 class BinaryFileModificationValidator 122 implements IFileModificationValidator { 123 126 public IStatus validateEdit(IFile[] files, Object context) { 127 for (int i = 0; i < files.length; i++) { 128 if (isBinaryResource(files[i], false)) { 129 return createProblemStatus(); 130 } 131 } 132 return createOKStatus(); 133 } 134 135 138 public IStatus validateSave(IFile file) { 139 if (isBinaryResource(file, false)) { 140 return createProblemStatus(); 141 } 142 return createOKStatus(); 143 } 144 } 145 146 public BinaryRepositoryProvider() { 147 moveDeleteHook = new BinaryMoveDeleteHook(); 148 fileModificationValidator = new BinaryFileModificationValidator(); 149 } 150 151 154 public void configureProject() throws CoreException { 155 IProject project = getProject(); 156 project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, EXTERNAL_PROJECT_VALUE); 157 } 158 159 162 public void deconfigure() throws CoreException { 163 IProject project = getProject(); 164 project.setPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY, null); 165 } 166 167 170 public IFileModificationValidator getFileModificationValidator() { 171 return fileModificationValidator; 172 } 173 174 177 public String getID() { 178 return PDECore.BINARY_REPOSITORY_PROVIDER; 179 } 180 181 184 public IMoveDeleteHook getMoveDeleteHook() { 185 return moveDeleteHook; 186 } 187 188 private boolean isBinaryResource(IResource resource, boolean excludeProjectChildren) { 189 IContainer parent = resource.getParent(); 190 191 if (!excludeProjectChildren || !(parent instanceof IProject)) { 193 if (resource.isLinked()) 194 return true; 195 } 196 197 199 while (parent instanceof IFolder) { 200 IFolder folder = (IFolder) parent; 201 if (folder.isLinked()) 202 return true; 203 parent = folder.getParent(); 204 } 205 return false; 206 } 207 208 private IStatus createProblemStatus() { 209 String message = PDECoreMessages.BinaryRepositoryProvider_veto; 210 return new Status( 211 IStatus.ERROR, 212 PDECore.PLUGIN_ID, 213 IStatus.OK, 214 message, 215 null); 216 } 217 218 private IStatus createOKStatus() { 219 return new Status(IStatus.OK, PDECore.PLUGIN_ID, IStatus.OK, "", null); 221 } 222 223 public boolean canHandleLinkedResources() { 224 return true; 225 } 226 } 227 | Popular Tags |