1 11 package org.eclipse.team.internal.ccvs.ui.actions; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Arrays ; 16 import java.util.List ; 17 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.resources.mapping.ResourceMapping; 20 import org.eclipse.core.resources.mapping.ResourceTraversal; 21 import org.eclipse.core.runtime.*; 22 import org.eclipse.jface.action.IAction; 23 import org.eclipse.jface.operation.IRunnableWithProgress; 24 import org.eclipse.team.core.subscribers.SubscriberResourceMappingContext; 25 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; 26 import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; 27 import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants; 28 import org.eclipse.team.internal.ccvs.ui.wizards.GenerateDiffFileWizard; 29 import org.eclipse.ui.PlatformUI; 30 31 37 public class GenerateDiffFileAction extends WorkspaceTraversalAction{ 38 39 42 public void execute(IAction action) { 43 44 try { 45 final IResource [][] resources = new IResource[][] { null }; 46 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 47 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 48 try { 49 resources[0] = getDeepResourcesToPatch(monitor); 50 } catch (CoreException e) { 51 throw new InvocationTargetException (e); 52 } 53 } 54 }); 55 GenerateDiffFileWizard.run(getTargetPart(), resources[0]); 56 } catch (InvocationTargetException e) { 57 CVSUIPlugin.openError(getShell(), null, null, e, CVSUIPlugin.LOG_NONTEAM_EXCEPTIONS); 58 } catch (InterruptedException e) { 59 } 61 } 62 63 private IResource[] getDeepResourcesToPatch(IProgressMonitor monitor) throws CoreException { 64 ResourceMapping[] mappings = getCVSResourceMappings(); 65 List roots = new ArrayList (); 66 for (int i = 0; i < mappings.length; i++) { 67 ResourceMapping mapping = mappings[i]; 68 ResourceTraversal[] traversals = mapping.getTraversals( 69 SubscriberResourceMappingContext.createContext(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber()), 70 monitor); 71 for (int j = 0; j < traversals.length; j++) { 72 ResourceTraversal traversal = traversals[j]; 73 IResource[] resources = traversal.getResources(); 74 if (traversal.getDepth() == IResource.DEPTH_INFINITE) { 75 roots.addAll(Arrays.asList(resources)); 76 } else if (traversal.getDepth() == IResource.DEPTH_ZERO) { 77 collectShallowFiles(resources, roots); 78 } else if (traversal.getDepth() == IResource.DEPTH_ONE) { 79 collectShallowFiles(resources, roots); 80 for (int k = 0; k < resources.length; k++) { 81 IResource resource = resources[k]; 82 if (resource.getType() != IResource.FILE) { 83 collectShallowFiles(members(resource), roots); 84 } 85 } 86 } 87 } 88 } 89 return (IResource[]) roots.toArray(new IResource[roots.size()]); 90 } 91 92 private void collectShallowFiles(IResource[] resources, List roots) { 93 for (int k = 0; k < resources.length; k++) { 94 IResource resource = resources[k]; 95 if (resource.getType() == IResource.FILE) 96 roots.add(resource); 97 } 98 } 99 100 private IResource[] members(IResource resource) throws CoreException { 101 return CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber().members(resource); 102 } 103 106 protected boolean isEnabledForMultipleResources() { 107 return true; 108 } 109 110 113 protected boolean isEnabledForUnmanagedResources() { 114 return true; 115 } 116 117 118 121 public String getId() { 122 return ICVSUIConstants.CMD_CREATEPATCH; 123 } 124 } 125 | Popular Tags |