1 11 package org.eclipse.team.internal.ccvs.ui.mappings; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.HashSet ; 15 import java.util.Set ; 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.resources.mapping.ResourceTraversal; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.jface.dialogs.MessageDialog; 21 import org.eclipse.jface.operation.IRunnableWithProgress; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.team.core.diff.*; 24 import org.eclipse.team.core.mapping.IResourceDiffTree; 25 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 26 import org.eclipse.team.internal.ccvs.ui.wizards.GenerateDiffFileWizard; 27 import org.eclipse.team.internal.ui.Utils; 28 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 29 import org.eclipse.ui.PlatformUI; 30 31 public class CreatePatchAction extends CVSModelProviderAction implements IDiffChangeListener { 32 33 public CreatePatchAction(ISynchronizePageConfiguration configuration) { 34 super(configuration); 35 getSynchronizationContext().getDiffTree().addDiffChangeListener(this); 36 } 37 38 41 protected boolean isEnabledForSelection(IStructuredSelection selection) { 42 return internalIsEnabled(selection); 43 } 44 45 private boolean internalIsEnabled(IStructuredSelection selection) { 46 int mode = getConfiguration().getMode(); 48 if (mode == ISynchronizePageConfiguration.OUTGOING_MODE || mode == ISynchronizePageConfiguration.BOTH_MODE) { 49 return getResourceMappings(selection).length > 0; 50 } 51 return getSynchronizationContext().getDiffTree().countFor(IThreeWayDiff.CONFLICTING, IThreeWayDiff.DIRECTION_MASK) > 0; 52 } 53 54 private IResource[] getVisibleResources(ResourceTraversal[] traversals) { 55 final Set resources = new HashSet (); 56 final IResourceDiffTree diffTree = getSynchronizationContext().getDiffTree(); 57 IDiff[] diffs = diffTree.getDiffs(traversals); 58 for (int i = 0; i < diffs.length; i++) { 59 IDiff diff = diffs[i]; 60 IResource child = diffTree.getResource(diff); 61 if (child.getType() == IResource.FILE && diff instanceof IThreeWayDiff) { 62 IThreeWayDiff twd = (IThreeWayDiff) diff; 63 IDiff local = twd.getLocalChange(); 64 if (local != null && local.getKind() != IDiff.NO_CHANGE) { 65 resources.add(child); 66 } 67 } 68 } 69 return (IResource[]) resources.toArray(new IResource[resources.size()]); 70 } 71 72 75 protected String getBundleKeyPrefix() { 76 return "GenerateDiffFileAction."; } 78 79 public void execute() { 80 final ResourceTraversal [][] traversals = new ResourceTraversal[][] { null }; 81 try { 82 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 83 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 84 try { 85 traversals[0] = getResourceTraversals(getStructuredSelection(), monitor); 86 } catch (CoreException e) { 87 throw new InvocationTargetException (e); 88 } 89 } 90 }); 91 } catch (InvocationTargetException e) { 92 Utils.handleError(getConfiguration().getSite().getShell(), e, null, null); 93 } catch (InterruptedException e) { 94 } 96 if (traversals[0] != null) { 97 IResource[] resources = getVisibleResources(traversals[0]); 98 if (resources.length == 0) { 99 MessageDialog.openInformation(getConfiguration().getSite().getShell(), CVSUIMessages.CreatePatchAction_0, CVSUIMessages.CreatePatchAction_1); 100 } else { 101 GenerateDiffFileWizard.run(getConfiguration().getSite().getPart(), resources, false); 102 } 103 } 104 } 105 106 public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) { 107 updateEnablement(); 108 } 109 110 public void propertyChanged(IDiffTree tree, int property, IPath[] paths) { 111 } 113 114 } 115 | Popular Tags |