1 11 package org.eclipse.team.internal.ccvs.core.syncinfo; 12 13 import java.util.*; 14 15 import org.eclipse.core.resources.*; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.team.core.TeamException; 18 import org.eclipse.team.internal.ccvs.core.*; 19 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 20 import org.eclipse.team.internal.ccvs.core.resources.EclipseSynchronizer; 21 import org.eclipse.team.internal.core.BackgroundEventHandler; 22 23 27 public class DeferredResourceChangeHandler extends BackgroundEventHandler { 28 29 public DeferredResourceChangeHandler() { 30 super(CVSMessages.DeferredResourceChangeHandler_0, CVSMessages.DeferredResourceChangeHandler_1); 31 } 32 33 private static final int IGNORE_FILE_CHANGED = 1; 34 private static final int RECREATED_CVS_RESOURCE = 2; 35 private static final int CONFLICTING_DELETION =3; 36 37 private Set changedIgnoreFiles = new HashSet(); 38 private Set recreatedResources = new HashSet(); 39 private Set conflictingDeletion = new HashSet(); 40 41 44 protected void processEvent(Event event, IProgressMonitor monitor) throws TeamException { 45 int type = event.getType(); 46 switch (type) { 47 case IGNORE_FILE_CHANGED : 48 changedIgnoreFiles.add(event.getResource()); 49 break; 50 case RECREATED_CVS_RESOURCE : 51 recreatedResources.add(event.getResource()); 52 break; 53 case CONFLICTING_DELETION : 54 conflictingDeletion.add(event.getResource()); 55 break; 56 } 57 } 58 59 private IContainer[] getParents(Set files) { 60 Set parents = new HashSet(); 61 for (Iterator iter = files.iterator(); iter.hasNext();) { 62 IFile file = (IFile) iter.next(); 63 parents.add(file.getParent()); 64 } 65 return (IContainer[]) parents.toArray(new IContainer[parents.size()]); 66 } 67 68 public void ignoreFileChanged(IFile file) { 69 if (isSharedWithCVS(file)) 70 queueEvent(new ResourceEvent(file, IGNORE_FILE_CHANGED, IResource.DEPTH_ZERO), false); 71 } 72 73 79 public void recreated(IResource resource) { 80 if (isSharedWithCVS(resource)) 81 queueEvent(new ResourceEvent(resource, RECREATED_CVS_RESOURCE, IResource.DEPTH_ZERO), false); 82 } 83 84 87 protected boolean doDispatchEvents(IProgressMonitor monitor) { 88 boolean workDone = !changedIgnoreFiles.isEmpty() || !recreatedResources.isEmpty(); 90 try { 91 EclipseSynchronizer.getInstance().ignoreFilesChanged(getParents(changedIgnoreFiles)); 92 } catch (CVSException e) { 93 CVSProviderPlugin.log(e); 95 } 96 changedIgnoreFiles.clear(); 97 Map recreations = getResourcesByProject((IResource[]) recreatedResources.toArray(new IResource[recreatedResources.size()])); 99 recreatedResources.clear(); 100 for (Iterator iter = recreations.values().iterator(); iter.hasNext();) { 101 List resources = (List) iter.next(); 102 try { 103 EclipseSynchronizer.getInstance().resourcesRecreated((IResource[]) resources.toArray(new IResource[resources.size()]), monitor); 104 } catch (CVSException e) { 105 CVSProviderPlugin.log(e); 107 } 108 } 109 IResource[] deletions = (IResource[]) conflictingDeletion.toArray(new IResource[conflictingDeletion.size()]); 110 conflictingDeletion.clear(); 111 for (int i = 0; i < deletions.length; i++) { 112 IResource resource = deletions[i]; 113 ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource); 114 try { 115 if(!cvsResource.isFolder() && cvsResource.isManaged()) { 116 cvsResource.unmanage(monitor); 117 } 118 } catch (CVSException e) { 119 CVSProviderPlugin.log(e); 121 } 122 } 123 return workDone; 124 } 125 126 private Map getResourcesByProject(IResource[] resources) { 127 Map result = new HashMap(); 128 for (int i = 0; i < resources.length; i++) { 129 IResource resource = resources[i]; 130 IProject project = resource.getProject(); 131 List projectResources = (List)result.get(project); 132 if (projectResources == null) { 133 projectResources = new ArrayList(); 134 result.put(project, projectResources); 135 } 136 projectResources.add(resource); 137 } 138 return result; 139 } 140 141 public void handleConflictingDeletion(IResource local) { 142 if (isSharedWithCVS(local)) 143 queueEvent(new ResourceEvent(local, CONFLICTING_DELETION, IResource.DEPTH_ZERO), false); 144 } 145 146 private boolean isSharedWithCVS(IResource resource) { 147 return CVSTeamProvider.isSharedWithCVS(resource.getProject()); 148 } 149 150 protected Object getJobFamiliy() { 151 return this; 152 } 153 154 } 155 | Popular Tags |