KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > patch > CompareWithPatchAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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     /* (non-Javadoc)
36      * @see org.eclipse.compare.internal.BaseCompareAction#run(org.eclipse.jface.viewers.ISelection)
37      */

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 JavaDoc(){
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