1 11 package org.eclipse.compare.internal.patch; 12 13 import org.eclipse.compare.CompareConfiguration; 14 import org.eclipse.compare.internal.*; 15 import org.eclipse.compare.patch.ApplyPatchOperation; 16 import org.eclipse.core.resources.IFile; 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.swt.custom.BusyIndicator; 22 import org.eclipse.ui.IObjectActionDelegate; 23 import org.eclipse.ui.IWorkbenchPart; 24 25 26 public class CompareWithPatchAction extends BaseCompareAction implements IObjectActionDelegate { 27 28 29 private IWorkbenchPart targetPart; 30 31 protected boolean isEnabled(ISelection selection) { 32 return Utilities.getResources(selection).length == 1; 33 } 34 35 38 protected void run(ISelection selection) { 39 IResource firstResource = Utilities.getFirstResource(selection); 40 41 boolean isPatch = false; 42 if (firstResource instanceof IFile) { 43 try { 44 isPatch = ApplyPatchOperation.isPatch((IFile)firstResource); 45 } catch (CoreException e) { 46 CompareUIPlugin.log(e); 47 } 48 } 49 50 final ApplyPatchOperation patchOp; 51 if (isPatch) { 52 patchOp= new ApplyPatchOperation(targetPart, (IFile)firstResource, null, new CompareConfiguration()); 53 } else { 54 patchOp= new ApplyPatchOperation(targetPart, firstResource); 55 } 56 57 targetPart.getSite().getShell().getDisplay().asyncExec(new Runnable (){ 58 public void run() { 59 BusyIndicator.showWhile(targetPart.getSite().getShell().getDisplay(), patchOp); 60 } 61 }); 62 63 } 64 65 public void setActivePart(IAction action, IWorkbenchPart targetPart) { 66 this.targetPart = targetPart; 67 } 68 } 69 | Popular Tags |