1 11 package org.eclipse.team.internal.core; 12 13 14 import java.util.*; 15 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.team.FileModificationValidationContext; 18 import org.eclipse.core.resources.team.FileModificationValidator; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.MultiStatus; 21 import org.eclipse.team.core.RepositoryProvider; 22 23 public class FileModificationValidatorManager extends FileModificationValidator { 24 private FileModificationValidator defaultValidator; 25 26 32 public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { 33 ArrayList returnStati = new ArrayList(); 34 35 Map providersToFiles = new HashMap(files.length); 37 38 for (int i = 0; i < files.length; i++) { 40 IFile file = files[i]; 41 RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject()); 42 43 if (!providersToFiles.containsKey(provider)) { 44 providersToFiles.put(provider, new ArrayList()); 45 } 46 47 ((ArrayList)providersToFiles.get(provider)).add(file); 48 } 49 50 Iterator providersIterator = providersToFiles.keySet().iterator(); 51 52 boolean allOK = true; 53 54 while(providersIterator.hasNext()) { 56 RepositoryProvider provider = (RepositoryProvider)providersIterator.next(); 57 ArrayList filesList = (ArrayList)providersToFiles.get(provider); 58 IFile[] filesArray = (IFile[])filesList.toArray(new IFile[filesList.size()]); 59 FileModificationValidator validator = getDefaultValidator(); 60 61 if (provider != null) { 63 FileModificationValidator v = provider.getFileModificationValidator2(); 64 if (v != null) validator = v; 65 } 66 67 IStatus status = validator.validateEdit(filesArray, context); 68 if(!status.isOK()) 69 allOK = false; 70 71 returnStati.add(status); 72 } 73 74 if (returnStati.size() == 1) { 75 return (IStatus)returnStati.get(0); 76 } 77 78 return new MultiStatus(TeamPlugin.ID, 79 0, 80 (IStatus[])returnStati.toArray(new IStatus[returnStati.size()]), 81 allOK 82 ? Messages.ok 83 : Messages.FileModificationValidator_editFailed, 84 null); 85 } 86 87 90 public IStatus validateSave(IFile file) { 91 RepositoryProvider provider = RepositoryProvider.getProvider(file.getProject()); 92 FileModificationValidator validator = getDefaultValidator(); 93 94 if (provider != null) { 96 FileModificationValidator v = provider.getFileModificationValidator2(); 97 if (v != null) validator = v; 98 } 99 100 return validator.validateSave(file); 101 } 102 103 private synchronized FileModificationValidator getDefaultValidator() { 104 if (defaultValidator == null) { 105 defaultValidator = new DefaultFileModificationValidator(); 106 } 107 return defaultValidator; 108 } 109 } 110 | Popular Tags |